I am new to Cucumber and learning automation testing, here i have an example table but i am not able to run all the table content and it says only 1 Scenarios (1 passed). please help !!
Demo.feature
Feature: Test login functionality
Scenario Outline: Check login is successful with valid credentials
Given browser is open
And user is on login page
When user enters <username> and <password>
And user clicks on login
Then user is navigated to the home page
Examples:
| username | password |
| student | Password123 |
| Raghav | pass123 |
| dil | dill2 |
this table is data is only runned one with first username and password instead of running 3 times and the whole program only executes once not 3 times
StepDefinition: DemoSteps
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.cucumber.java.en.*;
public class LoginDemoSteps {
WebDriver driver = null;
@Given("browser is open")
public void browser_is_open() {
System.out.println("inside step - browser open");
String projectPath = System.getProperty("user.dir");//will get the location of the current project folder
System.out.println(projectPath);
System.setProperty("webdriver.chrome.driver",projectPath+"/src/test/resources/drivers/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);//overall time to wait for all elements to load
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);//wait for the page to load
//if page is loaded these 2 statements are skipped
}
@And("user is on login page")
public void user_is_on_login_page() {
driver.navigate().to("https://practicetestautomation.com/practice-test-login/");
}
@When("^user enters (.*) and (.*)$")
public void user_enters_username_and_password(String username, String password) throws InterruptedException {
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
Thread.sleep(2000);
}
@And("user clicks on login")
public void user_clicks_on_login() {
//id=submit
driver.findElement(By.id("submit")).click();
}
@Then("user is navigated to the home page")
public void user_is_navigated_to_the_home_page() throws InterruptedException {
driver.getPageSource().contains("Logged In Successfully");//contains this text on the next page
System.out.println("Test Successful");
Thread.sleep(2000);
driver.close();
driver.quit();
}
}
RunnerClass : TestRunner.java
package StepDefinitions;
import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;
//This class is used to run all the automated steps
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/Features", glue = { "StepDefinitions" }, // Glue code
monochrome = true, plugin = { "pretty", "html:target/HTMLReports/report.html",
"json:target/JSONReports/report.json", "junit:target/JUNITReports/report.xml" } // reports
)
public class TestRunner {
}
Output:
Feb 28, 2024 1:59:26 PM cucumber.api.cli.Main run
WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main
Scenario: Check login is successful with valid credentials # src/test/resources/Features/LoginDemo.feature:3
inside step - browser open
C:\Users\..\CucumberJava2
Given browser is open # StepDefinitions.LoginDemoSteps.browser_is_open()
And user is on login page # StepDefinitions.LoginDemoSteps.user_is_on_login_page()
When user enters username and password # StepDefinitions.LoginDemoSteps.user_enters_username_and_password()
And user clicks on login # StepDefinitions.LoginDemoSteps.user_clicks_on_login()
Test Successful
Feb 28, 2024 1:59:33 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Connection reset
java.net.SocketException: Connection reset
at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394)
at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
at java.net.http/jdk.internal.net.http.SocketTube.readAvailable(SocketTube.java:1170)
at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:833)
at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowTask.run(SocketTube.java:181)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:230)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:303)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:256)
at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:774)
at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:957)
at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:253)
at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:979)
at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:934)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:934)
Then user is navigated to the home page # StepDefinitions.LoginDemoSteps.user_is_navigated_to_the_home_page()
1 Scenarios (1 passed)
5 Steps (5 passed)
0m6.839s
Deprecated Main Class is not the prblem
Problem solved !! the file was different but it will running another version of the file from another folder, fixed it by renaming and running it as junit test