Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example cucumber test #1180

Merged
merged 10 commits into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/cucumber/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
Original file line number Diff line number Diff line change
@@ -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 {


}
Original file line number Diff line number Diff line change
@@ -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 {
bsideup marked this conversation as resolved.
Show resolved Hide resolved

private BrowserWebDriverContainer container = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
.withRecordingMode(RECORD_ALL, new File("target"));
stsefanenko marked this conversation as resolved.
Show resolved Hide resolved

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<WebElement> 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);
}


}
Original file line number Diff line number Diff line change
@@ -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 "<location>"
When I ask is it possible to search here
Then I should be told "<answer>"

Examples:
| location | answer |
| https://www.google.com/ | YES |
| https://www.google.com/appsstatus | NOPE |
1 change: 1 addition & 0 deletions examples/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ include 'redis-backed-cache-testng'
include 'selenium-container'
include 'singleton-container'
include 'spring-boot'
include 'cucumber'