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

How to configure cuprite to test on mobile emulation ? #216

Open
jean-francois-labbe opened this issue Nov 8, 2022 · 3 comments
Open

How to configure cuprite to test on mobile emulation ? #216

jean-francois-labbe opened this issue Nov 8, 2022 · 3 comments

Comments

@jean-francois-labbe
Copy link

I'm trying to migrate to cuprite.
I can't find any setup for mobile testing.
I have the following selenium configuration.

  options = Selenium::WebDriver::Chrome::Options.new
  options.add_argument('--no-sandbox')
  options.add_argument('--headless') unless ENV['VIEW']
  options.add_argument('--disable-dev-shm-usage')
  options.add_argument('--disable-gpu')
  options.add_argument('--window-size=1024,1024')
  options.add_option(
    :mobileEmulation,
    {
      'deviceMetrics' => { 'width' => 360, 'height' => 640, 'pixelRatio' => 3.0 },
      'userAgent' => 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) '\
      'AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
    },
  )
  client = Selenium::WebDriver::Remote::Http::Default.new
  client.open_timeout = 30 # seconds
  client.read_timeout = 10 # seconds

  Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: options,
                                 http_client: client, **selenium_context.url_config)

I'd like to reproduce it with cuprite. I looked in the main repositories using cuprite (using this page). None is testing executing system tests on mobile.

Here is my current attempt.
I tried to specify the mobileEmulation option in different places.
The browsers is not using the mobile emulation.

Capybara.register_driver(:cuprite) do |app|
  Capybara::Cuprite::Driver.new(
    app,
    window_size: [360, 640],
    screen_size: [360, 640],
    browser_options: { 'no-sandbox': nil,
      'mobileEmulation': {
        'deviceMetrics' => { 'width' => 360, 'height' => 640, 'pixelRatio' => 3.0 },
        'userAgent' => 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) '\
        'AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
      },
    },
    headless: false,
    mobile_emulation: {
      'deviceMetrics' => { 'width' => 360, 'height' => 640, 'pixelRatio' => 3.0 },
      'userAgent' => 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) '\
      'AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
    },
  )
end

What am I missing ?

@grekko
Copy link

grekko commented Jan 29, 2024

@jean-francois-labbe did you solve this?

@jean-francois-labbe
Copy link
Author

@grekko sadly it's not solved. Selenium manages to make it work. I think it may need to configure to browser to work in a certain mode so that it all tabs and service worker uses the same user-agent, the one you configured.

@grekko
Copy link

grekko commented Jan 29, 2024

I briefly checked the Ferrum issues page and found rubycdp/ferrum#94 – so we'll have to wait for this being available before the ruby driver can make use of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants