getUrl always returns wrong results

I have the same issue, with WebUI.getUrl() and waitForPageLoad is not working.
All my test cases (where i want assert starts like this)

assert GlobalVariable.url + GlobalVariable.url_reg_6 == WebUI.getUrl()  

and geturl always returns wrong result.
For me therad.sleep woriking as well, but sometimes it returns previous url too, and test failed.

Is there any other soulitions, suggestion for this problem?

1 Like

Like I said, fixed value delays are NOT reliable.

Write a loop that allows you to check the URL. When the URL has changed, THEN check it’s the URL you expect. The following code should get you started (it’s a barebones version of something I use, you can modify it to suit your task).

// wait until oldURL changes to newURL
WebDriver driver = DriverFactory.getWebDriver()
int timeout = 20 // wait 20 seconds total
boolean timedout = false
int count = 0
boolean same = true
  if(count > timeout) {
    timedout = true
    break; // or throw exception
  // Check if URL has changed yet and restart the loop
  same = (boolean) (url == driver.getCurrentUrl())

// check if the loop timedout...
if(timedout) {
  // fail, the loop timedout
} else {
  // pass, the URL changed