-1

Im testing a scenario where there are about 100s of username and password. I should use each username-password pair one by one and then try login to application. Then logout. Login again in the same browser without closing it. Here if any of the credentials are invalid then only that particular row should be marked fail and rest should continue execution

I tried to search for the solution but couldnot get any proper resolution

Scenario: To test if the given list of users credentials are valid

    Given user is already at Login page
    And user enters credentails

|   Username    |   Password    |
|   user1       |   password1   |
|   user2       |   invalid         |
|   user3       |   password3   |
|   user4       |   password4   |
|   user5       |   password5   |
|   user6       |   password6   |
|   user7       |   password7   |

Here the status of 2nd row of datatable should be marked failed in the report and rest of the data should be executed except the failed ones. Passed data should be marked PASS in the report. How to achieve this.

Grasshopper
  • 8,908
  • 2
  • 17
  • 32

1 Answers1

-1

First you would need to modify scenario as per below outline.

 Scenario Outline: To test if the given list of users credentials are valid
    Given user is already at Login page
    And In credentails, user enters name as <Username> and Pwd as <Password>

    Examples: Checking Login Scenarios
      | Username | Password  |
      | user1    | password1 |
      | user2    | invalid   |

Second lets consider below is your step implementation

package my.package.name

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.And;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class MyStepDefinitions {

    @Given("^user is already at Login page$")
    public void user_is_already_at_login_page() throws Throwable {
        throw new PendingException();
    }

    @And("^In credentails, user enters name as (.+) and Pwd as (.+)$")
    public void in_credentails_user_enters_name_as_and_pwd_as(String username, String password) throws Throwable {
        throw new PendingException();
    }

}

Third lets say under above step implementation, you write action to log into site and Action gets failed as Password was invalid. Now depending on which report you are using, you would need to write one method as per API of report, like i am sharing for extent.

public static synchronized void logFail(String message) {
    try {
        testReport.get().fail("<details>" + "<summary>" + "<b>" + "<font color=" + "red>" + "</font>" + "</b >" + "</summary>" + "<br>" + "<h6>" + "<b>" + BasePage.returnLocator(message) +  "</b>"+ "</h6>" + "</br>" + message +"</details>"+" \n");
    }
    catch(Exception e) {            
    }   
}

At last, following above hierarchy you would be able to print Passed/Failed in report.

TheSociety
  • 1,936
  • 2
  • 8
  • 20
  • 1
    Thanks for the solution. Can you please help me understand BasePage.returnLocator(message). Also if i use Scenario Outline, for every row of data, a new chrome window will be launched. I want to test all in the same browser window. Thats the reason i didnt use scenario outline – Anisha Nadar Apr 11 '19 at 03:27