简体   繁体   中英

How to iterate feature files in cucumber selenium

I want to enter 5 different dates in my application.For that i am storing those dates in feature files.I want to iterate all dates one by one

Feature File:
Scenario Outline: To test feature file iteration   
Given User is on login Screen
When user enters credentials "<User_ID>" and "<Password>"
Then user enters "<processing_date>"
And clicks on logout  
Examples:

| User_ID | Password |processing_date|
| Abc     | Abc.     |28/11/2018|
| Abc.    | Abc.     |03/12/2018|

Method for entering date:

public void date(DataTable date) throws Exception {             
List<List<String>> data = processing_date.asList(String.class);//I had to use asList as .raw was not available)
System.out.println("Size is :" +data.size() );
for(int i=1;i<data.size();i++) 
{
    Thread.sleep(3000);
    String scriptText = "document.querySelector('.datafield').setAttribute('value','" + date.get(i).get(i)+ "')";
    ((JavascriptExecutor)driver).executeScript(scriptText);
    log.info("date is entered");
}

But this is not working.Is there any method to iterate feature files.Getting error as Argument mismatch.If i change DataTable date to String date and remove for loop , it works fine.But every time it login and logouts.But i want to execute all 5 dates one after the other without logging out.

You are using a scenario outline. You need to understand how a scenario outline works. Basically a scenario outline is a compact way of writing several separate scenarios. So your outline will create a single scenario for each date in your examples table. This means your step will only have one date available so there is nothing to iterate over.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM