= 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 <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>hellocucumber</groupId> <artifactId>hellocucumber</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-bom</artifactId> <version>7.14.1</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.junit</groupId> <artifactId>junit-bom</artifactId> <version>5.10.1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit-platform-engine</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-suite</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.16.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <encoding>UTF-8</encoding> <source>17</source> <target>17</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.2.2</version> </plugin> </plugins> </build> </project> }}} === 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 "<url>" 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 }}}