diff --git a/examples/cucumber/build.gradle b/examples/cucumber/build.gradle new file mode 100644 index 00000000000..f8744b9d0e8 --- /dev/null +++ b/examples/cucumber/build.gradle @@ -0,0 +1,16 @@ +plugins { + id 'java' +} + +repositories { + jcenter() +} + +dependencies { + implementation 'org.seleniumhq.selenium:selenium-remote-driver:3.14.0' + implementation 'org.seleniumhq.selenium:selenium-firefox-driver:3.14.0' + implementation 'org.seleniumhq.selenium:selenium-chrome-driver:3.14.0' + implementation 'io.cucumber:cucumber-java:2.3.1' + testImplementation 'io.cucumber:cucumber-junit:2.3.1' + testImplementation 'org.testcontainers:selenium' +} diff --git a/examples/cucumber/src/test/java/org/testcontainsers/examples/CucumberTest.java b/examples/cucumber/src/test/java/org/testcontainsers/examples/CucumberTest.java new file mode 100644 index 00000000000..df1a449f1a9 --- /dev/null +++ b/examples/cucumber/src/test/java/org/testcontainsers/examples/CucumberTest.java @@ -0,0 +1,12 @@ +package org.testcontainsers.examples; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions(plugin = {"pretty"}) +public class CucumberTest { + + +} diff --git a/examples/cucumber/src/test/java/org/testcontainsers/examples/Stepdefs.java b/examples/cucumber/src/test/java/org/testcontainsers/examples/Stepdefs.java new file mode 100644 index 00000000000..ee3c05d4457 --- /dev/null +++ b/examples/cucumber/src/test/java/org/testcontainsers/examples/Stepdefs.java @@ -0,0 +1,70 @@ +package org.testcontainsers.examples; + +import cucumber.api.Scenario; +import cucumber.api.java.After; +import cucumber.api.java.Before; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.testcontainers.containers.BrowserWebDriverContainer; +import org.testcontainers.lifecycle.TestDescription; + +import java.io.File; +import java.util.List; +import java.util.Optional; + +import static junit.framework.TestCase.assertEquals; +import static org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL; + +public class Stepdefs { + + private BrowserWebDriverContainer container = new BrowserWebDriverContainer() + .withCapabilities(new ChromeOptions()) + .withRecordingMode(RECORD_ALL, new File("build")); + + private String location; + private String answer; + + @Before + public void beforeScenario() { + container.start(); + } + + @After + public void afterScenario(Scenario scenario) { + container.afterTest(new TestDescription() { + @Override + public String getTestId() { + return scenario.getId(); + } + + @Override + public String getFilesystemFriendlyName() { + return scenario.getName(); + } + }, Optional.of(scenario).filter(Scenario::isFailed).map(__ -> new RuntimeException())); + } + + @Given("^location is \"([^\"]*)\"$") + public void locationIs(String location) throws Exception { + this.location = location; + } + + @When("^I ask is it possible to search here$") + public void iAskIsItPossibleToSearchHere() throws Exception { + RemoteWebDriver driver = container.getWebDriver(); + driver.get(location); + List searchInputs = driver.findElementsByTagName("input"); + answer = searchInputs != null && searchInputs.size() > 0 ? "YES" : "NOPE"; + } + + @Then("^I should be told \"([^\"]*)\"$") + public void iShouldBeTold(String expected) throws Exception { + assertEquals(expected, answer); + } + + +} diff --git a/examples/cucumber/src/test/resources/org/testcontainsers/examples/is_search_possible.feature b/examples/cucumber/src/test/resources/org/testcontainsers/examples/is_search_possible.feature new file mode 100644 index 00000000000..48ab4a7d5dc --- /dev/null +++ b/examples/cucumber/src/test/resources/org/testcontainsers/examples/is_search_possible.feature @@ -0,0 +1,12 @@ +Feature: Is it possible to search here? + Everybody wants to search something + + Scenario Outline: Is search possible here + Given location is "" + When I ask is it possible to search here + Then I should be told "" + + Examples: + | location | answer | + | https://www.google.com/ | YES | + | https://www.google.com/appsstatus | NOPE | \ No newline at end of file diff --git a/examples/settings.gradle b/examples/settings.gradle index 52617937c04..671646b76d6 100644 --- a/examples/settings.gradle +++ b/examples/settings.gradle @@ -10,4 +10,5 @@ include 'redis-backed-cache-testng' include 'selenium-container' include 'singleton-container' include 'spring-boot' +include 'cucumber'