Set up Playwright with Perfecto – iOS (BETA)
To integrate Playwright with Perfecto for iOS testing, follow the prerequisites and setup steps below for your preferred programming language. iOS Playwright support is currently in BETA and available only through the Node.js SDK (JavaScript and TypeScript). For information on known limitations and unsupported features, see Playwright known limitations.
For information on Playwright overview and prerequisites, see Playwright.
On this page:
Restrictions
The following restrictions apply to iOS Playwright BETA:
-
Status: BETA, available on real iOS devices only (iOS 18+) provisioned through Perfecto cloud
-
Supported Playwright version: Playwright 1.62 only. Pinning to exact version is required (see Install dependencies). Other Playwright versions are not supported and will not connect.
-
Available platforms: Node.js SDK only (JavaScript and TypeScript). Java is not supported for iOS testing.
-
Cloud configuration: Must specify cloud name in WebSocket URL.
-
Feature gate: Feature must be enabled for your Perfecto cloud/cradle.
Prerequisites
-
A real iOS device provisioned on your Perfecto cloud with iOS Playwright feature setting enabled
-
A Perfecto
securityToken -
The device's
deviceName(UDID), for example00001234-0005ACB12331120E
Mandatory capabilities
| Capability | Value |
|---|---|
platformName
|
'iOS'
|
securityToken
|
your Perfecto security token |
deviceName
|
target device's UDID |
Configuration requirement
The cloud name must be specified in the WebSocket URL used to connect:
wss://{cloudName}.perfectomobile.com/websocket?<encoded capabilities>
Setup steps
Click a language to expand the steps.
-
Pin exact versions with
--save-exact. The BETA server only accepts 1.62 clients. An unpinned^1.62.0range will silently drift to an incompatible version on your nextnpm install.Copynpm install --save-exact --save-dev @playwright/test@1.62 @types/node ts-node
npm install --save-exact playwright@1.62 -
Create a
setup-ios.tsfile that extends Playwright's basetestobject to connect to your Perfecto iOS device instead of launching a local browser:Copyimport { test as base } from '@playwright/test';
import { webkit } from '@playwright/test';
export const test = base.extend({
browser: [async ({}, use) => {
const caps = {
platformName: 'iOS',
securityToken: '<SECURITY_TOKEN>',
deviceName: '<DEVICE_UDID>',
};
const cloudName = 'demo';
const browser = await webkit.connect(
`wss://${cloudName}.perfectomobile.com/websocket?` +
encodeURIComponent(JSON.stringify(caps)),
{ timeout: 90_000 },
);
await use(browser);
await browser.close();
}, { scope: 'worker', timeout: 90_000 }],
page: async ({ browser }, use) => {
const context = await browser.newContext({ hasTouch: true });
const page = await context.newPage();
await use(page);
await page.close();
await context.close();
},
});
export { expect } from '@playwright/test'; -
Import
test/expectfrom yoursetup-ios.tsinstead of@playwright/test, and write a normal Playwright test:Copyimport { test, expect } from './setup-ios';
test('loads the home page', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveTitle(/Example Domain/);
}); -
Run the test:
Copynpx playwright test --config=playwright.ios.config.ts
-
Install Playwright pinned to version 1.62:
Copynpm install --save-exact playwright@1.62 -
Connect with the
webkitbrowser launcher exported fromplaywright, then run your test:Copyconst { webkit } = require('playwright');
(async () => {
const caps = {
platformName: 'iOS',
securityToken: '<SECURITY_TOKEN>',
deviceName: '<DEVICE_UDID>',
};
const cloudName = 'demo';
const browser = await webkit.connect(
`wss://${cloudName}.perfectomobile.com/websocket?` +
encodeURIComponent(JSON.stringify(caps)),
);
const context = await browser.newContext({ hasTouch: true });
const page = await context.newPage();
await page.goto('https://example.com');
console.log(await page.title());
await page.close();
await context.close();
await browser.close();
})();