From e0eb0a0032fd58a4e9f85e1e3df1ac63b1e18f11 Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 00:53:46 +0530 Subject: [PATCH 01/10] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb71fa6..5173755 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

Smart UI Testing With Selenium Node.JS

- +

@@ -162,4 +162,4 @@ import { smartuiSnapshot } from '@lambdatest/selenium-driver'; ```bash npx smartui exec node .js -``` \ No newline at end of file +``` From 6fcb0f10c1ab08269445b84818f609598adae81f Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 00:58:53 +0530 Subject: [PATCH 02/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5173755..2eb5f5f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ -

+

Blog   ⋅   Docs From daed7ec773d0de09f8175298eef94048c85dabf5 Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 01:00:55 +0530 Subject: [PATCH 03/10] Update README.md --- hooks/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/README.md b/hooks/README.md index 26bc724..8143a26 100644 --- a/hooks/README.md +++ b/hooks/README.md @@ -4,7 +4,7 @@

- Blog + Blog   ⋅   Docs   ⋅   From 9203613a190eaa2995ee9064207da582a8ef2b7d Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 02:38:51 +0530 Subject: [PATCH 04/10] Update LThooks-ci.yml --- .github/workflows/LThooks-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/LThooks-ci.yml b/.github/workflows/LThooks-ci.yml index 5c7b8e3..cdd5d0c 100644 --- a/.github/workflows/LThooks-ci.yml +++ b/.github/workflows/LThooks-ci.yml @@ -5,9 +5,9 @@ on: - main env: - LT_USERNAME: ${{ secrets.LT_USERNAME }} - LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }} - GRID_HOST: ${{ secrets.GRID_HOST }} + LT_USERNAME: sanchits + LT_ACCESS_KEY: LT_7oXbVfsJOn6xlDfEkpADYtJFIkeUFkyPclOAKmntbKz8lem + GRID_HOST: hub.lambdatest.com jobs: SmartUI-Gihub-Action: From f096c4dcb6f0f598143a2e8326c3df5f2aae07c1 Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 03:48:26 +0530 Subject: [PATCH 05/10] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb71fa6..7966511 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

@@ -162,4 +162,4 @@ import { smartuiSnapshot } from '@lambdatest/selenium-driver'; ```bash npx smartui exec node .js -``` \ No newline at end of file +``` From 2c2a76f9079bb63bf636ab6a0cd922cfde27d18d Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 03:49:49 +0530 Subject: [PATCH 06/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7966511..2dff3ae 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Newsletter   ⋅   Certifications -   ⋅   +   ⋅  n; YouTube

  From 5d7df9d1050d5998b308c47286ccf1b9bbcd73e3 Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 03:59:28 +0530 Subject: [PATCH 07/10] Update LThooks-ci.yml --- .github/workflows/LThooks-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/LThooks-ci.yml b/.github/workflows/LThooks-ci.yml index 5c7b8e3..cdd5d0c 100644 --- a/.github/workflows/LThooks-ci.yml +++ b/.github/workflows/LThooks-ci.yml @@ -5,9 +5,9 @@ on: - main env: - LT_USERNAME: ${{ secrets.LT_USERNAME }} - LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }} - GRID_HOST: ${{ secrets.GRID_HOST }} + LT_USERNAME: sanchits + LT_ACCESS_KEY: LT_7oXbVfsJOn6xlDfEkpADYtJFIkeUFkyPclOAKmntbKz8lem + GRID_HOST: hub.lambdatest.com jobs: SmartUI-Gihub-Action: From a3caa7b6a072d2d82ae902425a881314adc12aa0 Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 04:57:47 +0530 Subject: [PATCH 08/10] Update test.js --- hooks/examples/test.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hooks/examples/test.js b/hooks/examples/test.js index 0849f4d..1d35f85 100644 --- a/hooks/examples/test.js +++ b/hooks/examples/test.js @@ -94,12 +94,26 @@ async function startTest(gridUrl, capabilities, name) { console.log(caps.name, " : Setup Time :", duration.asSeconds()); // navigate to a url - let url = "https://www.lambdatest.com"; + let url = "https://devci.worksonlocal.dev/tests/player-dynamic/#/testbed?manifest=visual-regression-multiple-choice"; console.log(url); await driver .get(url) .then(function () { const session = driver.getSession(); + const { JSDOM } = require('jsdom'); + +// Simulate a document +const dom = new JSDOM(`
Visible
`); +global.window = dom.window; +global.document = dom.window.document; + +function isDisplayed(elem) { + return !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length); +} + +const target = document.getElementById("target"); + +console.log("Element is displayed:", isDisplayed(target)); // For Smartui TakeScreenshot setTimeout(function () { From 5cfad11562fa3d6eb172b4b68f12b837a89004c1 Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Sat, 21 Jun 2025 05:02:40 +0530 Subject: [PATCH 09/10] Update test.js --- hooks/examples/test.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/hooks/examples/test.js b/hooks/examples/test.js index 1d35f85..4977d9d 100644 --- a/hooks/examples/test.js +++ b/hooks/examples/test.js @@ -100,21 +100,7 @@ async function startTest(gridUrl, capabilities, name) { .get(url) .then(function () { const session = driver.getSession(); - const { JSDOM } = require('jsdom'); - -// Simulate a document -const dom = new JSDOM(`
Visible
`); -global.window = dom.window; -global.document = dom.window.document; - -function isDisplayed(elem) { - return !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length); -} - -const target = document.getElementById("target"); - -console.log("Element is displayed:", isDisplayed(target)); - + // For Smartui TakeScreenshot setTimeout(function () { console.log("taking screenshot ...") From 8d53ca76f3875704e6a1ff2cc4c621496bd37027 Mon Sep 17 00:00:00 2001 From: sanchit0612 Date: Mon, 23 Jun 2025 19:10:54 +0530 Subject: [PATCH 10/10] Update test.js --- hooks/examples/test.js | 224 +++++++++++++++++++++++++++++++++++------ 1 file changed, 191 insertions(+), 33 deletions(-) diff --git a/hooks/examples/test.js b/hooks/examples/test.js index 0849f4d..22e44d5 100644 --- a/hooks/examples/test.js +++ b/hooks/examples/test.js @@ -94,39 +94,197 @@ async function startTest(gridUrl, capabilities, name) { console.log(caps.name, " : Setup Time :", duration.asSeconds()); // navigate to a url - let url = "https://www.lambdatest.com"; + let url = "https://devci.worksonlocal.dev/tests/player-dynamic/#/testbed?manifest=visual-regression-multiple-choice"; + console.log(url); - await driver - .get(url) - .then(function () { - const session = driver.getSession(); - - // For Smartui TakeScreenshot - setTimeout(function () { - console.log("taking screenshot ...") - let config = { - screenshotName: "web-page" - }; - driver.executeScript("smartui.takeScreenshot", config).then(out => { - console.log("RESPONSE :", out) - return - }); - }, waitTime * 1000); - - - driver.getTitle().then(function (title) { - setTimeout(function () { - driver.executeScript("lambda-status=passed"); - driver.quit(); - }, 15000); - }); - }) - .catch(function (err) { - error = JSON.stringify(err); - console.log(error); - console.log("test failed with reason " + err); - driver.executeScript("lambda-status=failed"); - driver.quit(); - }); + try { + await driver.get(url); + console.log("URL loaded successfully"); + + // Wait for the document ready state to be 'complete' + let readyState = ''; + for (let i = 0; i < 20; i++) { // up to 10 seconds + readyState = await driver.executeScript('return document.readyState'); + if (readyState === 'complete') break; + await driver.sleep(500); + } + console.log('Document readyState:', readyState); + + // Wait for the page to load and add some debugging + await driver.sleep(2000); // Wait 2 seconds for page to load + + // Try to find the element and wait for it to be present + const startAssessmentElement = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy='startAssessment']")), + 10000 // Wait up to 10 seconds + ); + + await startAssessmentElement.click(); + console.log("Clicked startAssessment button"); + + // Take screenshot after startAssessment click + console.log("taking screenshot after startAssessment click..."); + let config1 = { + screenshotName: "screenshot-1" + }; + const screenshotResult1 = await driver.executeScript("smartui.takeScreenshot", config1); + console.log("RESPONSE :", screenshotResult1); + await driver.sleep(25000); // Wait 25 seconds before checking status + const status1 = await driver.executeScript("smartui.fetchScreenshotStatus=screenshot-1"); + console.log("Screenshot 1 Status:", status1); + + // Wait for the second element and click it + const choiceElement = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy-choice='1']")), + 10000 // Wait up to 10 seconds + ); + await choiceElement.click(); + console.log("Clicked choice 1 button"); + + // Wait for the header element and click it + const headerElement = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy='header']")), + 10000 // Wait up to 10 seconds + ); + await headerElement.click(); + console.log("Clicked header element"); + + // Take screenshot after header click + console.log("taking screenshot after header click..."); + let config2 = { + screenshotName: "screenshot-2" + }; + const screenshotResult2 = await driver.executeScript("smartui.takeScreenshot", config2); + console.log("RESPONSE :", screenshotResult2); + await driver.sleep(25000); // Wait 25 seconds before checking status + const status2 = await driver.executeScript("smartui.fetchScreenshotStatus=screenshot-2"); + console.log("Screenshot 2 Status:", status2); + + // Wait for the second choice element and click it + const choice2Element = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy-choice='2']")), + 10000 // Wait up to 10 seconds + ); + await choice2Element.click(); + console.log("Clicked choice 2 button"); + + // Click on header element again + const headerElement2 = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy='header']")), + 10000 // Wait up to 10 seconds + ); + await headerElement2.click(); + console.log("Clicked header element again"); + + // Take screenshot after second header click + console.log("taking screenshot after second header click..."); + let config3 = { + screenshotName: "screenshot-3" + }; + const screenshotResult3 = await driver.executeScript("smartui.takeScreenshot", config3); + console.log("RESPONSE :", screenshotResult3); + await driver.sleep(25000); // Wait 25 seconds before checking status + const status3 = await driver.executeScript("smartui.fetchScreenshotStatus=screenshot-3"); + console.log("Screenshot 3 Status:", status3); + + // Take additional screenshot after step 5 + console.log("taking additional screenshot after step 5..."); + let config4 = { + screenshotName: "screenshot-4" + }; + const screenshotResult4 = await driver.executeScript("smartui.takeScreenshot", config4); + console.log("RESPONSE :", screenshotResult4); + await driver.sleep(25000); // Wait 25 seconds before checking status + const status4 = await driver.executeScript("smartui.fetchScreenshotStatus=screenshot-4"); + console.log("Screenshot 4 Status:", status4); + + // Wait for the footer next button and click it + const footerNextElement = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy='footer-next-button']")), + 10000 // Wait up to 10 seconds + ); + await footerNextElement.click(); + console.log("Clicked footer next button"); + + // Wait for the footer back button and click it + const footerBackElement = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy='footer-back-button']")), + 10000 // Wait up to 10 seconds + ); + await footerBackElement.click(); + console.log("Clicked footer back button"); + + // Click on choice 2 again + const choice2ElementAgain = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy-choice='2']")), + 10000 // Wait up to 10 seconds + ); + await choice2ElementAgain.click(); + console.log("Clicked choice 2 button again"); + + // Click on header element again + const headerElement3 = await driver.wait( + webdriver.until.elementLocated(By.css("[data-cy='header']")), + 10000 // Wait up to 10 seconds + ); + await headerElement3.click(); + console.log("Clicked header element again"); + + // Take screenshot after third header click + console.log("taking screenshot after third header click..."); + let config5 = { + screenshotName: "screenshot-5" + }; + const screenshotResult5 = await driver.executeScript("smartui.takeScreenshot", config5); + console.log("RESPONSE :", screenshotResult5); + await driver.sleep(25000); // Wait 25 seconds before checking status + const status5 = await driver.executeScript("smartui.fetchScreenshotStatus=screenshot-5"); + console.log("Screenshot 5 Status:", status5); + + console.log("All test steps completed successfully!"); + + // Mark test as passed and quit driver + try { + await driver.executeScript("lambda-status=passed"); + console.log("Test marked as passed"); + } catch (statusErr) { + console.log("Could not set lambda status:", statusErr); + } + + // Quit driver with proper error handling + try { + await driver.quit(); + console.log("Driver quit successfully"); + } catch (quitErr) { + console.log("Driver quit error (this is normal):", quitErr.message); + } + } catch (err) { + error = JSON.stringify(err); + console.log(error); + console.log("test failed with reason " + err); + + // Try to get page source for debugging + try { + const pageSource = await driver.getPageSource(); + console.log("Page source preview:", pageSource.substring(0, 1000)); + } catch (sourceErr) { + console.log("Could not get page source:", sourceErr); + } + + // Mark test as failed and quit driver with proper error handling + try { + await driver.executeScript("lambda-status=failed"); + console.log("Test marked as failed"); + } catch (statusErr) { + console.log("Could not set lambda status:", statusErr); + } + + try { + await driver.quit(); + console.log("Driver quit successfully after error"); + } catch (quitErr) { + console.log("Driver quit error after failure (this is normal):", quitErr.message); + } + } }