|
| 1 | +const webdriver = require("selenium-webdriver"); |
| 2 | +const automationConfig = require("./parallel-config.json"); |
| 3 | +const smartUITests = require("./urls.json"); |
| 4 | + |
| 5 | +// USERNAME: Username can be found at automation dashboard |
| 6 | +const USERNAME = process.env.LT_USERNAME || "<Your_Username>"; |
| 7 | + |
| 8 | +// KEY: AccessKey can be generated from automation dashboard or profile section |
| 9 | +const KEY = process.env.LT_ACCESS_KEY || "<Your_Access_key>"; |
| 10 | + |
| 11 | +//connect to Lambdatest hub |
| 12 | +const GRID_HOST = process.env.GRID_HOST || "@hub.lambdatest.com/wd/hub"; |
| 13 | + |
| 14 | +const gridUrl = "https://" + USERNAME + ":" + KEY + GRID_HOST; |
| 15 | + |
| 16 | +// Selenium WebDriver Function |
| 17 | + |
| 18 | +async function runSmartUIonLambdatest() { |
| 19 | + // Lambdatest Cloud Selenium Grid Connection |
| 20 | + |
| 21 | + // Printing the Lambdatest Cloud Information for the test |
| 22 | + |
| 23 | + console.log("Please visit https://smartui.lambdatest.com to see your SmartUI - Visual Regression Tests"); |
| 24 | + const smartuiBuild = "smartui-build-"+ (Math.random() + 1).toString(36).substring(7); |
| 25 | + console.log("smartuiBuild", smartuiBuild); |
| 26 | + try { |
| 27 | + automationConfig.forEach(async (config) => { |
| 28 | + console.log("########################") |
| 29 | + config["smartUI.build"] = smartuiBuild |
| 30 | + console.log(config) |
| 31 | + const driver = await new webdriver.Builder() |
| 32 | + .usingServer(gridUrl) |
| 33 | + .withCapabilities(config) |
| 34 | + .build(); |
| 35 | + try { |
| 36 | + smartUITests.forEach((smartUITest) => { |
| 37 | + console.log("Opening URL ") |
| 38 | + console.log(smartUITest) |
| 39 | + let smartUI_ScreenshotName = smartUITest.screenshotName; |
| 40 | + let smartUI_url = smartUITest.url; |
| 41 | + smartUISeleniumTest(driver, smartUI_url, smartUI_ScreenshotName); |
| 42 | + }); |
| 43 | + } catch (err) { |
| 44 | + console.log(err); |
| 45 | + } |
| 46 | + // Closing the Browser Session |
| 47 | + await driver.executeScript("lambda-status=passed"); |
| 48 | + await driver.quit(); |
| 49 | + }); |
| 50 | + } catch (err) { |
| 51 | + console.log(JSON.stringify(err)); |
| 52 | + await driver.executeScript("lambda-status=failed"); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +async function smartUISeleniumTest(driver, url, screenshotName) { |
| 57 | + await driver |
| 58 | + .get(url) |
| 59 | + .then(() => { |
| 60 | + // For Smartui TakeScreenshot |
| 61 | + console.log(`Capturing the Screenshot Name: ${screenshotName} | URL: ${url}`); |
| 62 | + driver |
| 63 | + .executeScript(`smartui.takeScreenshot=${screenshotName}`) |
| 64 | + .then((result) => { |
| 65 | + console.log("Result :", result); |
| 66 | + }); |
| 67 | + }) |
| 68 | + .catch((err) => { |
| 69 | + console.log(err); |
| 70 | + }); |
| 71 | +} |
| 72 | + |
| 73 | +// Executing the tests in parallel of multiple urls |
| 74 | +runSmartUIonLambdatest(); |
0 commit comments