Running into errors due to a redirect and unsure of how to handle it

I have an App that loads a report i am trying to time. The app auto redirects to microsoft SSO where i enter the username and password. I can run the test on a single VU fine, but when i ramp it up to the desired 8 users i start seeing errors like these, likely at the redirect:

: execution context changed; most likely because of a navigation

: getting new document handle: getting document element handle: execution context changed; most likely because of a navigation

I see some of the navigation based waits are not implemented yet and unsure of how to proceed. I’m using the new promise framework as shown on Welcome instead of awaits.
Any help would be appreciated.

The script:

page
.goto(‘https://MyAppUrl’, {
waitUntil: ‘networkidle’,
timeout: 30000
})
.then(() => {
return Promise.all([
console.log(‘waiting for login’),
page.waitForLoadState(‘networkidle’, {timeout: 30000}),
]).then(() => {
// Wait for redirect to SSO login page complete
return Promise.all([
//enter Username only
page.waitForSelector(‘input[name=“loginfmt”]’, {timeout: 30000}),
page.locator(‘input[name=“loginfmt”]’).type(‘user@domain.com’),
page.locator(‘input[value=“Next”]’).click(),
]).then(() => {
return Promise.all([
//wait for password field to display and enter the values
page.waitForSelector(‘div[id=“displayName”]’, {state: ‘visible’}),
page.locator(‘input[name=“passwd”]’).focus(),
page.locator(‘input[name=“passwd”]’).type(‘verySecurePassword’),
page.locator(‘input[value=“Sign in”]’).click(),
page.waitForNavigation(),
page.waitForLoadState(‘networkidle’),

Hi there!

As you can imagine, it’s quite tricky debugging this without being able to run it :wink:

Can you tell where the failure is happening? You might want to put some console.log statements in your script if it isn’t obvious what’s causing the error.

A couple of things that might help:

  • I believe page.waitForSelector is not asynchronous (yet) - try putting it outside of/in front of the Promise.all calls
  • I’m under the impression that page.waitForNavigation() should be the first of the promises passed in to Promise.all. See the last code sample in #428 (“It is important to call waitForNavigation before click to set up waiting”)

Its unfortunate that i dont have a public site for this,but the issue i’m facing is k6 does not actually seem to wait for the element as there is a redirect like so Site A → SSO page. this autoredirect seems to cause all the dynamic waiting methods to start looking for the login field too early…
I’ve tried your suggestions but still see the same login error

in "input[name=\"loginfmt\"]": execution context changed; most likely because of a navigation

Could you share the updated code, please?