Set user agent for browser tests

For a browser test I am trying to set up I need to bypass a specific form that I can do by setting the user agent string to be google bot.

This works fine when I use the normal api based tests using { http }, however, when I want to take a screenshot of a page, or interact with components I need to use { browser }. It does not seem browser uses the user-agent set in the exported options, not does it seem to have the option to set it in its own options.

Is it possible to set the user-agent for browser based testing, and if so, how?

Yes you can do this.

It’s just an option that you set in the options structure within your test script:

Yeah I tried that, but it doesn’t seem to work. I still get redirected to the form which is not what I expect.

export const options = {
  userAgent: 'Googlebot/2.1 (+http://www.google.com/bot.html)',
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
}

Also tried it like this:

export const options = {
  
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
          userAgent: 'Googlebot/2.1 (+http://www.google.com/bot.html)',
        },
      },
    },
  },
}

Hi @ddemoel,

As explained in the documentation, you can use the userAgent option to set the user agent through the newContext function.

Thanks.

1 Like

Ah must have looked over that!

It’s working, thnks :slight_smile:

1 Like