|
| 1 | +/* |
| 2 | + LambdaTest selenium automation sample example |
| 3 | + Configuration |
| 4 | + ---------- |
| 5 | + username: Username can be found at automation dashboard |
| 6 | + accessToken: AccessToken can be generated from automation dashboard or profile section |
| 7 | +
|
| 8 | + Result |
| 9 | + ------- |
| 10 | + Execute NodeJS Automation Tests on LambdaTest Distributed Selenium Grid |
| 11 | +*/ |
| 12 | +const webdriver = require('selenium-webdriver'); |
| 13 | + |
| 14 | +/* |
| 15 | + Setup remote driver |
| 16 | + Params |
| 17 | + ---------- |
| 18 | + platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks) |
| 19 | + browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge, Safari) |
| 20 | + version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/ |
| 21 | +*/ |
| 22 | + |
| 23 | +// username: Username can be found at automation dashboard |
| 24 | +const USERNAME = 'ajaykorni'; |
| 25 | + |
| 26 | +// AccessKey: AccessKey can be generated from automation dashboard or profile section |
| 27 | +const KEY = 'ajaykorni'; |
| 28 | + |
| 29 | +// gridUrl: gridUrl can be found at automation dashboard |
| 30 | +const GRID_HOST = 'facebook.com'; |
| 31 | + |
| 32 | +function searchTextOnGoogle() { |
| 33 | + |
| 34 | + // Setup Input capabilities |
| 35 | + const capabilities = { |
| 36 | + platform: 'ubuntu', |
| 37 | + browserName: 'chrome', |
| 38 | + version: '67.0', |
| 39 | + resolution: '1280x800', |
| 40 | + network: true, |
| 41 | + visual: true, |
| 42 | + console: true, |
| 43 | + video: true, |
| 44 | + name: 'Test 1', // name of the test |
| 45 | + build: 'NodeJS build' // name of the build |
| 46 | + } |
| 47 | + |
| 48 | + // URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub |
| 49 | + const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST; |
| 50 | + |
| 51 | + // setup and build selenium driver object |
| 52 | + const driver = new webdriver.Builder() |
| 53 | + .usingServer(gridUrl) |
| 54 | + .withCapabilities(capabilities) |
| 55 | + .build(); |
| 56 | + |
| 57 | + // navigate to a url, search for a text and get title of page |
| 58 | + driver.get('https://www.google.com/ncr').then(function() { |
| 59 | + driver.findElement(webdriver.By.name('q')).sendKeys('LambdaTest\n').then(function() { |
| 60 | + driver.getTitle().then(function(title) { |
| 61 | + setTimeout(function() { |
| 62 | + console.log(title); |
| 63 | + driver.executeScript('lambda-status=passed'); |
| 64 | + driver.quit(); |
| 65 | + }, 5000); |
| 66 | + }); |
| 67 | + }); |
| 68 | + }).catch(function(err){ |
| 69 | + console.log("test failed with reason "+err) |
| 70 | + driver.executeScript('lambda-status=failed'); |
| 71 | + driver.quit(); |
| 72 | + }); |
| 73 | +} |
| 74 | +searchTextOnGoogle(); |
0 commit comments