= cucumber = * https://cucumber.io/docs/guides/10-minute-tutorial/?lang=java == Example project == {{{#!highlight sh mvn archetype:generate \ "-DarchetypeGroupId=io.cucumber" \ "-DarchetypeArtifactId=cucumber-archetype" \ "-DarchetypeVersion=7.14.1" \ "-DgroupId=hellocucumber" \ "-DartifactId=hellocucumber" \ "-Dpackage=hellocucumber" \ "-Dversion=1.0.0-SNAPSHOT" \ "-DinteractiveMode=false" }}} === pom.xml === {{{#!highlight xml 4.0.0 hellocucumber hellocucumber 1.0.0-SNAPSHOT jar UTF-8 io.cucumber cucumber-bom 7.14.1 pom import org.junit junit-bom 5.10.1 pom import io.cucumber cucumber-java test io.cucumber cucumber-junit-platform-engine test org.junit.platform junit-platform-suite test org.junit.jupiter junit-jupiter test org.seleniumhq.selenium selenium-java 4.16.1 org.apache.maven.plugins maven-compiler-plugin 3.11.0 UTF-8 17 17 org.apache.maven.plugins maven-surefire-plugin 3.2.2 }}} === src/test/java/hellocucumber/AnExample.java === {{{#!highlight java package hellocucumber; import io.cucumber.java.en.*; import static org.junit.jupiter.api.Assertions.assertNotNull; import org.junit.jupiter.api.Assertions.*; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class AnExample { WebDriver driver = null; private void waitMillis(long ms) { try { Thread.sleep(ms); } catch (InterruptedException e) { e.printStackTrace(); } } @Given("we are at site {string}") public void weAreAtRpiSite(String site) { driver = new FirefoxDriver(); driver.navigate().to(site); } @When("we try to login with credentials") public void tryToLoginWithCredentials() { // mvn clean test -Duser=xxxx -Dpassword=xxxx String user = System.getProperty("user"); String password = System.getProperty("password"); driver.findElement(By.name("user")).sendKeys(user); driver.findElement(By.name("password")).sendKeys(password); driver.findElement(By.className("btn-primary")).click(); } @Then("we should be logged in and see the logout link") public void shouldBeLoggedInAndSeeLogoutLink() { waitMillis(10000); WebElement logout = driver.findElement(By.id("logout")); assertNotNull(logout); logout.click(); waitMillis(10000); driver.close(); } } }}} === src/test/java/hellocucumber/Example.java === {{{#!highlight java package hellocucumber; import io.cucumber.java.en.*; public class Example { @Given("an example scenario") public void an_example_scenario() { } @When("all step definitions are implemented") public void all_step_definitions_are_implemented() { } @Then("the scenario passes") public void the_scenario_passes() { } } }}} === src/test/java/hellocucumber/RunCucumberTest.java === {{{#!highlight java package hellocucumber; import org.junit.platform.suite.api.ConfigurationParameter; import org.junit.platform.suite.api.IncludeEngines; import org.junit.platform.suite.api.SelectClasspathResource; import org.junit.platform.suite.api.Suite; import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME; @Suite @IncludeEngines("cucumber") @SelectClasspathResource("hellocucumber") @ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty") public class RunCucumberTest { } }}} === src/test/resources/hellocucumber/anexample.feature === {{{ Feature: AnExample Scenario: An example scenario Given we are at site "" When we try to login with credentials Then we should be logged in and see the logout link Examples: | url | | https://rpi.bitarus.mooo.com/ | }}} === src/test/resources/hellocucumber/example.feature === {{{ Feature: example Scenario: example scenario Given an example scenario When all step definitions are implemented Then the scenario passes }}}