How to stop selenium chrome testrun at current AUT URL, not at URL "data;"?
I disabled driver.quit()
in order to see the last URL.
I entered a wait after opening the correct AUT URL.
Browser navigation backward is disabled.
I do the following in code:
- use selenium webdriver driver manager to fetch matching chromedriver
driver = new ChromeDriver();
- use AUT URL
driver.get(";); // Replace with the actual homepage URL
- close with
driver.quit()
resp. comment out in order to see the last browser window
After each test is run the corresponding browser window hangs and the URL "data:," is written
This behaviour started just after adding a second cucumber feature file and corresponding second java class w/ stepdefinitions: I had to implement @Before
and @After
in both stepdefinition classes in order to launch the chrome browser!
I updated chrome, which is anized by my company: browserVersion: 134.0.6998.36, chrome: {chromedriverVersion: 134.0.6998.35
Perhaps it is a bad idea to auto update chrome in the test environment!
Any further ideas?
How to stop selenium chrome testrun at current AUT URL, not at URL "data;"?
I disabled driver.quit()
in order to see the last URL.
I entered a wait after opening the correct AUT URL.
Browser navigation backward is disabled.
I do the following in code:
- use selenium webdriver driver manager to fetch matching chromedriver
driver = new ChromeDriver();
- use AUT URL
driver.get("https://verwaltung.zentralregulierung.modellumgebung.ddg-webservice.de/login"); // Replace with the actual homepage URL
- close with
driver.quit()
resp. comment out in order to see the last browser window
After each test is run the corresponding browser window hangs and the URL "data:," is written
This behaviour started just after adding a second cucumber feature file and corresponding second java class w/ stepdefinitions: I had to implement @Before
and @After
in both stepdefinition classes in order to launch the chrome browser!
I updated chrome, which is anized by my company: browserVersion: 134.0.6998.36, chrome: {chromedriverVersion: 134.0.6998.35
Perhaps it is a bad idea to auto update chrome in the test environment!
Any further ideas?
Share Improve this question edited Mar 7 at 12:39 Leder asked Mar 7 at 8:36 LederLeder 3941 gold badge6 silver badges23 bronze badges2 Answers
Reset to default 0Typically, when the WebDriver is initiated, the browser opens with "data;"
in the address bar.
WebDriver driver = new ChromeDriver();
After the initialization is complete, navigate to your application URL:
driver.get("YOUR-APPLICATION-URL");
Additionally, ensure that you are using the correct version of the WebDriver, as version mismatches can sometimes cause issues.
I did some chatGPT magic with dependency injection and the AUT URLs are working again:
----------------Schnipp
Cucumber does not allow step definition classes to extend other classes that also contain step definitions or hooks (@Before
, @After
). To solve this, we need a different approach for sharing the @Before
and @After
setup without inheritance.
✅ Solution: Use Dependency Injection Instead of Inheritance
Instead of extending BaseTest
, you should use composition:
Create a separate utility class (without step definitions) that manages WebDriver setup.
Use an instance of this class in
LoginLogout
andLieferanten
.
1. Create WebDriverManager
(Utility Class)
This class will manage WebDriver and proxy settings but won't contain step definitions.
package bdd.utils;
import .openqa.selenium.Proxy;
import .openqa.selenium.WebDriver;
import .openqa.selenium.chrome.ChromeDriver;
public class WebDriverManager {
private WebDriver driver;
public void setup() {
System.setProperty("http.proxyHost", "100.100.101.58");
System.setProperty("http.proxyPort", "3128");
System.setProperty("https.proxyHost", "100.100.101.58");
System.setProperty("https.proxyPort", "3128");
Proxy proxy = new Proxy();
proxy.setHttpProxy("100.100.101.58:3128");
// Initialize the WebDriver
driver = new ChromeDriver();
}
public WebDriver getDriver() {
return driver;
}
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
2. Update LoginLogout
Class
Instead of extending a base class, create an instance of WebDriverManager
.
package bdd.stepdefinitions;
import bdd.utils.WebDriverManager;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import .openqa.selenium.By;
import .openqa.selenium.WebDriver;
import .openqa.selenium.WebElement;
import java.util.List;
import static .junit.jupiter.api.Assertions.assertEquals;
import static .junit.jupiter.api.Assertions.assertTrue;
public class LoginLogout {
private WebDriverManager webDriverManager = new WebDriverManager();
private WebDriver driver;
@Before
public void setup() {
webDriverManager.setup();
driver = webDriverManager.getDriver();
}
@Given("homepageIsOpened")
public void homepageIsOpened() {
driver.get("https://verwaltung.zentralregulierung.modellumgebung.ddg-webservice.de/login");
}
@When("loginNegative")
public void loginNegative() {
WebElement usernameField = driver.findElement(By.xpath("//*[@id=\"root\"]/div[3]/div/div/div/form/input[1]"));
WebElement passwordField = driver.findElement(By.xpath("//*[@id=\"root\"]/div[3]/div/div/div/form/input[2]"));
WebElement loginButton = driver.findElement(By.xpath("//*[@id=\"root\"]/div[3]/div/div/div/form/button"));
usernameField.sendKeys("wrong-username");
passwordField.sendKeys("wrong-password");
loginButton.click();
List<WebElement> errorMessages = driver.findElements(By.xpath("//div[@role='alert' and @class='fade alert alert-danger show']"));
assertTrue(errorMessages.size() > 0);
assertEquals("Benutzername oder Passwort ist falsch", errorMessages.get(0).getText());
}
@After
public void tearDown() {
webDriverManager.tearDown();
}
}
3. Update Lieferanten
Class
Same approach: use WebDriverManager
without inheritance.
package bdd.stepdefinitions;
import bdd.utils.WebDriverManager;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import .openqa.selenium.By;
import .openqa.selenium.WebDriver;
import .openqa.selenium.WebElement;
import static .junit.jupiter.api.Assertions.assertTrue;
public class Lieferanten {
private WebDriverManager webDriverManager = new WebDriverManager();
private WebDriver driver;
@Before
public void setup() {
webDriverManager.setup();
driver = webDriverManager.getDriver();
}
@When("chooseLieferantenFilialenFiliale")
public void choose_lieferanten_filialen_filiale() {
WebElement stammdaten = driver.findElement(By.xpath("(//*[@id='basic-nav-dropdown'])[1]"));
stammdaten.click();
}
@Then("filialeIsDisplayed")
public void filiale_is_displayed() {
WebElement filialePage = driver.findElement(By.xpath("//some_xpath_for_filiale"));
assertTrue(filialePage.isDisplayed());
}
@After
public void tearDown() {
webDriverManager.tearDown();
}
}
✅ Why This Works
No inheritance issues – Cucumber allows composition but not extending step definitions.
Reusable WebDriver setup –
WebDriverManager
is shared across multiple classes.Clean & maintainable – Easy to update browser settings in one place.
This method ensures that all Cucumber step definitions can use a shared WebDriver instance without breaking Cucumber's rules.
Would you like additional logging or WebDriver wait improvements?