diff --git a/README.md b/README.md index 577a8f50..1797c445 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,16 @@ -

Smart UI Testing With GitHub

+--- +runme: + id: 01HWAFWEYMX18NF1CSHAZ7M8QB + version: v3 +--- + +

Smart UI Testing With GitHub

+

+ Blog   ⋅   Docs @@ -17,19 +25,20 @@

    +   -*Learn the how to get started with testing GitHub app integration with SmartUI on the LambdaTest platform.* -[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) +*Learn the how to get started with testing GitHub app integration with SmartUI on the LambdaTest platform.* +[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) ## Table of Contents: + * [Pre-requisites](#pre-requisites) * [Getting Started With Github App Integration with SmartUI](#getting-started-with-github-app-integration-with-smartui) - ## Pre-requisites * An account with Github with valid permission to install new applications to your repositories. @@ -38,7 +47,7 @@ ## Getting Started With Github App Integration with SmartUI -### Steps 1: Integrate the your Lambdatest Account with GitHub App. +### Steps 1: Integrate the your Lambdatest Account with GitHub App. You can integrate your LambdaTest account with the GiHub application in the following ways: @@ -46,8 +55,7 @@ You can integrate your LambdaTest account with the GiHub application in the foll ![github-app-landing-92ef6e152a7302cb9ab88f5034b9ec0c](https://user-images.githubusercontent.com/126776938/232715867-f375b4df-1bc9-4e88-8340-44e986be2e9a.png) - -### Step 2: Select your GitHub repository +### Step 2: Select your GitHub repository Go to your GitHub repository where you want to configure your SmartUI project. Check out our GitHub sample [here](https://github.com/LambdaTest/smartui-node-sample). @@ -55,7 +63,7 @@ Go to your GitHub repository where you want to configure your SmartUI project. C Add the `Github` capability to your current test configuration: -```bash +```bash {"id":"01HWAFWEYGEXVSMJCB2CKFCSDN"} const capabilities: { platform: "Windows 10", browserName: "chrome", @@ -76,12 +84,14 @@ Setting up your CI workflow to execute on GitHub. Here is an example setup with Go to `.github/workflows/.yml`. -```bash +```bash {"id":"01HWAFWEYHTNW1BFEH1B42Q0EE"} name: Execute SmartUI Test with Github App Integration runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 + + - name: Create commit status run: | API_HOST=https://api.github.com @@ -100,19 +110,19 @@ Go to `.github/workflows/.yml`. After the setup is completed, you can now execute your test suite with the Continuos Integration (CI) pipeline with any tool of your choice. -**Please Note:** *On running the tests with this repository the user should be able to trigger the `GitHub Action` and execute the `SmartUI` tests for `Selenium`, `Cypress, CDP, and Taiko` frameworks. As this action does not work for `StoryBook`, check our how you can SmartUI test with `StoryBook` [here](https://github.com/LambdaTest/smartui-storybook).* +**Please Note:** *On running the tests with this repository the user should be able to trigger the `GitHub Action` and execute the `SmartUI` tests for `Selenium`, `Cypress, CDP, and Taiko` frameworks. As this action does not work for `StoryBook`, check our how you can SmartUI test with `StoryBook` [here](https://github.com/LambdaTest/smartui-storybook).* ### Step 6: Commit you changes over git on a branch and raise the PR to main branch. ### Step 7: Now you will see the `lambdatest-smartui-app` in the PR. ## Documentation & Resources :books: - + Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) -* [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) +* [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) ## LambdaTest Community :busts_in_silhouette: @@ -120,11 +130,11 @@ The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&u ## What's New At LambdaTest ❓ -To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) - +To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) + ## About LambdaTest -[LambdaTest](https://www.lambdatest.com?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) is an intelligent unified digital experience testing cloud that helps businesses drastically reduce time to market through faster test execution, ensuring quality releases and accelerated digital transformation. The platforms allows you to perform both real time and automation testing across 3000+ environments and real mobile devices, making it a top choice among other cloud testing platforms. Over 10,000+ enterprise customers and 2+ million users across 130+ countries rely on LambdaTest for their testing needs. +[LambdaTest](https://www.lambdatest.com?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) is an intelligent unified digital experience testing cloud that helps businesses drastically reduce time to market through faster test execution, ensuring quality releases and accelerated digital transformation. The platforms allows you to perform both real time and automation testing across 3000+ environments and real mobile devices, making it a top choice among other cloud testing platforms. Over 10,000+ enterprise customers and 2+ million users across 130+ countries rely on LambdaTest for their testing needs. ### Features @@ -140,11 +150,11 @@ To stay updated with the latest features and product add-ons, visit [Changelog]( * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. * Geolocation testing of web and mobile apps across 53+ countries. * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports - -[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) - + +[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) + ## We are here to help you :headphones: * Got a query? we are available 24x7 to help. [Contact Us](mailto:support@lambdatest.com) * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) - + diff --git a/tests/test.js b/tests/test.js index 71e16666..9c77224a 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,109 +1,149 @@ const webdriver = require("selenium-webdriver"); const By = webdriver.By; -var moment = require("moment"); -var waitTime = 2 // 2 seconds +const moment = require("moment"); + +const waitTime = 2; // 2 seconds // username: Username can be found at automation dashboard -const USERNAME = process.env.LT_USERNAME || "username"; +// const USERNAME = process.env.LT_USERNAME || "haiderk"; -// AccessKey: AccessKey can be generated from automation dashboard or profile section -const KEY = process.env.LT_ACCESS_KEY || "accessKey"; +// AccessKey: AccessKey can be generated from automation dashboard or profile section +// const KEY = process.env.LT_ACCESS_KEY || "i7vF5r66IYgsgE9Hp5t6hZqd5PkQX021FgpWRC70mp0ShbFh1R"; // gridUrl: gridUrl can be found at automation dashboard -const GRID_HOST = -process.env.GRID_HOST || "@hub.lambdatest.com/wd/hub"; //connect to lambdatest hub +// const GRID_HOST = process.env.GRID_HOST || "@hub.lambdatest.com/wd/hub"; //connect to lambdatest hub + +// const GRID_URL = process.env.GRID_URL || "GRID_URL"; +const GRID_URL = "https://haiderk:W0AB7YqcubvLeUNPD65N2XANdVq55VZO8KdmLAEO1fbrSFC97B@stage-hub.lambdatestinternal.com/wd/hub"; +// const GRID_URL = "https://smartui-internal:jNbKw8iwoDlqGuBfIBtd5F1Cnr4A0H07ifYNDGpylobjWyA2QX@stage-hub.lambdatestinternal.com/wd/hub"; +// const GRID_URL = "https://haiderk:i7vF5r66IYgsgE9Hp5t6hZqd5PkQX021FgpWRC70mp0ShbFh1R@hub.lambdatest.com/wd/hub"; +// const GRID_URL = "https://ltgdprhak:1JF7nbtNVDTSFQdstywJQxVqaaIEX87sP7q7ghbFjwpcm5Kbgv@stage-hub-eu.lambdatestinternal.com/wd/hub"; +// const GRID_URL = "https://gdpreu:svffEGGVpCulkAYtaqCRVbHIwrZor4aD0BeF89I3xbaPLTpcXz@hub-eu.lambdatest.com/wd/hub"; + -const GRID_URL = process.env.GRID_URL || "GRID_URL"; async function searchTextOnGoogle() { - var keys = process.argv; + const keys = process.argv; console.log(keys); - let parallelCount = keys[2] || 1; - let tunnel = keys[3] || false; - let platform = keys[4] || "Windows 10"; - let browserName = keys[5] || "chrome"; - let version = keys[6] || "latest"; + const parallelCount = keys[2] || 1; + const tunnel = keys[3] || false; + const platform = keys[4] || "Windows 10"; + // const platform = keys[4] || "bigsur"; + const browserName = keys[5] || "chrome"; + const version = keys[6] || "latest"; // Setup Input capabilities - let capabilities = { + const capabilities = { platform: platform, browserName: browserName, version: version, queueTimeout: 300, visual: true, - user: USERNAME, - accessKey: KEY, + user: process.env.LT_USERNAME, + accessKey: process.env.LT_ACCESS_KEY, name: "test session", // name of the test - build: platform + browserName + version, // name of the build - "smartUI.project": "github-integration-demo", + build: `${platform}${browserName}${version}`, // name of the build + "smartUI.smartIgnore":true, + "smartUI.project": "[Git_Branching#ComparisonStrategy]", + + github: { url: process.env.GITHUB_URL, }, - }; + }; if (tunnel === "true") { capabilities.tunnel = true; } - var gridUrl = GRID_URL; - console.log("gridUrl : ", gridUrl); - console.log("GITHUB_REPOSITORY : ", process.env.GITHUB_REPOSITORY); + console.log("gridUrl: ", GRID_URL); + console.log("GITHUB_REPOSITORY: ", process.env.GITHUB_REPOSITORY); console.log(capabilities); - console.log("Running " + parallelCount + " parallel tests "); - let i = 1; - for (i = 1; i <= parallelCount; i++) { - startTest(gridUrl, capabilities, "Test " + i); + console.log(`Running ${parallelCount} parallel tests`); + + for (let i = 1; i <= parallelCount; i++) { + startTest(GRID_URL, capabilities, `Test ${i}`); } } - -searchTextOnGoogle(); - async function startTest(gridUrl, capabilities, name) { - const caps = capabilities; - var start_date = moment(); - - const driver = await new webdriver.Builder() - .usingServer(gridUrl) - .withCapabilities(caps) - .build(); - - var end_date = moment(); - var duration = moment.duration(end_date.diff(start_date)); - console.log(caps.name, " : Setup Time :", duration.asSeconds()); - - // navigate to a url - let url = "https://www.lambdatest.com"; - url = "https://www.lambdatest.com/enterprise"; - console.log(url); - await driver - .get(url) - .then(function () { - const session = driver.getSession(); - - // For Smartui TakeScreenshot - setTimeout(function () { - console.log("taking screenshot ...") - driver.executeScript(`smartui.takeScreenshot,{"screenshotName":"sample-screenshot"}`).then(out => { - console.log("RESPONSE :", out) - return + const caps = { ...capabilities, name }; + + try { + const start_date = moment(); + + const driver = await new webdriver.Builder() + .usingServer(gridUrl) + .withCapabilities(caps) + .build(); + + const end_date = moment(); + const duration = moment.duration(end_date.diff(start_date)); + console.log(`${caps.name} : Setup Time: ${duration.asSeconds()} seconds`); + + // const url = "https://www.lambdatest.com/"; + // const url = "https://www.flipkart.com/"; + const url = "https://www.samsung.com/"; + console.log(url); + await driver.get(url); + + console.log("taking screenshot ..."); + setTimeout(() => { + driver.executeScript(`smartui.takeScreenshot=TEST`).then(() => { + + driver.executeScript(`smartui.fetchScreenshotStatus=TEST`).then(out => { + console.log("response:", out); + }).catch(err => { + console.error("Error fetching screenshot status:", err); }); - }, waitTime * 1000); - - - driver.getTitle().then(function (title) { - setTimeout(function () { - driver.executeScript("lambda-status=passed"); + }).catch(err => { + console.error("Error taking screenshot:", err); + }); + }, waitTime * 1000); + + driver.getTitle().then(function (title) { + console.log("Title:", title); + setTimeout(function () { + driver.executeScript("lambda-status=passed").then(() => { driver.quit(); - }, 15000); + }).catch(err => { + console.error("Error setting lambda status to passed:", err); + driver.quit(); + }); + }, 15000); + }).catch(err => { + console.error("Error getting title:", err); + driver.executeScript("lambda-status=failed").then(() => { + driver.quit(); + }).catch(scriptError => { + console.error("Failed to set lambda status:", scriptError); + driver.quit(); }); - }) - .catch(function (err) { - error = JSON.stringify(err); - console.log(error); - console.log("test failed with reason " + err); - driver.executeScript("lambda-status=failed"); - driver.quit(); }); + } catch (err) { + console.error("Test failed with reason:", err); + try { + await driver.executeScript("lambda-status=failed"); + } catch (scriptError) { + console.error("Failed to set lambda status:", scriptError); + } + await driver.quit(); + } } +searchTextOnGoogle(); + + + + + + + + + + + + + + +