I have to write tests for web application and also I have to use them on mobile chrome browser.It is any possibility to use chrome devtools and mobile device emulator during test?
Thanks for help
I have to write tests for web application and also I have to use them on mobile chrome browser.It is any possibility to use chrome devtools and mobile device emulator during test?
Thanks for help
You can use Chrome mobile emulation by passing chrome options to webdriver.
For example, if you use WebDriverIO helper and want to use Nexus 5:
helpers: {
WebDriverIO: {
url: "https://rambler.ru",
browser: "chrome",
...
desiredCapabilities: {
chromeOptions: {
mobileEmulation: {
deviceName: "Nexus 5"
}
}
}
}
}
Or if you want to specify something more specific:
chromeOptions: {
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"
}
}
}
More information here: http://chromedriver.chromium.org/mobile-emulation
For Puppeteer use chrome option in config with defaultViewport value.
https://codecept.io/helpers/Puppeteer/#configuration https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
Or use
page.emulate()
before each test https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageemulateoptionsUPD: add page.emulate example
For
page.emulate
using: In custom helper, create own function, which will work with page for example:Where option is object with viewport and userAgent: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageemulateoptions https://codecept.io/helpers/Puppeteer/#access-from-helpers
Then in test: Create options:
And you can call it in your code: