Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide working example of PW test code of a web app that can be run on a browser of a real mobile device #982

Open
craitose opened this issue Nov 20, 2024 · 0 comments

Comments

@craitose
Copy link

craitose commented Nov 20, 2024

🚀 Feature Proposal

A clear and concise description of what the feature is.
There is claim of supporting Playwright but not Playwright tests on a mobile device. Currently the only support is Windows OS/Mac OS but I imagine as playwright supports mobile viewports in which it runs web apps in virtual browsers. It should not be too difficult to provide capabilities to run these mobile viewports tests in the browsers of real devices. As the tests are testing a web app and not an application, the use of Appium and XCUI libraries should not be needed.
If this is currently possible , please add it the repo and docs as a example.

Motivation

Allow users to test web-app behavior on real devices using existing playwright code.

Example

config code:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'SauceLab iOS Safari',
      use: {
        browserName: 'webkit', // Safari runs on WebKit
        viewport: { width: 375, height: 667 }, // iPhone dimensions
        browserstack: {
          os: 'ios',
          os_version: '14', // Specify iOS version
          device: 'iPhone 12', // Specify device
        },
      },
    },
  ],
});

test code:

import { chromium } from 'playwright';

(async () => {
    const browser = await chromium.connect({
        wsEndpoint: 'wss://your-cloud-service-url.com/playwright-session',
        headers: {
            'x-access-key': 'your-access-key',
        },
    });

    const context = await browser.newContext();
    const page = await context.newPage();

    await page.goto('https://your-web-app.com');
    console.log(await page.title());
    await browser.close();
})();

test execution:

npx playwright test --project="SauceLab iOS Safari"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants