Mobile Device Emulation | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Advanced Tricks and Techniques
Instructor: Artem Bondar
Lesson Summary
This lesson focuses on running tests on mobile emulators using Playwright, allowing you to test web applications on various devices like the iPhone and Android. Setting Up Mobile Tests To begin, a new test file named testMobile.spec.ts is created. The following steps are involved: Import the Playwright library. Use beforeEach to navigate to the application. Navigate to the form layout page and simplify the test code. Creating a Mobile Project To run tests on mobile devices: Create a new project named Mobile . Specify the test to run using test match with testMobile.spec.ts . Use a use block to select the desired device from the available options. Running and Improving Tests After running the test on an iPhone 13 Pro, issues may arise due to the mobile responsive view. To resolve this: Identify and click the menu icon to access the form layout. Use unique locators to ensure the menu displays correctly. Implement conditions to handle different test scenarios based on the project name. Universal Test Optimization To make tests adaptable for both mobile and desktop: Utilize test info.project.name to conditionally execute steps. Ensure the test runs successfully in both environments. In summary, creating a separate mobile project and using conditional logic allows for efficient testing across platforms. This approach enhances code reusability and simplifies the testing process.