I'm faced with issue when my tests on remote (CI+saucelabs or local machine + saucelabs remote) are not the similar.
I have a site (e.g. example.com)
My scenario consists on next steps:
inside the step 5 - browser.getUrl() should refers to example2.com (on local execution without saucelabs it's true), but on saucelabs I get example.com.
env:
nodejs: 16.13.1
npm: 8.1.2
libs:
@wdio/cli: 6.10.11
@wdio/sauce-service: 6.3.6
Without seeing more code it's hard to tell, but I suspect the problem is either timing related, or Selenium doing some weird caching.
(Sauce Labs acts as a proxy in this instance; It does nothing besides send commands to Selenium and relay responses back to your test runner.)
The network distance between a Sauce Labs browser and your SUT is going to be different than that between your local browsers and your SUT... especially if the SUT is located inside your corporate network. That makes me suspect there Sauce Labs browser may have to wait longer for your SUT to completely load, and the browser itself is telling Selenium it's on the wrong page still.
If you add a browser.waitUntil(browser.getUrl() === "desired_url", timeout), with a timeout of "30000", does your test start working? If so, it is a problem with the browser load time and you can either see what you can do to improve load time or just leave the wait in place.
I'd lower the timeout value after diagnosis though, to something more sensible.