From UI I have to read the below values (I have given example values)

  • EmployeeID : 100
  • First name : abc
  • Last name : XYZ
  • Joining date : 22-Aug-2015
  • Gender : Male
  • Phone Number : 10908333

I have to compare this with data from the database. The database stores the data as a Key value pair like (Field_Name) and (Field_Value).

I am using the following code to extract the list values:

List<WebElement> payLoads = driver.findElements(By.xpath(".//*[@id='payloadAndCharts']/d‌​iv/div[1]/div")); 
Iterator<WebElement> itr = payLoads.iterator(); 

I am using split by : (colon) to extract the field name and field value, and save into hasp map so I can compare with the DB field name and field value.

Is this the correct approach?

  • To suggest a better approach we need to have your approach. Have you implemented some code already?. Also please specify the programming language you're using. – Alexey R. Sep 1 '17 at 11:12
  • 1
    Iterating a list and comparing values is a programming question... – FDM Sep 1 '17 at 11:20
  • I have implemented below code to print values using Java code List<WebElement> payLoads = driver.findElements(By.xpath(".//*[@id='payloadAndCharts']/div/div[1]/div")); Iterator<WebElement> itr = payLoads.iterator(); while(itr.hasNext()) { System.out.println(itr.next().getText()); – praveen cn Sep 1 '17 at 11:30
  • @praveencn did that print what you were expecting? – Alexey R. Sep 1 '17 at 11:35
  • 2
    To use any library, you need to become competent programmer in your chosen language. Get a book or online course and learn loops, data structures etc. Once you are competent programmer, these problems are trivial and solutions are obvious. IMHO this is not a forum to teach programming basics - correct me if I am wrong. – Peter M. - stands for Monica Sep 1 '17 at 14:01

So your test would consisit of three parts

  1. Fetch the user fields from UI. To make the effective fetching code you have to examine the structure of html that represents your user data. The same would affect the most appropriate data structure to store. I would better implement a class that would represent the data you have on your UI. Also I would implement my own equals() method to make assertions easier.


class Employee{

    int employeeId;
    String firstName;
    String lastName;
    // ...
    // other fields;
    // getters
    // setters
    // constructors

    public boolean equals(Object obj) {
        if(/*you comparison rules*/){
            return true;
        return false;

Thus when you read a data from UI you create Employee instance object (or a collection of objects if there is a list of users on your page)

  1. Fetch the user data from database. You have to implement the data fetching code depending on what database you're using. If it is an SQL or no-SQL database. What particular database vendor you're using and so on.

When you fetch data from the database you build another Employee isntance using that fetched data

  1. Compare objects from different sources. Use your overriden equals() method.
| improve this answer | |
  • You should always override both hashCode() and equals(Object). And let the IDE help you. – beatngu13 Sep 2 '17 at 8:56

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