Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation on user agent strings #159

Closed
wants to merge 2 commits into from

Conversation

edwinv
Copy link

@edwinv edwinv commented Jul 27, 2021

In our test suite, we also test with mobile user agents. We do this by creating several different drivers with different user agents. Coming from Selenium, I was used to set the user agent in the browser options. With no mention of the user-agent option in the Ferrum or Cuprite documentation, I assumed we needed to use headers:

driver = Capybara::Cuprite::Driver.new(app)
driver.add_header("User-Agent", "...")

This works fine for the first request in the driver, but subsequent requests fail due to the reset of the headers. I found out the user-agent browser option still works fine. I think it is worth a mention in the README so other developers also know how to set the right user-agent string for their drivers.

In our test suite, we also test with mobile user agents. We do this by creating several different drivers with different user agents. Coming from Selenium, I was used to set the user agent in the browser options. With no mention of the `user-agent` option in the Ferrum or Cuprite documentation, I assumed we needed to use headers:

```
driver = Capybara::Cuprite::Driver.new(app)
driver.add_header("User-Agent", "...")
```

This works fine for the first request in the driver, but subsequent requests fail due to the reset of the headers. I found out the `user-agent` browser option still works fine. I think it is worth a mention in the README so other developers also know how to set the right user-agent string for their drivers.
README.md Outdated Show resolved Hide resolved
Capybara::Cuprite::Driver.new(app, { browser_options: { 'user-agent': 'Your own user agent string' } })
```

If you want to change the user-agent for one request, you can use the request headers.
Copy link
Collaborator

@Mifrill Mifrill Aug 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 this spec is passed:

      it "supports User-Agent" do
        @driver.add_header("User-Agent", "foo")
        @session.visit "/"
        expect(@driver.evaluate_script("window.navigator.userAgent")).to eq("foo")
        @session.visit "/"
        expect(@driver.evaluate_script("window.navigator.userAgent")).to eq("foo")
      end

can you please provide the version of which you using and could you please provide a test with this behavior reproduction? It's probably a bug

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the setup running anymore, because we stopped using Cuprite due to incompatibility with our test suite. The request headers through add_header works okay, but is reset after each spec. We set the user agent in the driver before starting the suite, therefore we lost the user agent header. Only when providing the browser_options you can persist the user agent for all requests in the whole suite.

Co-authored-by: Aleksei Strizhak <alexei.mifrill.strizhak@gmail.com>
@route
Copy link
Member

route commented Sep 27, 2021

This sounds like a bug, it shouldn't be like that

@route route added the bug Something isn't working label Sep 27, 2021
@edwinv edwinv closed this Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants