-1

I'm writing a test with Serenity BDD-Cucumber.

I want to check if the URL is correct when it's navigated. But the result always shows data, and my test fails with driver.getCurrentUrl().

Please see my code below:

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

This also opens a page with URL: "data:," which doesn't close after the test

SUPARNA SOMAN
  • 2,311
  • 3
  • 19
  • 35

1 Answers1

1

Use driver.get in order to navigate somewhere.

String someUrl = "https://www.example.com/index.html";
driver.get(someUrl);

This code:

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

just launch the browser, and the initial url is data:,.

Also it's unclear why BasePage getUrl() method launches the new webdriver and uses it as a local variable. But in homePageOpens() method in feature steps looks like some another driver used..

Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14