-1

I'm making an UI test, where I should check out, if the registration was successful. My code gets executed, and it does make the registration successfully, however when I want to assert that the URL gets redirected to the "http://localhost:8080/sportsbetting-web/home";

My code fails, stating that:

org.junit.ComparisonFailure: 
Expected :http://localhost:8080/sportsbetting-web/register
Actual   :http://localhost:8080/sportsbetting-web/home

My assertion looks like this:

button.click(); //registration button is clicked
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); //wait so it has time to redirect
String actualUrl = "http://localhost:8080/sportsbetting-web/home";
String expectedUrl = driver.getCurrentUrl();
Assert.assertEquals(actualUrl,expectedUrl);

I tried switching the expectedUrl and actualUrl, but it doesn't work.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mate25
  • 65
  • 6
  • Does this answer your question? [Wait for page load in Selenium](https://stackoverflow.com/questions/5868439/wait-for-page-load-in-selenium) – Lunatic Jun 03 '22 at 11:46
  • No, since I'm aleady trying to use waits, but it doesnt solve my problem. – Mate25 Jun 03 '22 at 11:51
  • As an aside, you're confusing the meaning of _actual_ and _expected_. _Expected_ is what *you* think the value should be, and _actual_ is the actual value produced by the code. – Mark Rotteveel Jun 03 '22 at 15:48

1 Answers1

0

Implicit wait is not a sleep. It's a polling loop that triggers when finding an element and ignores element not found. It'll throw a timeout if the timeout period is met. Since Selenium will not wait automatically for a redirect, you need a standard sleep, or use a driver find element method that attempts to find an element that appears once logged in (this would be quicker than a standard sleep.) The reason you need this is because the browser needs time to save login state, usually via cookies, and then to perform the redirect. Your current code does not wait at all.

(I also recommend ditching the implicit wait and using explicit waits throughout your code.)

pcalkins
  • 1,188
  • 13
  • 20