Skip to content

Commit e1dd7cb

Browse files
kiviewAnna Chernyshova
andcommitted
Fix deprecated API usage in Cucumber examples.
Co-authored-by: Anna Chernyshova <[email protected]>
1 parent 780b97c commit e1dd7cb

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

examples/cucumber/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ repositories {
77
}
88

99
dependencies {
10-
implementation 'org.seleniumhq.selenium:selenium-remote-driver:3.141.59'
11-
implementation 'org.seleniumhq.selenium:selenium-firefox-driver:3.141.59'
12-
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:3.141.59'
10+
testImplementation 'org.seleniumhq.selenium:selenium-java:4.1.0'
1311
testImplementation 'io.cucumber:cucumber-java:6.11.0'
1412
testImplementation 'io.cucumber:cucumber-junit:6.11.0'
1513
testImplementation 'org.testcontainers:selenium'

examples/cucumber/src/test/java/org/testcontainsers/examples/Stepdefs.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.cucumber.java.en.Given;
77
import io.cucumber.java.en.Then;
88
import io.cucumber.java.en.When;
9+
import org.openqa.selenium.By;
910
import org.openqa.selenium.WebElement;
1011
import org.openqa.selenium.chrome.ChromeOptions;
1112
import org.openqa.selenium.remote.RemoteWebDriver;
@@ -21,7 +22,7 @@
2122

2223
public class Stepdefs {
2324

24-
private BrowserWebDriverContainer container = new BrowserWebDriverContainer()
25+
private final BrowserWebDriverContainer<?> container = new BrowserWebDriverContainer<>("selenium/standalone-chrome:4")
2526
.withCapabilities(new ChromeOptions())
2627
.withRecordingMode(RECORD_ALL, new File("build"));
2728

@@ -49,20 +50,20 @@ public String getFilesystemFriendlyName() {
4950
}
5051

5152
@Given("^location is \"([^\"]*)\"$")
52-
public void locationIs(String location) throws Exception {
53+
public void locationIs(String location) {
5354
this.location = location;
5455
}
5556

5657
@When("^I ask is it possible to search here$")
57-
public void iAskIsItPossibleToSearchHere() throws Exception {
58-
RemoteWebDriver driver = container.getWebDriver();
58+
public void iAskIsItPossibleToSearchHere() {
59+
RemoteWebDriver driver = new RemoteWebDriver(container.getSeleniumAddress(), new ChromeOptions());
5960
driver.get(location);
60-
List<WebElement> searchInputs = driver.findElementsByTagName("input");
61+
List<WebElement> searchInputs = driver.findElements(By.tagName("input"));
6162
answer = searchInputs != null && searchInputs.size() > 0 ? "YES" : "NOPE";
6263
}
6364

6465
@Then("^I should be told \"([^\"]*)\"$")
65-
public void iShouldBeTold(String expected) throws Exception {
66+
public void iShouldBeTold(String expected) {
6667
assertEquals(expected, answer);
6768
}
6869

0 commit comments

Comments
 (0)