'How to combine device emulation and headless mode in TestCafe
I'm trying to see if I can run my TestCafe cases in Headless Chrome browser using emulator device. I followed the instructions from TestCafe doc and I wasn't successful in it. (https://testcafe.io/documentation/402828/guides/concepts/browsers#use-emulation-in-headless-mode)
Below is the command I tried to use to run the same testcafe "chrome:headless:emulation:device=iphone X" ./tests/ --test-meta tags=Core
Actual - When I ran this command, the chrome headless browser was launched without the emulator. And the XPATH was failing since it wasn't the emulator.
Could anyone please let me know how to handle this?
Solution 1:[1]
I ran the following test:
import { ClientFunction } from 'testcafe';
const getUserAgent = ClientFunction(() => navigator.userAgent);
fixture `Fixture`;
test.meta('tags', 'Core')('test', async t => {
console.log(await getUserAgent());
});
The test report indicates that emulated device is set correctly (see the userAgent string).

Could you please clarify how you determine that the emulator is not launched?
Solution 2:[2]
I can do this with this:
testcafe "chrome:headless:emulation:device=iphone X;cdpPort=9223" tests/sample-fixture.js
And I can notice that is device emulator taking a screenshot.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mlosev |
| Solution 2 | Tyler2P |
