How to configure cuprite to test on mobile emulation ?
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 ?
@jean-francois-labbe did you solve this?
@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.
I briefly checked the Ferrum issues page and found https://github.com/rubycdp/ferrum/issues/94 – so we'll have to wait for this being available before the ruby driver can make use of it.