-1

I have written a POM for test automation of a web UI using Selenium Webdriver using java.

In the POM, I have created a repository of methods of all the page fields. Basically the web page has more than 100 fields. So I am using an excel sheet for data with the help of apache poi.

The problem is, I want to call all the method in the test script and that particular method should be executed only if the excel sheet has data for that method. I am a beginner to coding so please help with this.

(I am reading the data from the excel sheet using column name and the excel template has a column for all the 100+ fields.)

Now I need to write test script for each test cases. But I want my program to run depending on the data from the excel sheet, ignoring the method for which there is no data in the excel sheet.

Below is a similar example. I have two classes POM and TestCase.

public class POM(){
   public method1(String a){
       sop("1st method"+a)
   }

   public method2(String a){
       sop("2nd Method"+a)
   }

   public method2(String a){
       sop("3rd Method"+a)
   }
}

Below is the test case class, which will call the methods of class POM. The data for the methods is provided by excel file.

public class TestCase(){
  main(){
    POM obj = new POM();
    obj.method1(poi.getDataFromExcel("column name", row_number));
    obj.method2(poi.getDataFromExcel("column name", row_number));
    obj.method3(poi.getDataFromExcel("column name", row_number));
    }
 }

So now again my question is, I don't have any data for method2 in my excel sheet. How can I skip that method?

7
  • Is you task structured like this one: stackoverflow.com/questions/4247933/… ? Commented Sep 13, 2019 at 18:23
  • No, in that they are talking about if one of the data fails in those given arrays, but my question is about if there is no data from the Excel sheet for my method how can I skip that particular method. Commented Sep 13, 2019 at 18:29
  • I was referring to the "structrue" of your task, not the goal - i.e. repeatedly calling a method with different data. If yours is like that, then in the loop, could you simply have an IF statement that doesn't execute the test if there is no data? Commented Sep 13, 2019 at 18:34
  • Should I use if(null) or if(text==null) Commented Sep 13, 2019 at 18:37
  • 1
    Can you post the code for the method in question? I'm not clear what you are asking. Commented Sep 13, 2019 at 19:13

2 Answers 2

1

According your description you wants calling the obj.method* in your TestCase only if there is a not empty string returned from poi.getDataFromExcel("column name", row_number).

That would look like so:

...
POM obj = new POM();
String cellValue = poi.getDataFromExcel("column name", row_number);
if (cellValue != null && !cellValue.isEmpty()) {
    obj.method1(cellValue);
}
...
Sign up to request clarification or add additional context in comments.

Comments

0

While reading the data why can't you just skip the function if there is no data for the function.

Something like this,

if(data != null){ //Then call the function ..... }

2 Comments

Should I include this in the method or before calling the method?
Before calling the method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.