Redirect does not work with httpCredentials

The code being tested has js that redirects the user, using
document.location = "http://localhost/somePage.html";
But nothing happens, it sits there with a page loading in the browser (running headless:false)

Note: testing this in a browser, not through k6 runs as expected, it redirects to somepage.html

And it tried this on a server that does not have basic auth, and it redirects as expected.

Otherwise, many thanks for the k6 tool in general.

import { browser } from 'k6/experimental/browser';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        }
      },
    },
  }
}

export default async function () {
  const page = browser.newPage({
    "httpCredentials": {
      "username": __ENV.STAGING_WEB_USER,
      "password": __ENV.STAGING_WEB_PASSWORD,
    }
  });

  try {
    await page.goto('http://localhost/img/test-redir.html');
    sleep(10);
  } finally {
    page.close();
  }
}

I created a simple version of the page to demonstrate test-redir.html

<html>
	<body>
	test redirect
	<script>
                document.location = "http://localhost/somePage.html";
	</script>

	</body>
</html>
1 Like

Hi @kevindrew,

Thank you for providing the test script and HTML page. We’re able to reproduce the issue, and it looks like a bug. I’ve reported the issue on our repository here.

Thank you

1 Like