### TestingBot Playwright Environment Setup and Execution Commands (Bash) Source: https://context7.com/testingbot/node-playwright-test-example/llms.txt A set of bash commands for setting up the Playwright testing environment and executing tests with TestingBot. This includes cloning the repository, installing dependencies, setting TestingBot credentials via environment variables, and running different test configurations (desktop, Android, custom timeouts, retries, CI mode). ```bash # Clone repository git clone cd playwright-example # Install dependencies npm install # Set TestingBot credentials (required) export TB_KEY="your_testingbot_key" export TB_SECRET="your_testingbot_secret" # Run desktop browser tests (parallel across 3 browsers) npm run sample-test # Run Android device test npm run android-test # Run with custom timeout TEST_TIMEOUT=60000 npm run sample-test # Run with retry configuration TEST_RETRIES=3 npm run sample-test # CI mode execution CI=true npm run sample-test # View test results # HTML report: ./playwright-report/index.html # Dashboard: https://testingbot.com/members/ ``` -------------------------------- ### Playwright Android Mobile Test Configuration (TypeScript) Source: https://context7.com/testingbot/node-playwright-test-example/llms.txt Provides a specialized Playwright configuration for Android mobile device testing via TestingBot. It utilizes custom fixtures to manage Android device connections and browser contexts, ensuring proper setup for mobile testing environments. ```typescript // playwright-android.config.ts import { defineConfig } from '@playwright/test'; export default defineConfig({ testDir: './tests', testMatch: '**/android*.spec.ts', timeout: 30 * 1000, expect: { timeout: 10 * 1000 }, retries: process.env.CI ? 2 : 0, reporter: [['html'], ['list']], use: { actionTimeout: 10 * 1000, navigationTimeout: 30 * 1000 }, projects: [{ name: 'android' }] }); // Run Android tests: npm run android-test // or: npx playwright test --config=playwright-android.config.ts tests/android.spec.ts ``` -------------------------------- ### Desktop Browser Test Example with TestingBot Fixture (TypeScript) Source: https://context7.com/testingbot/node-playwright-test-example/llms.txt A sample Playwright test that utilizes the custom `baseTest` fixture for desktop browser testing. It demonstrates navigating to a website, interacting with elements, and verifying URL changes, running in parallel across configured browser/platform combinations. Dependencies include './baseTest' and '@playwright/test'. ```typescript import { test, expect } from './baseTest'; test('Sample TestingBot test', async ({ page }) => { // Navigate to target website await page.goto('https://playwright.dev/'); // Interact with page elements await page.getByRole('link', { name: 'Get started' }).click(); // Verify expected outcome await expect(page).toHaveURL(/.*intro/); }); // Run with: npm run sample-test // Executes on: Chrome/Windows 10, Safari/macOS, Firefox/Linux // View results at: https://testingbot.com/members/ ``` -------------------------------- ### Android Mobile Test Example with TestingBot Fixture (TypeScript) Source: https://context7.com/testingbot/node-playwright-test-example/llms.txt A sample Playwright test demonstrating Android mobile browser testing using the custom `androidPage` fixture. This test navigates to a specified URL on a remote Android device and verifies the page title, showcasing mobile testing capabilities. Dependencies include './android.fixture' and '@playwright/test'. ```typescript import { test, expect } from './android.fixture'; test('Sample TestingBot Android test', async ({ androidPage }) => { // Navigate to website on Android device await androidPage.goto('https://testingbot.com'); // Verify page loaded correctly await expect(androidPage).toHaveTitle(/TestingBot/); }); // Run with: npm run android-test // Device: Pixel 9, Android, Chrome 15.0 // View results at: https://testingbot.com/members/ ``` -------------------------------- ### Android Device Fixture for TestingBot (TypeScript) Source: https://context7.com/testingbot/node-playwright-test-example/llms.txt This custom Playwright fixture is designed for Android device testing. It establishes a connection to TestingBot's Android device grid, launches a browser on the device, and provides a configured `page` object for automation. It includes necessary cleanup steps for the device connection and browser context. Dependencies include 'playwright-core', './baseTest', and '../testingbot.config'. ```typescript import { _android } from 'playwright-core'; import { test as base } from './baseTest'; import { getConnectWsEndpoint } from '../testingbot.config'; export const test = base.extend({ androidPage: async ({}, use) => { // Generate WebSocket endpoint for Android device const wsEndpoint = getConnectWsEndpoint({ browserName: 'chrome', browserVersion: '15.0', platformName: 'Android', deviceName: 'Pixel 9' }); // Connect to Android device const device = await _android.connect(wsEndpoint); const context = await device.launchBrowser(); const [page] = context.pages(); // Provide page to test await use(page); // Cleanup after test await context.close(); await device.close(); } }); export { expect } from './baseTest'; ``` -------------------------------- ### Custom Playwright Fixture for TestingBot Session Management (TypeScript) Source: https://context7.com/testingbot/node-playwright-test-example/llms.txt This custom Playwright fixture extends the base test to manage TestingBot session names and report test statuses. It automatically sets the session name before a test starts and reports 'passed' or 'failed' statuses after completion, enhancing visibility in the TestingBot dashboard. Dependencies include '@playwright/test'. ```typescript import { test as base } from '@playwright/test'; export const test = base.extend({ page: async ({ page }, use, testInfo) => { // Set session name before test await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({ action: 'setSessionName', arguments: { name: testInfo.project.name } })}` ); await use(page); // Report test status after completion if (testInfo.status === 'passed') { await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({ action: 'setSessionStatus', arguments: { passed: true } })}` ); } else if (['failed', 'interrupted', 'timedOut'].includes(testInfo.status!)) { await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({ action: 'setSessionStatus', arguments: { passed: false, reason: testInfo.error?.message } })}` ); } } }); export { expect } from '@playwright/test'; ``` -------------------------------- ### Playwright Desktop Browser Test Configuration (TypeScript) Source: https://context7.com/testingbot/node-playwright-test-example/llms.txt Configures Playwright for running tests on remote desktop browsers across multiple platforms in parallel. It excludes Android-specific test files and sets up browser connections to the TestingBot grid. This configuration is essential for distributed desktop testing. ```typescript // playwright.config.ts import { defineConfig } from '@playwright/test'; import { getConnectWsEndpoint } from './testingbot.config'; export default defineConfig({ testDir: './tests', testIgnore: '**/android*.spec.ts', timeout: 30 * 1000, expect: { timeout: 10 * 1000 }, retries: process.env.CI ? 2 : 0, workers: process.env.CI ? 1 : undefined, reporter: [['html', { outputFolder: 'playwright-report' }], ['list']], projects: [ { name: 'playwright-chrome@latest:Windows 10', use: { connectOptions: { wsEndpoint: getConnectWsEndpoint({ browserName: 'chrome', browserVersion: 'latest', platform: 'WIN10' }) } } }, { name: 'playwright-webkit@latest:macOS Sequoia', use: { connectOptions: { wsEndpoint: getConnectWsEndpoint({ browserName: 'safari', platform: 'SEQUOIA' }) } } } ] }); // Run tests: npm run sample-test // or: npx playwright test tests/sample.spec.ts ``` -------------------------------- ### Generate TestingBot WebSocket Connection URL (TypeScript) Source: https://context7.com/testingbot/node-playwright-test-example/llms.txt Generates a WebSocket endpoint URL for Playwright to connect to TestingBot's remote browser grid. It accepts custom capabilities and merges them with TestingBot authentication credentials from environment variables. This function is crucial for establishing the connection to the remote testing environment. ```typescript import { getConnectWsEndpoint } from './testingbot.config'; // Desktop browser configuration const chromeEndpoint = getConnectWsEndpoint({ browserName: 'chrome', browserVersion: 'latest', platform: 'WIN10' }); // Returns: "wss://cloud.testingbot.com/playwright?capabilities=%7B%22tb%3Aoptions%22%3A%7B%22key%22%3A%22YOUR_KEY%22%2C%22secret%22%3A%22YOUR_SECRET%22%7D%2C%22browserName%22%3A%22chrome%22%2C%22browserVersion%22%3A%22latest%22%2C%22platform%22%3A%22WIN10%22%7D" // Android device configuration const androidEndpoint = getConnectWsEndpoint({ browserName: 'chrome', browserVersion: '15.0', platformName: 'Android', deviceName: 'Pixel 9' }); // Use with Playwright connect options import { chromium } from 'playwright'; const browser = await chromium.connect(chromeEndpoint); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.