Skip to content

Commit

Permalink
Merge pull request #54 from amrsa1/parallel-test-pw-ts
Browse files Browse the repository at this point in the history
Instantiate LT WS connection from config file
  • Loading branch information
4DvAnCeBoY authored Mar 22, 2023
2 parents 3f30746 + a439a04 commit 4657733
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
16 changes: 16 additions & 0 deletions playwright-config-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "playwright-test-suite",
"version": "1.0.0",
"author": "LambdaTest",
"engines": {
"node": ">=12.0.0"
},
"description": "Sample project to run playwright tests using playwright runner on LambdaTest platform",
"scripts": {
"test": "npx playwright test --config=./playwright.config.ts"
},
"devDependencies": {
"@playwright/test": "^1.24.0",
"playwright": "^1.24.0"
}
}
115 changes: 115 additions & 0 deletions playwright-config-ts/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import type { PlaywrightTestConfig } from "@playwright/test";
import { devices } from "@playwright/test";

const capabilities = [{
browserName: "Chrome", // Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
browserVersion: "latest",
"LT:Options": {
platform: "Windows 10",
build: "Playwright Build",
name: "Playwright Test",
user: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
network: true,
video: true,
console: true,
tunnel: false, // Add tunnel configuration if testing locally hosted webpage
tunnelName: "", // Optional
geoLocation: '', // country code can be fetched from https://www.lambdatest.com/capabilities-generator/
},
},
{
browserName: "pw-webkit", // Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
browserVersion: "latest",
"LT:Options": {
platform: "MacOS Monterey",
build: "Playwright Build",
name: "Playwright Test",
user: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
network: true,
video: true,
console: true,
tunnel: false, // Add tunnel configuration if testing locally hosted webpage
tunnelName: "", // Optional
geoLocation: '', // country code can be fetched from https://www.lambdatest.com/capabilities-generator/
},
}
];

// Playwright config to run tests on LambdaTest platform and local
const config: PlaywrightTestConfig = {
testDir: "tests",
timeout: 60000,
use: {},
projects: [
// -- LambdaTest Config --
// name in the format: browserName:browserVersion:platform@lambdatest
// Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
// Use additional configuration options provided by Playwright if required: https://playwright.dev/docs/api/class-testconfig
{
name: "chrome:latest:windows 10@lambdatest",
use: {
connectOptions: {
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(
JSON.stringify(capabilities[0])
)}`
},
viewport: { width: 1920, height: 1080 },
},
},
{
name: "safari:latest:macOs Monterey@lambdatest",
use: {
connectOptions: {
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(
JSON.stringify(capabilities[1])
)}`
},
viewport: { width: 1280, height: 720 },
},
},
{
name: "safari:latest:macOs Monterey@lambdatest",
use: {
connectOptions: {
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(
JSON.stringify(capabilities[1])
)}`
},
...devices["iPhone 12 Pro Max"],
},
}
// Config for running tests in local
// {
// name: "chrome",
// use: {
// browserName: "chromium",
// channel: "chrome",
// },
// },
// {
// name: "safari",
// use: {
// browserName: "webkit",
// viewport: { width: 1200, height: 750 },
// },
// },
// {
// name: "firefox",
// use: {
// browserName: "firefox",
// viewport: { width: 800, height: 600 },
// },
// },
// // Test in mobile viewport.
// {
// name: "chrome@pixel5",
// use: {
// ...devices['iPhone 12 Pro Max'],
// }
// },
],
};

export default config;
17 changes: 17 additions & 0 deletions playwright-config-ts/tests/test_1.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import test from "../lambdatest-setup";
import { expect } from "@playwright/test";

test.describe("Browse LambdaTest in different search engines", () => {
test("Search LambdaTest on Bing", async ({ page }) => {
await page.goto("https://www.bing.com");
const element = await page.$('[aria-label="Enter your search term"]');
await element.click();
await element.type("LambdaTest");
await element.press("Enter");
const title = await page.title();

console.log("Page title:: ", title);
// Use the expect API for assertions provided by playwright
expect(title).toEqual(expect.stringContaining("LambdaTest"));
});
});
17 changes: 17 additions & 0 deletions playwright-config-ts/tests/test_2.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import test from "../lambdatest-setup";
import { expect } from "@playwright/test";

test.describe("Browse LambdaTest in different search engines", () => {
test("Search LambdaTest Blog on Bing", async ({ page }) => {
await page.goto("https://www.bing.com");
const element = await page.$('[aria-label="Enter your search term"]');
await element.click();
await element.type("LambdaTest Blog");
await element.press("Enter");
const title = await page.title();

console.log("Page title:: ", title);
// Use the expect API for assertions provided by playwright
expect(title).toEqual(expect.stringContaining("LambdaTest Blog"));
});
});

0 comments on commit 4657733

Please sign in to comment.