Search code examples
javaseleniumserenity-bdd

Unexpected "data:," windows open during selenium test


I am trying to test if the URL of the window is correct after clicking on a link. But unexpected windows with URL data:, get open between the test and getCurrentUrl grabs the "data:," as the URL and fails the test instead of the actual URL.

The windows with data:, is open even after all the test is complete.

Feature steps:

public void homePageOpens() {
        WebDriverWait wait = new WebDriverWait(driver, 15);
        wait.until(ExpectedConditions.titleContains("STORE"));
        String homepageUrl = navigationUser.getUrl();
        System.out.println(homepageUrl);
        Assert.assertTrue(homepageUrl.contains("https://www.example.com/index.html"));
        driver.close();
    }

Navigation steps:

@Step("Get the URL")
public String getUrl() { return basePage.getUrl();
}

BasePage:

public String getUrl() {
        System.out.println("just testing");
        WebDriver driver = new ChromeDriver();
        return driver.getCurrentUrl();
    }

Solution

  • Replacing base page code with the following worked:

    WebDriver driver = new ChromeDriver();
    return driver.getCurrentUrl();
    

    to

    return getDriver().getCurrentUrl();