|
| 1 | +const { chromium } = require('playwright') |
| 2 | +const { expect } = require('@playwright/test'); |
| 3 | + |
| 4 | +(async () => { |
| 5 | + const capabilities = { |
| 6 | + 'browserName': 'Chrome', // Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit` |
| 7 | + 'browserVersion': 'latest', |
| 8 | + 'LT:Options': { |
| 9 | + 'platform': 'Windows 10', |
| 10 | + 'build': 'Playwright SmartUI Build', |
| 11 | + 'name': 'Playwright SmartUI Test', |
| 12 | + 'user': process.env.LT_USERNAME || '<USERNAME>', |
| 13 | + 'accessKey': process.env.LT_ACCESS_KEY || '<ACCESS KEY>', |
| 14 | + 'network': true, |
| 15 | + 'video': true, |
| 16 | + 'console': true, |
| 17 | + 'smartUIProjectName': 'Playwright-SmartUI-Project4', |
| 18 | + // 'smartUIBaseline': false |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + const githubURL = process.env.GITHUB_URL |
| 23 | + if(githubURL){ |
| 24 | + capabilities['LT:Options']['github'] = { |
| 25 | + url : githubURL |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + const browser = await chromium.connect({ |
| 30 | + wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}` |
| 31 | + }) |
| 32 | + |
| 33 | + const page = await browser.newPage() |
| 34 | + |
| 35 | + await page.goto('https://www.lambdatest.com') |
| 36 | + |
| 37 | + // Add the following command in order to take screenshot in SmartUI |
| 38 | + await page.evaluate((_) => {}, |
| 39 | + `lambdatest_action: ${JSON.stringify({ action: 'smartui.takeScreenshot', arguments: { fullPage: true, screenshotName: 'search-lambdatest' } |
| 40 | + })}`) // Add a relevant screenshot name here |
| 41 | + |
| 42 | + const element = await page.$('[id="sb_form_q"]') |
| 43 | + // await element.click() |
| 44 | + await element.type('LambdaTest') |
| 45 | + await page.waitForTimeout(1000) |
| 46 | + await page.keyboard.press('Enter') |
| 47 | + await page.waitForSelector('[class=" b_active"]') |
| 48 | + const title = await page.title() |
| 49 | + |
| 50 | + try { |
| 51 | + expect(title).toEqual('LambdaTest - Search') |
| 52 | + // Mark the test as completed or failed |
| 53 | + await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status: 'passed', remark: 'Title matched' } })}`) |
| 54 | + } catch { |
| 55 | + await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status: 'failed', remark: 'Title not matched' } })}`) |
| 56 | + } |
| 57 | + |
| 58 | + await page.goto("https://www.lambdatest.com") |
| 59 | + |
| 60 | + await page.evaluate((_) => {}, |
| 61 | + `lambdatest_action: ${JSON.stringify({ action: 'smartui.takeScreenshot', arguments: { fullPage: true, screenshotName: 'lambdatest-website' } |
| 62 | + })}`) |
| 63 | + await page.evaluate((_) => {},`lambdatest_action: ${JSON.stringify({ action: 'smartui.takeScreenshot', arguments: { fullPage: false, screenshotName: '<Screenshot Name>'}})}`) |
| 64 | + await page.goto("https://www.lambdatest.com/support/api-doc/") |
| 65 | + await page.evaluate((_) => {}, |
| 66 | + `lambdatest_action: ${JSON.stringify({ action: 'smartui.takeScreenshot', arguments: { fullPage: true, screenshotName: 'api-doc' } |
| 67 | + })}`) |
| 68 | + |
| 69 | + await browser.close() |
| 70 | +})() |
0 commit comments