0

Web table with cell values

How do i validate all column values based on technologies.
e.g For

  • Technology A - values should be 0 0 1

  • Technology B - Values should be 1 0 100

and so on.

My code looks something like this

str1 = driver.findbyxpath.gettext();     
if(str1.equals("A"))
            {
                cell1 = driver.findElement(By.xpath("//*[@id=\"siaSummaryTable\"]/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[2]")).getText();
                cell2 = driver.findElement(By.xpath("//*[@id=\"siaSummaryTable\"]/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[3]")).getText();
                cell3 = driver.findElement(By.xpath("//*[@id=\"siaSummaryTable\"]/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[4]")).getText();
                Assert.assertEquals("Not valid data,"0",cell1);
                Assert.assertEquals("Not valid data","0",cell2);
                Assert.assertEquals("Not valid data","0",cell3);
                System.out.println("Asserstion for A Successfull");
            }

But code will be much complex if i validate for all technologies and respective column values.
what is the other solution ?
p.s - Please ignore the xpath with multiple divs. This is just for testing purpose.

  • Do you want to validate data in table or to validate some values using data from table as reference one? – Alexey R. Oct 7 at 7:34
1

You can create a method that would validate data in one row of a table. It could accept the row number and expected values. So you would just reuse that method for all the table rows.

This would make your code less complex and more readable.

0

Loop over the cells

Pseudo code:

valid_data = ['a', 'b', 'c']
valid_data.each do |expected|
  actual = driver.findElement(By.xpath("//*[@id=\"siaSummaryTable\"]/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[@expected]")).getText();
  Assert.assertEquals("invalid", actual, expected)
end
0

The cleanest solution is to create a model object for each row.

This object would have one attribute for each column:

  • Technology
  • Cell 1
  • ....

One method of this object would be something as Java's equals, which is responsible to check if the attributes of two objects (of the same model class) match each other. This method will have any "adjustment" necessary, such as trimming string attributes.

You can have a factory for these objects.

Then, your test just needs to ask the factory for the objects and the equals method for the equality check. No logic about the modeling or the checking itself will stay in the test.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.