Cucumber Testing
1. Data Table : https://www.baeldung.com/cucumber-data-tables
2. Parllel Execution: https://cucumber.io/docs/guides/parallel-execution/
3. cucumber hooks
-@Before
-@BeforeStep
-@After
-@AfterStep
4. Background keyword is used to define some pre-conditions for all the scenarios. Many a times, we repeat the same ‘Given’ step in all the scenarios. Since ‘Given’ step is repeated in every scenario, we can move such repeated steps to the background, by grouping them under a ‘Background’ section.
5. Cucumber
a) TestRunner.java
@RunWith(cucumber.class)
@cucumberOptions(){
features="",glue={""},tags={"smokeTest"}
}
public class TestRunner(){
}
b) login.feature
Feature: test to login functioanlity
description------
Sceanrio: Given user is navigated to webpage
When enter the <username> and <password> in input fields
Then user is able to login into page
c) loginSteps.java
public class navigateToWebpage() {
Webdriver driver = new ChromeDriver();
@Given("^user is navigated to webpage$")
public void user_navigate_to_webpage(){
driver.get("www.gmail.com")
}
@When("enter the "username" and "password" in input fields")
public void enter_user_details(String name,String password){
driver.findElement(By.xpath("")).sendKeys("ramanrayat");
driver.findElement(By.xpath("")).sendKeys("password");
driver.findElement(By.xpath("")).click();
}
}
DataTables
cucumber data table
And User enters Credentials to LogIn
| testuser_1 | Test@153 |
@When("User enters valid credentials")
public void entersValidCredential(DataTable dataTable) throws InterruptedException{
List<String> LoginForm = dataTable.asList();
String userName = LoginForm.get(0);
String passWord = LoginForm.get(1);
driver.findElement(By.name("Username")).sendKeys(userName);
driver.findElement(By.name("Password")).sendKeys(passWord);
}
with labels (asMaps)
When User clicks the Login button after entering valid username and password
| Username | Password |
| Sharon2023 | Welc@2023 |
@When("User enters valid credentials")
public void entersValidCredential(DataTable dataTable)
{
List<Map<String, String>> user = userTable.asMaps(String.class, String.class);
for (Map<String, String> form : user) {
String userName = form.get("Username");
System.out.println("Username :" + userName);
driver.findElement(By.name("Username")).sendKeys(userName);
String passWord = form.get("Password");
System.out.println("Password :" + passWord);
driver.findElement(By.name("Password")).sendKeys(passWord);
}
Comments
Post a Comment