Redirection problem

Dear all,
I am having trouble with the redirection page during a browser test. Despite the sleep(10) and all the page.waitForNavigation() when I finally ask for page.title() the output is not the final page’s title.

Tis is the code:

import { chromium, Frame } from 'k6/experimental/browser';
import { check, sleep } from 'k6';

export const options = {
  maxRedirects: 20,
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      exec: 'browser',
      vus: 1,
      maxDuration: '1m',
      
    },
  },
};

export async function browser() {
  const browser = chromium.launch({ headless: false ,timeout: '120s',slowMo:'500ms'});
  const context = browser.newContext();
  let page = context.newPage();
  await page.goto('http://localhost:5000/', { waitUntil: 'networkidle' });

  const cookieButton = await page.locator('//*[@id="cookies-banner"]/div/div[2]/button');
  await cookieButton.click();

  await page.locator('#company-input').type('Test1');
  const continueButton = await page.locator('#company-login-continue-button');
  
  await Promise.all([
    page.waitForNavigation(),
    continueButton.click(),
  ]);

  /* check(page, {
    'Button': (page) => page.locator('//*[@id="login-method-selection-password-login-button"]/p').textContent() == 'USERNAME & PASSWORD',
  }); */

  sleep(1);

  const loginButton = await page.locator('//*[@id="login-method-selection-password-login-button"]/p');

  await Promise.all([
    page.waitForNavigation(),
    loginButton.click(),
  ]);

  sleep(1);

  await page.locator('#user-name-input').type('TestUsername');
  await page.locator('#password-input').type('TestPassword');

  const continueButton2 = await page.locator('//*[@id="password-login-continue-button"]/p');

  await Promise.all([
    page.waitForNavigation(),
    continueButton2.click(),
  ]);
  
  sleep(10)
  console.log(page.title())
  await page.close();
  await browser.close();
}

Thank you!!

Hi @kefnikolas,

Thank you for your question and I apologies for the lateness in my reply.

I’ve taken a look at your script and I can’t see anything that would cause the title issue you’ve raised. I’ve tried to replicate the issue with the fillform.js example script (and remembering to add console.log(page.title() to the end), but it is printing the expected title:

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

export const options = {
  maxRedirects: 20,
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      exec: 'browser',
      vus: 1,
      maxDuration: '1m',
    },
  },
};

export async function browser() {
  const browser = chromium.launch({ headless: false ,timeout: '120s',slowMo:'500ms'});
  const context = browser.newContext();
  let page = context.newPage();
  await page.goto('https://test.k6.io', { waitUntil: 'networkidle' });

  await Promise.all([
    page.waitForNavigation(),
    page.locator('a[href="/my_messages.php"]').click(),
  ]);

  page.locator('input[name="login"]').type('admin');
  page.locator('input[name="password"]').type('123');

  await Promise.all([
    page.waitForNavigation(),
    page.locator('input[type="submit"]').click(),
  ]);
  
  sleep(10)
  console.log(page.title())
  page.close();
  browser.close();
}

Prints:

INFO[0016] My messages                                   source=console

Can you try to replicate the issue with a public facing website and send us the new script? The output of the test would also be useful along with what you expect the output to be, and what is actually being printed.

Cheers,
Ankur