99 -------
1010 Execute NodeJS Automation Tests on LambdaTest Distributed Selenium Grid
1111*/
12- const webdriver = require ( 'selenium-webdriver' ) ;
1312
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- */
13+ const webdriver = require ( 'selenium-webdriver' ) ;
2214
2315// username: Username can be found at automation dashboard
2416const USERNAME = process . env . LT_USERNAME ;
@@ -29,53 +21,48 @@ const KEY = process.env.LT_ACCESS_KEY;
2921// gridUrl: gridUrl can be found at automation dashboard
3022const GRID_HOST = 'hub.lambdatest.com/wd/hub' ;
3123
32-
33- function searchTextOnGoogle ( ) {
34-
24+ async function searchTextOnGoogle ( ) {
3525 // Setup Input capabilities
26+
3627 const capabilities = {
37- platform : 'windows 10' ,
38- browserName : 'chrome' ,
39- version : 'latest' ,
40- resolution : '1280x800' ,
41- // geoLocation : "US",
42- // network: true,
43- // visual: true,
44- // console: true,
45- // video: true,
46- name : 'Test 1' , // name of the test
47- build : 'NodeJS build' // name of the build
28+ "browserName" : "Chrome" ,
29+ "browserVersion" : "latest" ,
30+ "LT:Options" : {
31+ // "platformName": "Windows 10",
32+ name : 'Test 1' , // name of the test
33+ build : 'NodeJS build' , // name of the build
34+ "project" : "Untitled" ,
35+ "w3c" : true ,
36+ "plugin" : "node_js-node_js"
37+ }
4838 }
4939
5040 // URL: https://{username}:{accessToken}@beta -hub.lambdatest.com/wd/hub
5141 const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST ;
5242
53- // setup and build selenium driver object
43+ // Setup and build selenium driver object
5444 const driver = new webdriver . Builder ( )
5545 . usingServer ( gridUrl )
5646 . withCapabilities ( capabilities )
5747 . build ( ) ;
5848
59- // navigate to a url, click on the first and second list items and add a new one in the list.
60- driver . get ( 'https://lambdatest.github.io/sample-todo-app/' ) . then ( function ( ) {
61- driver . findElement ( webdriver . By . name ( 'li1' ) ) . click ( ) . then ( function ( ) {
62- console . log ( "Successfully clicked first list item." ) ;
63- } ) ;
64- driver . findElement ( webdriver . By . name ( 'li2' ) ) . click ( ) . then ( function ( ) {
65- console . log ( "Successfully clicked second list item." ) ;
66- } ) ;
67-
68- driver . findElement ( webdriver . By . id ( 'sampletodotext' ) ) . sendKeys ( 'Complete Lambdatest Tutorial\n' ) . then ( function ( ) {
69- driver . findElement ( webdriver . By . id ( 'addbutton' ) ) . click ( ) . then ( function ( ) {
70- console . log ( "Successfully added a new task." ) ;
71- } )
72- } ) ;
49+ try {
50+ // Navigate to a URL, click on the first and second list items and add a new one in the list.
51+ await driver . get ( 'https://lambdatest.github.io/sample-todo-app/' ) ;
52+ await driver . findElement ( webdriver . By . name ( 'li1' ) ) . click ( ) ;
53+ console . log ( "Successfully clicked first list item." ) ;
54+ await driver . findElement ( webdriver . By . name ( 'li2' ) ) . click ( ) ;
55+ console . log ( "Successfully clicked second list item." ) ;
7356
74- } ) . catch ( function ( err ) {
75- console . log ( "test failed with reason " + err )
76- driver . executeScript ( 'lambda-status=failed' ) ;
77- driver . quit ( ) ;
78- } ) ;
57+ await driver . findElement ( webdriver . By . id ( 'sampletodotext' ) ) . sendKeys ( 'Complete Lambdatest Tutorial\n' ) ;
58+ await driver . findElement ( webdriver . By . id ( 'addbutton' ) ) . click ( ) ;
59+ console . log ( "Successfully added a new task." ) ;
60+ } catch ( err ) {
61+ console . log ( "test failed with reason " + err ) ;
62+ await driver . executeScript ( 'lambda-status=failed' ) ;
63+ } finally {
64+ await driver . quit ( ) ;
65+ }
7966}
80- searchTextOnGoogle ( ) ;
8167
68+ searchTextOnGoogle ( ) ;
0 commit comments