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: diff --git a/README.md b/README.md index eb71fa6..f7834f0 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -
+
Blog ⋅ Docs @@ -13,7 +13,7 @@ Newsletter ⋅ Certifications - ⋅ + ⋅  n; YouTube
@@ -162,4 +162,4 @@ import { smartuiSnapshot } from '@lambdatest/selenium-driver'; ```bash npx smartui exec node- Blog + Blog ⋅ Docs ⋅ diff --git a/hooks/examples/test.js b/hooks/examples/test.js index 0849f4d..376aac5 100644 --- a/hooks/examples/test.js +++ b/hooks/examples/test.js @@ -94,13 +94,206 @@ 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); + 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); + } + } + console.log(url); await driver .get(url) .then(function () { const session = driver.getSession(); - + // For Smartui TakeScreenshot setTimeout(function () { console.log("taking screenshot ...")