diff --git a/README.md b/README.md
index 26bc724..eb71fa6 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-
Smart UI Testing With Selenium Node.JS
+Smart UI Testing With Selenium Node.JS
@@ -22,388 +22,144 @@
*Learn the how to get started with Smart UI testing with Selenium Node.JS 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)
-* [Running Your First Selenium Node JS Test](#running-your-first-selenium-node-js-test)
-* [Examples For Different Use Cases](#examples-for-different-use-cases)
-* [Configuring The Test Environment](#configuring-the-test-environment)
-* [Setting Up GitHub App Integration With SmartUI](#setting-up-github-app-integration-with-smartui)
-
-## Pre-requisites
-
-1. To get started, you would require the Node version >=14.
- ```
- node --version
- ```
-
-2. You can switch the Node version by running the below command:
- ```
- nvm install 12.0.0
- node --version
- ```
-
-3. Create a `New Project` with the SmartUI Web Application.
-
-## Configuring The Test Environment
-
-Before executing your NodeJs test, you need to configure the `config.json` file. You can find the `config.json` file [here](https://github.com/keys-github/smartui-node-sample/blob/main/config.json). To add capabilities, visit our [capabilities generator](https://www.lambdatest.com/capabilities-generator/).
-## Running Your First Selenium Node JS Test
+[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample)
-1. In order to run your Smart UI tests with Selenium Python, you will need to set your LambdaTest username and access key in the environment variables. Click the **Access Key** button at the top-right of the Automation Dashboard to access it.
-![Screenshot 2023-04-18 132921](https://user-images.githubusercontent.com/126776938/232711334-676f1895-d223-4ee2-9bff-d82837715520.png)
+## Getting Started with Smart UI Testing
-**Windows**
+Smart UI testing is an integral part of ensuring visual consistency across different environments for your web application. Using the LambdaTest platform with Selenium and Node.js, this process becomes intuitive and efficient.
-```js
-set LT_USERNAME="YOUR_USERNAME"
-set LT_ACCESS_KEY="YOUR ACCESS KEY"
-```
+### Pre-Requisites:
-**macOS/Linux**
+To execute the tests, your need to login to your lambdatest account and from the `Sidebar` you can find the `Username` and `Access Key` information which needs to be added to your environment variables:
-```js
-export LT_USERNAME="YOUR_USERNAME"
-export LT_ACCESS_KEY="YOUR ACCESS KEY"
-```
-
-2. To create a `New Project` using the SmartUI Web Application, click the **New Project** button in the top-right corner of your dashboard.
-
-![Screenshot 2023-04-18 133652](https://user-images.githubusercontent.com/126776938/232756654-ad1f5594-06da-4a42-ac7d-709cefdff5b1.png)
-
-3. Fill in the specifications such as **Platform**, **Project Name**, **Approvers**, and **Tags** as per your requirement and click **Create Project**.
-
-![Screenshot 2023-04-18 134121](https://user-images.githubusercontent.com/126776938/232714262-56ae0be3-3ba3-4ba3-8e82-2f063657fcaf.png)
-
-3. Clone the `smartui-node-sample` Repo.
- ```
- git clone https://github.com/LambdaTest/smartui-node-sample
- ```
-
-4. Install the Dependencies.
- ```
- npm i
- ```
-
-
-## Examples For Different Use Cases
-
-We have many different examples revolving around different use cases. They are as follows:
-
-### General Capability Change Test Cases
-
- * `index.js` - This Test is an example of all the **advanced funtionalities** possible with Smart UI.
-
- ```
- npm start
- ```
- * `general.js` - This Test is an example of all the **general test**
-
- ```
- npm start general
- ```
-
- * `errorSetting.js` - This Test is an example of how **error settings** can be modified.
-
- ```
- npm start error
- ```
-
- * `transparency.js` - This Test is to show how to **alter the opacity** of the comparison screenshot.
-
- ```
- npm start transparency
- ```
-
- * `BoundingBoxes.js` - This Test shows an example of comparing only a **certain area** in the screenshot.
-
- ```
- npm start boundingBoxes
- ```
-
- * `ignoredBoxes.js` - This test is for **excluding certain areas** in the screenshot for comparison.
-
- ```
- npm start ignoredBoxes
- ```
-
- * `ignoreAreasColoredWith.js` - This test is for **removing the colored content** from the comparison.
-
- ```
- npm start ignoreAreasColoredWith
- ```
-
-### Execute Tests on Multiple URLs
-
-To get started, first configure the `url.json` with the help of the code given below.
+For MacOS/Linux:
```bash
-[
- {
- "screenshotName": "Lambdatest Landing Page",
- "url": "https://lambdatest.com"
- },
- {
- "screenshotName": "Amazon Home Page",
- "url": "https://amazon.com"
- }
-]
+export LT_USERNAME=""
+export LT_ACCESS_KEY=""
```
-Run the following command to execute tests on multiple URLs.
+For Windows CMD
```bash
-npm run multiple
+set LT_USERNAME=""
+set LT_ACCESS_KEY=""
```
-Given below is the multiple URL tests sample.
+For Windows PowerShell
```bash
-const webdriver = require("selenium-webdriver");
-const By = webdriver.By;
-const moment = require("moment");
-const automationConfig = require("./config.json");
-const smartUITests = require("./urls.json");
-
-// username: Username can be found at automation dashboard
-const USERNAME = process.env.LT_USERNAME || "";
-
-// AccessKey: AccessKey can be generated from automation dashboard or profile section
-const KEY = process.env.LT_ACCESS_KEY || "";
-
-//connect to Lambdatest hub
-const GRID_HOST = process.env.GRID_HOST || "@hub.lambdatest.com/wd/hub";
-
-const gridUrl = "https://" + USERNAME + ":" + KEY + GRID_HOST;
-
-// Selenium WebDriver Function
-
-async function runSmartUIonLambdatest() {
- // Lambdatest Cloud Selenium Grid Connection
-
- // Printing the Lambdatest Cloud Information for the test
-
- console.log(
- "Please visit https://smartui.lambdatest.com to see your SmartUI - Visual Regression Tests"
- );
-
- try {
- automationConfig.forEach(async (...config) => {
- const driver = await new webdriver.Builder()
- .usingServer(gridUrl)
- .withCapabilities(...config)
- .build();
- try {
- smartUITests.forEach((smartUITest) => {
- let smartUI_ScreenshotName = smartUITest.screenshotName;
- let smartUI_url = smartUITest.url;
- smartUISeleniumTest(driver, smartUI_url, smartUI_ScreenshotName);
- });
- } catch (err) {
- console.log(err);
- }
- // Closing the Browser Session
- await driver.executeScript("lambda-status=failed");
- await driver.quit();
- });
- } catch (err) {
- console.log(JSON.stringify(err));
- await driver.executeScript("lambda-status=failed");
- }
-}
-
-async function smartUISeleniumTest(driver, url, screenshotName) {
- await driver
- .get(url)
- .then(() => {
- // For Smartui TakeScreenshot
- console.log(
- `Capturing the Screenshot Name: ${screenshotName} | URL: ${url}`
- );
- driver.manage().setTimeouts({ implicit: 10000 });
- let images = driver.findElements(webdriver.By.css("img.lazyload"));
- for (let i = 0; i < images.length; i++) {
- driver.executeScript("arguments[0].scrollIntoView();", images[i]);
- driver.wait(until.elementIsVisible(images[i]), 10000); // wait up to 10 seconds for image to appear
-
- let src = images[i].getAttribute("src");
- console.log(`Captured image source: ${src}`);
- }
- driver
- .executeScript(`smartui.takeFullPageScreenshot=${screenshotName}`)
- .then((result) => {
- console.log("Result :", result);
- });
- })
- .catch((err) => {
- console.log(err);
- });
-}
-
-// Executing the tests in parallel of multiple urls
-runSmartUIonLambdatest();
+$env:LT_USERNAME=""
+$env:LT_ACCESS_KEY=""
```
+Now, navigate to `SmartUI` section from the sidebar and create a new project with the `project type` as the following:
-
-### Execute Tests on Multiple Resolutions
+- **Web** - For running the tests using `hooks` within the `selenium/cypress/playwright` functional tests.
+- **CLI** - For running your `SDK` execution for DOM capture and render on multiple browsers and viewports for comparison.
-If you want to execute Visual Regression tests on multiple resolutions, you need to add the capability `resolution` in capabilities option.
-```
- let capabilities = {
- ...
- resolution = "1920x1080";
- ...
- }
-```
-Few common resolutions are:
-- 1024x768
-- 1280x800
-- 1600x1200
-- 1920x1080
-- 2560x1440
-
-Here is the code for all the commonly used resolutions:
-
-#### Run Test on `1024x768` resolution
-```
-$ node custom-resolutions.js 1024x768
-```
+### Features
-#### Run Test on `1280x800` resolution
-```
-$ node custom-resolutions.js 1280x800
+#### LT-Hooks Integration
+- **Location:** See the `hooks` folder, where you can see all the `examples` scripts to setup your suite or run the demo.
+- **Purpose:** Enhance visual regression capabilities in your LambdaTest web automation tests.
+- **Benefits:** Increase efficiency with advanced testing features with visual regression testing.
+- **Documentation:** [LambdaTest Selenium Visual Regression Documentation](https://www.lambdatest.com/support/docs/selenium-visual-regression/).
+##### **Steps:**
+- Install the dependencies.
+```bash
+cd hooks
+npm i
+```
+- Configure the capabilities (SmartUI Project Name and other SmartUI options) in .examples\test.js
+```javascript
+let capabilities = {
+ platform: "Windows 10", // Configure your OS for Selenium test
+ browserName: "chrome", // Configure your Browser for Selenium test
+ version: "latest", // Configure your Browser Version for Selenium test
+ visual: true, // Configure your Capture screenshot for Selenium test
+ name: "test session", // name of the test for Selenium
+ build: "Automation Build", // name of the build for Selenium
+ "smartUI.project": "", // Replace the name of project with the new project name
+ "smartUI.build": "", // Replace the name of Build with the new Build name
+ "smartUI.baseline": false, // Enable if you want to update to a new baseline build
+
+};
+```
+- Add the Screenshot hook in .examples\test.js
+```js
+let config = {
+ screenshotName: ''
+};
+await driver.executeScript("smartui.takeScreenshot", config);
```
-
-#### Run Test on `1600x1200` resolution
+- Run the script
```
-$ node custom-resolutions.js 1600x1200
+node .examples\test.js
```
-#### Run Test on `1920x1080` resolution
-```
-$ node custom-resolutions.js 1920x1080
-```
-
+#### SmartUI SDK Utilization
+- **Location:** Check out the `sdk` folder, and setup the environment for running the tests.
+- **Purpose:** Use the SmartUI SDK for comprehensive visual testing in both local and remote automation tests environments.
+- **Advantages:** Ensure consistent DOM capturing and rendering across various browsers and resolutions.
+- **More Information:** [SmartUI Selenium JavaScript SDK Documentation](https://www.lambdatest.com/support/docs/smartui-selenium-js-sdk/).
-#### Run Test on `2560x1440` resolution
-```
-$ node custom-resolutions.js 2560x1440
+##### Steps:
+- Install the dependencies
+```bash
+cd sdk
+npm i @lambdatest/smartui-cli @lambdatest/selenium-driver selenium-webdriver
```
+- Configure your Project Token
-## Setting Up Github App Integration with SmartUI
-
-### Steps 1: Integrate the your Lambdatest Account with GitHub App.
-
-You can integrate your LambdaTest account with the GiHub application in the following ways:
+Setup your project token show in the **SmartUI** app after, creating your project.
-- Using OAuth
-
-![github-app-landing-92ef6e152a7302cb9ab88f5034b9ec0c](https://user-images.githubusercontent.com/126776938/232715867-f375b4df-1bc9-4e88-8340-44e986be2e9a.png)
-
-
-### 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).
-
-### Step 3: Configure your test suite
-
-Add the `Github` capability to your current test configuration:
+
+
```bash
-const capabilities: {
- platform: "Windows 10",
- browserName: "chrome",
- version: "latest",
- "smartUI.project": "Smart UI sample test",
- github: {
- "url": "https://api.github.com/repos/OWNER/REPO/statuses/commitId", // Mandatory
- "owner": "{OWNER}", //Optional
- "repo": "{REPO}", //Optional
- "commit": "{commitId}" //Optional
- }
-}
+export PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
```
-### Step 4: Setting up your CI configuration
-
-Setting up your CI workflow to execute on GitHub. Here is an example setup with `GitHub Actions`:
-
-Go to `.github/workflows/.yml`.
+
+
```bash
- 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
- # Check out the PR branch
- git checkout $GITHUB_HEAD_REF
- # Get the commit ID of the last commit
- COMMIT_ID=$(git rev-parse HEAD)
- echo "Last commit ID of PR: $COMMIT_ID"
- GITHUB_URL=$API_HOST/repos/$GITHUB_REPOSITORY/statuses/$COMMIT_ID
- echo "GITHUB_URL: $GITHUB_URL"
- echo "GITHUB_URL=$GITHUB_URL" >> $GITHUB_ENV
+set PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
```
-### Step5: Execute your test suite with CI
-
-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 and CDP` frameworks excluding `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 Community :busts_in_silhouette:
-
-The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎
-
-## What's New At LambdaTest ❓
-
-To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
-
-## About LambdaTest
+```bash
+$Env:PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
+```
+
+
-[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.
+- Add the SmartUI function to take screenshot to `sdkLocal.js` file
+```js
+import { Builder, By, Key, until } from 'selenium-webdriver';
+import { smartuiSnapshot } from '@lambdatest/selenium-driver';
-### Features
+(async function example() {
+ let driver = await new Builder()
+ .forBrowser('chrome')
+ .build();
-* Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
-* Real-time cross browser testing on 3000+ environments.
-* Test on Real device cloud
-* Blazing fast test automation with HyperExecute
-* Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
-* Smart Visual Regression Testing on cloud
-* 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
-* Automated Screenshot testing across multiple browsers in a single click.
-* Local testing of web and mobile apps.
-* 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)
-
-## We are here to help you :headphones:
+ try {
+ await driver.get(''); //enter your desired URL here
+ await smartuiSnapshot(driver, '');
+ } finally {
+ await driver.quit();
+ }
+})();
+```
+- Execute the Tests on SmartUI Cloud
-* 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)
+```bash
+npx smartui exec node .js
+```
\ No newline at end of file
diff --git a/.gitignore b/hooks/.gitignore
similarity index 100%
rename from .gitignore
rename to hooks/.gitignore
diff --git a/hooks/README.md b/hooks/README.md
new file mode 100644
index 0000000..26bc724
--- /dev/null
+++ b/hooks/README.md
@@ -0,0 +1,409 @@
+ Smart UI Testing With Selenium Node.JS
+
+
+
+
+
+ Blog
+ ⋅
+ Docs
+ ⋅
+ Learning Hub
+ ⋅
+ Newsletter
+ ⋅
+ Certifications
+ ⋅
+ YouTube
+
+
+
+
+
+*Learn the how to get started with Smart UI testing with Selenium Node.JS 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)
+* [Running Your First Selenium Node JS Test](#running-your-first-selenium-node-js-test)
+* [Examples For Different Use Cases](#examples-for-different-use-cases)
+* [Configuring The Test Environment](#configuring-the-test-environment)
+* [Setting Up GitHub App Integration With SmartUI](#setting-up-github-app-integration-with-smartui)
+
+## Pre-requisites
+
+1. To get started, you would require the Node version >=14.
+ ```
+ node --version
+ ```
+
+2. You can switch the Node version by running the below command:
+ ```
+ nvm install 12.0.0
+ node --version
+ ```
+
+3. Create a `New Project` with the SmartUI Web Application.
+
+## Configuring The Test Environment
+
+Before executing your NodeJs test, you need to configure the `config.json` file. You can find the `config.json` file [here](https://github.com/keys-github/smartui-node-sample/blob/main/config.json). To add capabilities, visit our [capabilities generator](https://www.lambdatest.com/capabilities-generator/).
+
+## Running Your First Selenium Node JS Test
+
+1. In order to run your Smart UI tests with Selenium Python, you will need to set your LambdaTest username and access key in the environment variables. Click the **Access Key** button at the top-right of the Automation Dashboard to access it.
+
+![Screenshot 2023-04-18 132921](https://user-images.githubusercontent.com/126776938/232711334-676f1895-d223-4ee2-9bff-d82837715520.png)
+
+**Windows**
+
+```js
+set LT_USERNAME="YOUR_USERNAME"
+set LT_ACCESS_KEY="YOUR ACCESS KEY"
+```
+
+**macOS/Linux**
+
+```js
+export LT_USERNAME="YOUR_USERNAME"
+export LT_ACCESS_KEY="YOUR ACCESS KEY"
+```
+
+2. To create a `New Project` using the SmartUI Web Application, click the **New Project** button in the top-right corner of your dashboard.
+
+![Screenshot 2023-04-18 133652](https://user-images.githubusercontent.com/126776938/232756654-ad1f5594-06da-4a42-ac7d-709cefdff5b1.png)
+
+3. Fill in the specifications such as **Platform**, **Project Name**, **Approvers**, and **Tags** as per your requirement and click **Create Project**.
+
+![Screenshot 2023-04-18 134121](https://user-images.githubusercontent.com/126776938/232714262-56ae0be3-3ba3-4ba3-8e82-2f063657fcaf.png)
+
+3. Clone the `smartui-node-sample` Repo.
+ ```
+ git clone https://github.com/LambdaTest/smartui-node-sample
+ ```
+
+4. Install the Dependencies.
+ ```
+ npm i
+ ```
+
+
+## Examples For Different Use Cases
+
+We have many different examples revolving around different use cases. They are as follows:
+
+### General Capability Change Test Cases
+
+ * `index.js` - This Test is an example of all the **advanced funtionalities** possible with Smart UI.
+
+ ```
+ npm start
+ ```
+ * `general.js` - This Test is an example of all the **general test**
+
+ ```
+ npm start general
+ ```
+
+ * `errorSetting.js` - This Test is an example of how **error settings** can be modified.
+
+ ```
+ npm start error
+ ```
+
+ * `transparency.js` - This Test is to show how to **alter the opacity** of the comparison screenshot.
+
+ ```
+ npm start transparency
+ ```
+
+ * `BoundingBoxes.js` - This Test shows an example of comparing only a **certain area** in the screenshot.
+
+ ```
+ npm start boundingBoxes
+ ```
+
+ * `ignoredBoxes.js` - This test is for **excluding certain areas** in the screenshot for comparison.
+
+ ```
+ npm start ignoredBoxes
+ ```
+
+ * `ignoreAreasColoredWith.js` - This test is for **removing the colored content** from the comparison.
+
+ ```
+ npm start ignoreAreasColoredWith
+ ```
+
+### Execute Tests on Multiple URLs
+
+To get started, first configure the `url.json` with the help of the code given below.
+
+```bash
+[
+ {
+ "screenshotName": "Lambdatest Landing Page",
+ "url": "https://lambdatest.com"
+ },
+ {
+ "screenshotName": "Amazon Home Page",
+ "url": "https://amazon.com"
+ }
+]
+```
+
+Run the following command to execute tests on multiple URLs.
+
+```bash
+npm run multiple
+```
+
+Given below is the multiple URL tests sample.
+
+```bash
+const webdriver = require("selenium-webdriver");
+const By = webdriver.By;
+const moment = require("moment");
+const automationConfig = require("./config.json");
+const smartUITests = require("./urls.json");
+
+// username: Username can be found at automation dashboard
+const USERNAME = process.env.LT_USERNAME || "";
+
+// AccessKey: AccessKey can be generated from automation dashboard or profile section
+const KEY = process.env.LT_ACCESS_KEY || "";
+
+//connect to Lambdatest hub
+const GRID_HOST = process.env.GRID_HOST || "@hub.lambdatest.com/wd/hub";
+
+const gridUrl = "https://" + USERNAME + ":" + KEY + GRID_HOST;
+
+// Selenium WebDriver Function
+
+async function runSmartUIonLambdatest() {
+ // Lambdatest Cloud Selenium Grid Connection
+
+ // Printing the Lambdatest Cloud Information for the test
+
+ console.log(
+ "Please visit https://smartui.lambdatest.com to see your SmartUI - Visual Regression Tests"
+ );
+
+ try {
+ automationConfig.forEach(async (...config) => {
+ const driver = await new webdriver.Builder()
+ .usingServer(gridUrl)
+ .withCapabilities(...config)
+ .build();
+ try {
+ smartUITests.forEach((smartUITest) => {
+ let smartUI_ScreenshotName = smartUITest.screenshotName;
+ let smartUI_url = smartUITest.url;
+ smartUISeleniumTest(driver, smartUI_url, smartUI_ScreenshotName);
+ });
+ } catch (err) {
+ console.log(err);
+ }
+ // Closing the Browser Session
+ await driver.executeScript("lambda-status=failed");
+ await driver.quit();
+ });
+ } catch (err) {
+ console.log(JSON.stringify(err));
+ await driver.executeScript("lambda-status=failed");
+ }
+}
+
+async function smartUISeleniumTest(driver, url, screenshotName) {
+ await driver
+ .get(url)
+ .then(() => {
+ // For Smartui TakeScreenshot
+ console.log(
+ `Capturing the Screenshot Name: ${screenshotName} | URL: ${url}`
+ );
+ driver.manage().setTimeouts({ implicit: 10000 });
+ let images = driver.findElements(webdriver.By.css("img.lazyload"));
+ for (let i = 0; i < images.length; i++) {
+ driver.executeScript("arguments[0].scrollIntoView();", images[i]);
+ driver.wait(until.elementIsVisible(images[i]), 10000); // wait up to 10 seconds for image to appear
+
+ let src = images[i].getAttribute("src");
+ console.log(`Captured image source: ${src}`);
+ }
+ driver
+ .executeScript(`smartui.takeFullPageScreenshot=${screenshotName}`)
+ .then((result) => {
+ console.log("Result :", result);
+ });
+ })
+ .catch((err) => {
+ console.log(err);
+ });
+}
+
+// Executing the tests in parallel of multiple urls
+runSmartUIonLambdatest();
+```
+
+
+
+### Execute Tests on Multiple Resolutions
+
+If you want to execute Visual Regression tests on multiple resolutions, you need to add the capability `resolution` in capabilities option.
+```
+ let capabilities = {
+ ...
+ resolution = "1920x1080";
+ ...
+ }
+```
+Few common resolutions are:
+- 1024x768
+- 1280x800
+- 1600x1200
+- 1920x1080
+- 2560x1440
+
+Here is the code for all the commonly used resolutions:
+
+#### Run Test on `1024x768` resolution
+```
+$ node custom-resolutions.js 1024x768
+```
+
+#### Run Test on `1280x800` resolution
+```
+$ node custom-resolutions.js 1280x800
+```
+
+#### Run Test on `1600x1200` resolution
+```
+$ node custom-resolutions.js 1600x1200
+```
+
+
+#### Run Test on `1920x1080` resolution
+```
+$ node custom-resolutions.js 1920x1080
+```
+
+
+#### Run Test on `2560x1440` resolution
+```
+$ node custom-resolutions.js 2560x1440
+```
+
+## Setting Up Github App Integration with SmartUI
+
+### Steps 1: Integrate the your Lambdatest Account with GitHub App.
+
+You can integrate your LambdaTest account with the GiHub application in the following ways:
+
+- Using OAuth
+
+![github-app-landing-92ef6e152a7302cb9ab88f5034b9ec0c](https://user-images.githubusercontent.com/126776938/232715867-f375b4df-1bc9-4e88-8340-44e986be2e9a.png)
+
+
+### 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).
+
+### Step 3: Configure your test suite
+
+Add the `Github` capability to your current test configuration:
+
+```bash
+const capabilities: {
+ platform: "Windows 10",
+ browserName: "chrome",
+ version: "latest",
+ "smartUI.project": "Smart UI sample test",
+ github: {
+ "url": "https://api.github.com/repos/OWNER/REPO/statuses/commitId", // Mandatory
+ "owner": "{OWNER}", //Optional
+ "repo": "{REPO}", //Optional
+ "commit": "{commitId}" //Optional
+ }
+}
+```
+
+### Step 4: Setting up your CI configuration
+
+Setting up your CI workflow to execute on GitHub. Here is an example setup with `GitHub Actions`:
+
+Go to `.github/workflows/.yml`.
+
+```bash
+ 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
+ # Check out the PR branch
+ git checkout $GITHUB_HEAD_REF
+ # Get the commit ID of the last commit
+ COMMIT_ID=$(git rev-parse HEAD)
+ echo "Last commit ID of PR: $COMMIT_ID"
+ GITHUB_URL=$API_HOST/repos/$GITHUB_REPOSITORY/statuses/$COMMIT_ID
+ echo "GITHUB_URL: $GITHUB_URL"
+ echo "GITHUB_URL=$GITHUB_URL" >> $GITHUB_ENV
+```
+
+### Step5: Execute your test suite with CI
+
+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 and CDP` frameworks excluding `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 Community :busts_in_silhouette:
+
+The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎
+
+## What's New At LambdaTest ❓
+
+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.
+
+### Features
+
+* Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
+* Real-time cross browser testing on 3000+ environments.
+* Test on Real device cloud
+* Blazing fast test automation with HyperExecute
+* Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
+* Smart Visual Regression Testing on cloud
+* 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
+* Automated Screenshot testing across multiple browsers in a single click.
+* Local testing of web and mobile apps.
+* 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)
+
+## 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/config.json b/hooks/config.json
similarity index 100%
rename from config.json
rename to hooks/config.json
diff --git a/tests/generalCases/boundingBoxes.js b/hooks/examples/boundingBoxes.js
similarity index 100%
rename from tests/generalCases/boundingBoxes.js
rename to hooks/examples/boundingBoxes.js
diff --git a/tests/generalCases/custom-resolutions.js b/hooks/examples/custom-resolutions.js
similarity index 100%
rename from tests/generalCases/custom-resolutions.js
rename to hooks/examples/custom-resolutions.js
diff --git a/tests/generalCases/errorSetting.js b/hooks/examples/errorSetting.js
similarity index 100%
rename from tests/generalCases/errorSetting.js
rename to hooks/examples/errorSetting.js
diff --git a/tests/generalCases/general.js b/hooks/examples/general.js
similarity index 100%
rename from tests/generalCases/general.js
rename to hooks/examples/general.js
diff --git a/tests/generalCases/helper.js b/hooks/examples/helper.js
similarity index 100%
rename from tests/generalCases/helper.js
rename to hooks/examples/helper.js
diff --git a/tests/generalCases/ignoreAreasColoredWith.js b/hooks/examples/ignoreAreasColoredWith.js
similarity index 100%
rename from tests/generalCases/ignoreAreasColoredWith.js
rename to hooks/examples/ignoreAreasColoredWith.js
diff --git a/tests/generalCases/ignoredBoxes.js b/hooks/examples/ignoredBoxes.js
similarity index 100%
rename from tests/generalCases/ignoredBoxes.js
rename to hooks/examples/ignoredBoxes.js
diff --git a/tests/generalCases/index.js b/hooks/examples/index.js
similarity index 100%
rename from tests/generalCases/index.js
rename to hooks/examples/index.js
diff --git a/tests/generalCases/multiple-urls/config.json b/hooks/examples/multiple-urls/config.json
similarity index 100%
rename from tests/generalCases/multiple-urls/config.json
rename to hooks/examples/multiple-urls/config.json
diff --git a/tests/generalCases/multiple-urls/multiple-url-tests-sample.js b/hooks/examples/multiple-urls/multiple-url-tests-sample.js
similarity index 100%
rename from tests/generalCases/multiple-urls/multiple-url-tests-sample.js
rename to hooks/examples/multiple-urls/multiple-url-tests-sample.js
diff --git a/tests/generalCases/multiple-urls/parallel-config-sample.js b/hooks/examples/multiple-urls/parallel-config-sample.js
similarity index 100%
rename from tests/generalCases/multiple-urls/parallel-config-sample.js
rename to hooks/examples/multiple-urls/parallel-config-sample.js
diff --git a/tests/generalCases/multiple-urls/parallel-config.json b/hooks/examples/multiple-urls/parallel-config.json
similarity index 100%
rename from tests/generalCases/multiple-urls/parallel-config.json
rename to hooks/examples/multiple-urls/parallel-config.json
diff --git a/tests/generalCases/multiple-urls/urls.json b/hooks/examples/multiple-urls/urls.json
similarity index 100%
rename from tests/generalCases/multiple-urls/urls.json
rename to hooks/examples/multiple-urls/urls.json
diff --git a/tests/generalCases/mutiple-url-tests.js b/hooks/examples/mutiple-url-tests.js
similarity index 100%
rename from tests/generalCases/mutiple-url-tests.js
rename to hooks/examples/mutiple-url-tests.js
diff --git a/tests/generalCases/test.js b/hooks/examples/test.js
similarity index 100%
rename from tests/generalCases/test.js
rename to hooks/examples/test.js
diff --git a/tests/generalCases/transparency.js b/hooks/examples/transparency.js
similarity index 100%
rename from tests/generalCases/transparency.js
rename to hooks/examples/transparency.js
diff --git a/lazyLoadingImages.js b/hooks/lazyLoadingImages.js
similarity index 100%
rename from lazyLoadingImages.js
rename to hooks/lazyLoadingImages.js
diff --git a/package-lock.json b/hooks/package-lock.json
similarity index 100%
rename from package-lock.json
rename to hooks/package-lock.json
diff --git a/package.json b/hooks/package.json
similarity index 62%
rename from package.json
rename to hooks/package.json
index cca5bf3..15d8554 100644
--- a/package.json
+++ b/hooks/package.json
@@ -2,18 +2,19 @@
"dependencies": {
"minimatch": "^3.0.5",
"moment": "^2.29.4",
+ "playwright": "^1.35.1",
"scroll-to-bottomjs": "^1.1.0",
- "selenium-webdriver": "^3.6.0"
+ "selenium-webdriver": "^4.16.0"
},
"name": "nodejs-selenium-sample",
"description": "![LambdaTest Logo](https://www.lambdatest.com/images/logo.svg)",
"version": "1.0.0",
"main": "index.js",
"scripts": {
- "start": "node ./tests/generalCases/index.js",
- "test": "node ./tests/generalCases/test.js",
- "multiple": "node ./tests/generalCases/multiple-urls/multiple-url-tests-sample.js",
- "multiple-config": "node ./tests/generalCases/multiple-urls/parallel-config-sample.js"
+ "start": "node ./examples/index.js",
+ "test": "node ./examples/test.js",
+ "multiple": "node ./examples/multiple-urls/multiple-url-tests-sample.js",
+ "multiple-config": "node ./examples/multiple-urls/parallel-config-sample.js"
},
"repository": {
"type": "git",
@@ -25,5 +26,8 @@
"bugs": {
"url": "https://github.com/LambdaTest/nodejs-selenium-sample/issues"
},
- "homepage": "https://github.com/LambdaTest/nodejs-selenium-sample#readme"
+ "homepage": "https://github.com/LambdaTest/nodejs-selenium-sample#readme",
+ "devDependencies": {
+ "@playwright/test": "^1.35.1"
+ }
}
diff --git a/util/helpLogger.js b/hooks/util/helpLogger.js
similarity index 100%
rename from util/helpLogger.js
rename to hooks/util/helpLogger.js
diff --git a/util/validCommands.js b/hooks/util/validCommands.js
similarity index 100%
rename from util/validCommands.js
rename to hooks/util/validCommands.js
diff --git a/sdk/README.md b/sdk/README.md
new file mode 100644
index 0000000..88f239e
--- /dev/null
+++ b/sdk/README.md
@@ -0,0 +1,174 @@
+# Integrating SmartUI SDK with Selenium(JS) tests
+
+Welcome to the world of simplified visual testing with the SmartUI SDK.
+
+Integrating seamlessly into your existing Selenium testing suite, SmartUI SDK revolutionizes the way you approach visual regression testing. Our robust solution empowers you to effortlessly capture, compare, and analyze screenshots across a multitude of browsers and resolutions, ensuring comprehensive coverage and accuracy in your visual testing endeavors.
+
+## Pre-requisites for running tests through SmartUI SDK
+
+- Basic understanding of Command Line Interface and Selenium is required.
+- Login to [LambdaTest SmartUI](https://smartui.lambdatest.com/) with your credentials.
+
+The following steps will guide you in running your first Visual Regression test on LambdaTest platform using SmartUI Selenium SDK integration.
+
+## Create a SmartUI Project
+
+The first step is to create a project with the application in which we will combine all your builds run on the project. To create a SmartUI Project, follow these steps:
+
+1. Go to [Projects page](https://smartui.lambdatest.com/)
+2. Click on the `new project` button
+3. Select the platform as CLI or Web for executing your `SDK` tests.
+4. Add name of the project, approvers for the changes found, tags for any filter or easy navigation.
+5. Click on the **Submit**.
+
+## Steps to run your first test
+
+Once you have created a SmartUI Project, you can generate screenshots by running automation scripts. Follow the below steps to successfully generate screenshots
+
+### **Step 1:** Create/Update your test
+
+You can clone the sample repository to run `LambdaTest` automation tests with `SmartUI` and use the `sdk.js` file present in the `sdk` folder.
+
+```bash
+git clone https://github.com/LambdaTest/smartui-node-sample
+```
+### **Step 2**: Install the Dependencies
+
+Install required NPM modules for `LambdaTest Smart UI Selenium SDK` in your **Frontend** project.
+
+```bash
+npm i @lambdatest/smartui-cli @lambdatest/selenium-driver selenium-webdriver
+```
+
+To ensure seamless execution of ES6 modules within our repository, it is essential to configure the Node.js environment to recognize ES6 module syntax. This is accomplished by specifying the module type in your `package.json` file.
+
+
+```bash
+"type": "module"
+```
+
+
+### **Step 3:** Configure your Project Token
+
+Setup your project token show in the **SmartUI** app after, creating your project.
+
+
+
+
+```bash
+export PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
+```
+
+
+
+
+```bash
+set PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
+```
+
+
+
+
+```bash
+$Env:PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
+```
+
+
+
+### **Step 4:** Create and Configure SmartUI Config
+
+You can now configure your project settings on using various available options to run your tests with the SmartUI integration. To generate the configuration file, please execute the following command:
+
+```bash
+smartui config:create smartui-web.json
+```
+
+Once, the configuration file will be created, you will be seeing the default configuration pre-filled in the configuration file:
+
+```json title="/smartui-sdk-project/smartui-web.json"
+{
+ "web": {
+ "browsers": [
+ "chrome",
+ "firefox",
+ "safari",
+ "edge"
+ ],
+ "viewports": [
+ [
+ 1920,
+ 1080
+ ],
+ [
+ 1366,
+ 768
+ ],
+ [
+ 360,
+ 640
+ ]
+ ],
+ "waitForPageRender": 50000,
+ "waitForTimeout": 1000
+
+ }
+}
+```
+
+#### Optional Keys in SmartUI configuration
+
+**waitForPageRender** - If one or more `URLs` in your script require a relatively higher amount of time to load, you may use the `waitForPageRender` key in the config file to make sure the screenshots are rendered correctly. Avoid using the same in case your websites render in less than 30 seconds as it might increase the execution time of your tests.
+
+
+**waitForTimeout** - If you are using any `async` components, you can add wait time for the page to load the DOM of your components. This can help avoid false-positive results for your tests. You can add the wait time in milliseconds, which might increase the execution time of your tests.
+:::
+
+### **Step 5:** Adding SmartUI function to take screenshot
+
+- You can incorporate SmartUI into your custom `Selenium` automation test (any platform) script by adding the `smartuiSnapshot` function in the required segment of selenium script of which we would like to take the screenshot, as shown below:
+
+
+```js
+import { Builder, By, Key, until } from 'selenium-webdriver';
+import { smartuiSnapshot } from '@lambdatest/selenium-driver';
+
+(async function example() {
+ let driver = await new Builder()
+ .forBrowser('chrome')
+ .build();
+
+ try {
+ await driver.get(''); //enter your desired URL here
+ await smartuiSnapshot(driver, '');
+ // Please specify your driver and the screenshot name in this function
+ // driver - selenium driver instance (required)
+ // Screenshot_Name - Name of the screenshot ; unique to each screenshot (required)
+ await driver.get('https://www.example.com');
+ await smartuiSnapshot(driver, '');
+ } finally {
+ await driver.quit();
+ }
+})();
+
+
+```
+
+### **Step 6:** Execute the Tests on SmartUI Cloud
+
+Execute `visual regression tests` on SmartUI using the following commands
+
+```bash
+npx smartui exec node .js
+```
+
+**You may use the `smartui --help` command in case you are facing issues during the execution of SmartUI commands in the CLI.
+**
+## View SmartUI Results
+
+You have successfully integrated SmartUI SDK with your Selenium tests. Visit your SmartUI project to view builds and compare snapshots between different test runs.
+
+You can see the Smart UI dashboard to view the results. This will help you identify the mis-matches from the existing `Baseline` build and do the required visual testing.
+
+
+
+For additional information about SmartUI APIs please explore the documentation [here](https://www.lambdatest.com/support/api-doc/)
diff --git a/sdk/package.json b/sdk/package.json
new file mode 100644
index 0000000..31e6391
--- /dev/null
+++ b/sdk/package.json
@@ -0,0 +1,18 @@
+{
+ "dependencies": {
+ "@lambdatest/selenium-driver": "^1.0.1",
+ "@lambdatest/smartui-cli": "^2.0.3",
+ "selenium-webdriver": "^4.16.0"
+ },
+ "type": "module",
+ "name": "sdk",
+ "version": "1.0.0",
+ "description": "",
+ "main": "sdk.js",
+ "scripts": {
+ "smartui-local": "smartui exec node sdkLocal.js",
+ "smartui-cloud": "smartui exec node sdkCloud.js"
+ },
+ "author": "",
+ "license": "ISC"
+}
diff --git a/sdk/sdkCloud.js b/sdk/sdkCloud.js
new file mode 100644
index 0000000..0a058e4
--- /dev/null
+++ b/sdk/sdkCloud.js
@@ -0,0 +1,40 @@
+import { Builder, By, Key, until } from "selenium-webdriver";
+import { smartuiSnapshot } from "@lambdatest/selenium-driver";
+
+// username: Username can be found at automation dashboard
+const USERNAME = process.env.LT_USERNAME || "";
+
+// AccessKey: AccessKey can be generated from automation dashboard or profile section
+const KEY = process.env.LT_ACCESS_KEY || "";
+let capabilities = {
+ platform: "catalina",
+ browserName: "chrome",
+ version: "latest",
+ "LT:Options": {
+ username: USERNAME,
+ accessKey: KEY,
+ project: "",
+ w3c: true,
+ name: "", // name of the test
+ build: "