Verifying a dynamic table record, if they match with data then PASS else Fail the test case using Assert



  • Page Object Class

    public class Transactions {
        WebDriver driver;
        boolean result1;
    public Transactions(WebDriver driver) {
            //super();
            this.driver = driver;
        }
    
    public void click_on_transaction()
    {
        driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/div[3]/button[1]")).click();
    }
    public boolean display_transaction()
    {
    
        List<WebElement> element= driver.findElements(By.id("anchor0"));
        Integer trsize= element.size();
        //System.out.println(trsize);
        String[] current_transaction = {"Oct 25, 2018 12:07:52 PM 1200 Credit", "Oct 25, 2018 12:07:56 PM 200 Debit"};
        int i;
        for(i=0;i<=trsize;i++)
        {
            WebElement transaction_table= driver.findElement(By.id("anchor"+i));
            String table_data= transaction_table.getText();
            @SuppressWarnings("unlikely-arg-type")
            boolean result1 = (table_data.equals(current_transaction));
    
        }
        return result1;
    
    }
    
    }  
    

    Here is my Test Class

    public class TestTransactionDetails extends BaseTest {
      @Test
      public void view_complete_transaction() throws Exception {
          TestWithdrawl testwithdrawl= new TestWithdrawl();
          Transactions transaction= new Transactions(driver);
          testwithdrawl.valid_ammount_withdrawl();
          transaction.click_on_transaction();
    
          ScreenShot.takeSnapShot(driver, "D:\\Images\\Test4");
          Assert.True(transaction.display_transaction());
      }
    }
    

    Here is my Base Class

    public class BaseTest {
        public static WebDriver driver;
      @BeforeTest
      public void launchBank() {
          //System.setProperty("webdriver.chrome.driver", "C:\\Intel\\chromedriver.exe");
          //driver = new ChromeDriver(); 
          driver= new FirefoxDriver();
          driver.get("http://www.way2automation.com/angularjs-protractor/banking/#/login");
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      }
      @AfterTest
      public void QuitLaunch()
      {
          driver.close();
          driver.quit();
      }
    }  
    

    I'm new to Automation so i'm not able to verify that my test is fail or pass and how to verify this.Plz someone help me to get out of it.



  • I found my answer it is working for me, i just tried a very simple way to verify small table data

    Now my Page Object Class method look like this

    public String display_transaction()
    {
        List<WebElement> element= driver.findElements(By.tagName("tr"));
        Integer trsize= element.size(); 
        String reult_set = null;
        int j;
        String[] ammountmessage= {"1200","200"};    
        for(j=0;j<trsize-1;j++)
        {
        WebElement transaction_table1= driver.findElement(By.xpath(".//*[@id='anchor"+j+"']/td[2]"));
        String data1=transaction_table1.getText();
        if (data1.equals(ammountmessage[j]))
        {
        reult_set="Transaction Pass";   
        }
        else
        {       
            reult_set=null;
            break;      
        }
        }   
        return reult_set;
    }  
    

    And my Test Class

    public class TestTransactionDetails extends BaseTest {
      @Test
      public void view_complete_transaction() throws Exception {
          TestWithdrawl testwithdrawl= new TestWithdrawl();
          Transactions transaction= new Transactions(driver);
          testwithdrawl.valid_ammount_withdrawl();
          Thread.sleep(1000);
          transaction.click_on_transaction();     
          ScreenShot.takeSnapShot(driver, "D:\\Images\\Test4");
          Assert.assertEquals( transaction.display_transaction(),"Transaction Pass");
      }
    }  
    

    Thank you all who response for this.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2