Mobile Device Testing
Learn about mobile device testing features within leading JavaScript automation frameworks.
It’s a fact that websites are used more nowadays on mobile devices than on desktop machines. With that in mind, developers and test engineers must include mobile device testing as part of their test plan. This core capability can be a bit complicated across analyzed test automation frameworks since testing on simulated viewports or emulators/simulators is only good to some extent. To ensure real-world user experience, performance, and quality on mobile devices, testing must be also done on real devices.
Cypress mobile device testing
Cypress can use the cy.viewport()
APIs to mimic the width and height of a mobile phone screen’s viewport for the website under test; however, this will only give us a basic look and feel for our web application across specified screen sizes. In addition, Cypress offers the use of userAgent
userAgent
is a characteristic string that lets servers and network peers identify the properties of an application, type of operating system, vendor, and OS version of the requesting platform.
We can specify the use of a specific mobile platform userAgent
string within the cypress.json
file or embed it in the test code itself within the onBeforeLoad()
method.
Note: The Mozilla Developer Network (MDN) web docs by Mozilla provide very useful documentation on how to use and specify userAgent
.
As an example, to test a Cypress web application scenario on a Google Pixel 6 device running on Android 12 on a Chrome 96 browser version, we can use the following declaration in our test code with the value: [userAgent]
attribute, as specified in the following:
Get hands-on with 1200+ tech skills courses.