Skip to content

Test #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Test #39

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/LThooks-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h1>Smart UI Testing With Selenium Node.JS</h1>
<h1>Smart UI Testing With Selenium Node.JS</h1>

<img height="400" src="https://user-images.githubusercontent.com/126776938/232535511-8d51cf1b-1a33-48fc-825c-b13e7a9ec388.png">
<img height="400" src="https://user-images.githubusercontent.com/126776938/232535511-8d51cf1b-1a33-48fc-825c-b13e7a9ec388.png">


<p align="center">
<p align="center">
<a href="https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample" target="_bank">Blog</a>
&nbsp; &#8901; &nbsp;
<a href="https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample" target="_bank">Docs</a>
Expand All @@ -13,7 +13,7 @@
<a href="https://www.lambdatest.com/newsletter/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample" target="_bank">Newsletter</a>
&nbsp; &#8901; &nbsp;
<a href="https://www.lambdatest.com/certifications/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample" target="_bank">Certifications</a>
&nbsp; &#8901; &nbsp;
&nbsp; &#8901; &nbspn;
<a href="https://www.youtube.com/c/LambdaTest" target="_bank">YouTube</a>
</p>
&emsp;
Expand Down Expand Up @@ -162,4 +162,4 @@ import { smartuiSnapshot } from '@lambdatest/selenium-driver';

```bash
npx smartui exec node <fileName>.js
```
```
2 changes: 1 addition & 1 deletion hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


<p align="center">
<a href="https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample" target="_bank">Blog</a>
<a href="https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample" target="_bank">Blog</a>
&nbsp; &#8901; &nbsp;
<a href="https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample" target="_bank">Docs</a>
&nbsp; &#8901; &nbsp;
Expand Down
197 changes: 195 additions & 2 deletions hooks/examples/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...")
Expand Down