├── .gitignore
├── .gitpod.yml
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── test.js
└── tutorial-images
├── automation testing logs.PNG
├── cmd.PNG
└── lambdaTest desired capabilities generator.png
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | ./package-lock.json
3 |
--------------------------------------------------------------------------------
/.gitpod.yml:
--------------------------------------------------------------------------------
1 | # This configuration file was automatically generated by Gitpod.
2 | # Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
3 | # and commit this file to your remote git repository to share the goodness with others.
4 |
5 | tasks:
6 | - init: npm install && npm test
7 |
8 |
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Run Selenium Tests With Node.js On LambdaTest
2 |
3 |
4 |
5 |
6 |
7 |
8 | Blog
9 | ⋅
10 | Docs
11 | ⋅
12 | Learning Hub
13 | ⋅
14 | Newsletter
15 | ⋅
16 | Certifications
17 | ⋅
18 | YouTube
19 |
20 |
21 |
22 |
23 |
24 | *Learn how to use Node.js environment to configure and run your JavaScript automation testing scripts on the [LambdaTest Selenium cloud platform](https://www.lambdatest.com/selenium-automation/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample).*
25 |
26 | [
](https://accounts.lambdatest.com/register)
27 |
28 | ## Table of Contents
29 |
30 | * [Pre-requisites](#pre-requisites)
31 | * [Run Your First Test](#run-your-first-test)
32 | * [Executing The Test](#executing-the-test)
33 | * [Testing Locally Hosted or Privately Hosted Projects](#testing-locally-hosted-or-privately-hosted-projects)
34 |
35 | ## Pre-requisites
36 |
37 | Before getting started with Selenium automation testing on LambdaTest, you need to:
38 |
39 | * Download and install **NodeJS**. You should be having **NodeJS v6 to NodeJS v16**. Click [here](https://nodejs.org/en/) to download.
40 | * Make sure you are using the latest version of **JavaScript**.
41 | * Install **npm** from the official website by clicking [here](https://www.npmjs.com/).
42 | * Download [Selenium JavaScript bindings](https://www.selenium.dev/downloads/) from the official website. Latest versions of **Selenium Client** and **WebDriver** are ideal for running your JavaScript automation testing script on LambdaTest’s Selenium Grid.
43 |
44 | ### Installing Selenium Dependencies and tutorial repo
45 |
46 | Clone the LambdaTest’s [nodejs-selenium-sample](https://github.com/LambdaTest/nodejs-selenium-sample) repository and navigate to the code directory as shown below:
47 |
48 | ```bash
49 | git clone https://github.com/LambdaTest/nodejs-selenium-sample
50 | cd nodejs-selenium-sample
51 | ```
52 | You need to install the following dependencies to your `package.json` file:
53 |
54 | You will need to install the `selenium webdriver` to make the connection to the `GRID`:
55 |
56 | ```bash
57 | npm install selenium-webdriver
58 | ```
59 |
60 | Create a new file as `index.js` in your current project or the sample folder and add the below code snippet which will call the installed driver.
61 |
62 | ```js
63 | // index.js
64 | const webdriver = require('selenium-webdriver');
65 | ```
66 |
67 | ### Setting up Your Authentication
68 |
69 | Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest Selenium Grid. You can obtain these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample) or through [LambdaTest Profile](https://accounts.lambdatest.com/login/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample).
70 |
71 | Set LambdaTest `Username` and `Access Key` in environment variables.
72 |
73 | * For **Linux/macOS**:
74 | ```bash
75 | export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY"
76 | ```
77 | * For **Windows**:
78 | ```bash
79 | set LT_USERNAME="YOUR_USERNAME" set LT_ACCESS_KEY="YOUR ACCESS KEY"
80 | ```
81 |
82 | ### Connecting to The Cloud Grid
83 |
84 | Now you can add the `GRID HOST` which is used to connect your current test suites to be executed on the cloud grid.
85 |
86 | ```js
87 | // index.js
88 | // username: Username can be found at automation dashboard
89 | const username = process.env.LT_USERNAME;
90 |
91 | // AccessKey: AccessKey can be generated from automation dashboard or profile section
92 | const accessKey = process.env.LT_ACCESS_KEY;
93 |
94 | const gridUrl = 'https://' + username + ':' + accessKey + '@hub.lambdatest.com/wd/hub';
95 |
96 | // Setup and build selenium driver object
97 | const driver = new webdriver.Builder()
98 | .usingServer(gridUrl)
99 | .withCapabilities(capabilities)
100 | .build();
101 |
102 | ```
103 | The above grid connect will create the `Webdriver` for the test suite to execute the `Selenium` commands for your test.
104 |
105 | ## Run Your First Test
106 |
107 | ### Configuration of Your Test Capabilities
108 |
109 | In the test script, you need to update your test capabilities. In this code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. The capabilities object in the above code are defined as:
110 |
111 | ```js
112 | // index.js
113 | // Setup capabilities, Know more about LamdbdaTest Capabilities: https://www.lambdatest.com/capabilities-generator/
114 | const capabilities = {
115 | "browserName": "Chrome",
116 | // "browserVersion": "latest", #Uncomment to Specify Browser Version
117 | "LT:Options": {
118 | name: 'NodeJS Get Set Go', // name of the test
119 | build: 'NodeJS Loves LambdaTest', // name of the build
120 | "project": "Build-With-LambdaTtest",
121 | "w3c": true,
122 | "plugin": "NodeJS",
123 | "customData": {
124 | "buildNumber": "1234",
125 | "environment": "Staging",
126 | "apiVersion": "v1.2.3",
127 | "releaseTag": "v1.2.3-rc1"
128 | },
129 |
130 | }
131 | ```
132 | > **Note:** You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)**.
133 |
134 | ### Writing your Test Cases
135 |
136 | Now you write your selenium test cases in your `index.js` file:
137 |
138 | ```js
139 | async function todoTest() {
140 | try {
141 | // Navigate to a URL, click on the first and second list items and add a new one in the list.
142 | await driver.get('https://lambdatest.github.io/sample-todo-app/');
143 | await driver.findElement(webdriver.By.name('li1')).click();
144 | console.log("Successfully clicked first list item.");
145 | await driver.findElement(webdriver.By.name('li2')).click();
146 | console.log("Successfully clicked second list item.");
147 |
148 | await driver.findElement(webdriver.By.id('sampletodotext')).sendKeys('Complete Lambdatest Tutorial\n');
149 | await driver.findElement(webdriver.By.id('addbutton')).click();
150 | console.log("Successfully added a new task.");
151 | await driver.executeScript('lambda-status=passed');
152 | } catch (err) {
153 | console.log("test failed with reason " + err);
154 | await driver.executeScript('lambda-status=failed');
155 | } finally {
156 | await driver.quit();
157 | }
158 | }
159 |
160 | todoTest();
161 | ```
162 |
163 | ## Executing the Test
164 |
165 | Please execute the following command below to run your tests:
166 |
167 | ```bash
168 | npm test OR node index.js
169 | ```
170 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on [LambdaTest automation dashboard](https://automation.lambdatest.com/build/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample). LambdaTest Automation Dashboard will help you view all your text logs, screenshots and video recording for your entire automation tests.
171 |
172 | ## Testing Locally Hosted or Privately Hosted Projects
173 |
174 | You can test your locally hosted or privately hosted projects with [LambdaTest Selenium grid cloud](https://www.lambdatest.com/selenium-automation/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample) using LambdaTest Tunnel app. All you would have to do is set up an SSH tunnel using LambdaTest Tunnel app and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are made live.
175 |
176 | >Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information.
177 |
178 | Here’s how you can establish LambdaTest Tunnel.
179 |
180 | >Download the binary file of:
181 | * [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip)
182 | * [LambdaTest Tunnel for Mac](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip)
183 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip)
184 |
185 | Open command prompt and navigate to the binary folder.
186 |
187 | Run the following command:
188 | ```bash
189 | LT -user {user’s login email} -key {user’s access key}
190 | ```
191 | So if your user name is lambdatest@example.com and key is 123456, the command would be:
192 | ```bash
193 | LT -user lambdatest@example.com -key 123456
194 | ```
195 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below :
196 |
197 | **Tunnel Capability**
198 | ```js
199 | const capabilities = {
200 | tunnel: true,
201 | }
202 | ```
203 |
204 | ## Additional Links
205 |
206 | * [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/selenium-automation-capabilities/)
207 | * [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/)
208 | * [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/)
209 |
210 | ## Tutorials 📙
211 |
212 | Check out our latest tutorials on JavaScript automation testing 👇
213 |
214 | * [How To Perform Modern Web Testing With TestCafe Using JavaScript And Selenium](https://www.lambdatest.com/blog/modern-web-testing-with-testcafe/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
215 | * [How To Implement Drag And Drop In JavaScript Using Selenium?](https://www.lambdatest.com/blog/how-to-implement-drag-and-drop-in-javascript/#:~:text=Launch%20the%20browser.,Close%20the%20browser./?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
216 | * [Automation Testing with Selenium JavaScript [Tutorial]](https://www.lambdatest.com/blog/automation-testing-with-selenium-javascript/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
217 | * [Best 9 JavaScript Testing Frameworks](https://www.lambdatest.com/blog/top-javascript-automation-testing-framework/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
218 | * [Jest vs Mocha vs Jasmine: Comparing The Top 3 JavaScript Testing Frameworks](https://www.lambdatest.com/blog/jest-vs-mocha-vs-jasmine/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
219 | * [How To Use JavaScript Wait Function In Selenium WebDriver](https://www.lambdatest.com/blog/javascript-wait-in-selenium-webdriver/#SeleniumWebDriver/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
220 | * [Jest Tutorial For Selenium JavaScript Testing With Examples](https://www.lambdatest.com/blog/jest-tutorial-for-selenium-javascript-testing-with-examples/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
221 | * [Cucumber.js Tutorial with Examples For Selenium JavaScript](https://www.lambdatest.com/blog/cucumberjs-tutorial-selenium/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
222 | * [Mocha JavaScript Tutorial With Examples For Selenium Testing](https://www.lambdatest.com/blog/mocha-javascript-tutorial-with-examples-for-selenium-testing/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
223 | * [How To Get Data Of Attributes In JavaScript With Selenium](https://www.lambdatest.com/blog/how-to-get-data-of-attributes-in-javascript-with-selenium/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
224 | * [How To Take Screenshots In Selenium WebDriver Using JavaScript](https://www.lambdatest.com/blog/taking-screenshots-in-selenium-webdriver-using-javascript/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
225 | * [How To Use Strings In JavaScript With Selenium WebDriver](https://www.lambdatest.com/blog/using-strings-in-javascript-using-selenium-webdriver/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
226 | * [How To Use JavaScript Wait Function In Selenium WebDriver](https://www.lambdatest.com/blog/javascript-wait-in-selenium-webdriver/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
227 |
228 | ## Documentation & Resources :books:
229 |
230 | Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing.
231 |
232 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
233 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
234 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
235 |
236 | ## LambdaTest Community :busts_in_silhouette:
237 |
238 | The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎
239 |
240 | ## What's New At LambdaTest ❓
241 |
242 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
243 |
244 | ## About LambdaTest
245 |
246 | [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs.
247 |
248 | ### Features
249 |
250 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
251 | * Real-time cross browser testing on 3000+ environments.
252 | * Test on Real device cloud
253 | * Blazing fast test automation with HyperExecute
254 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
255 | * Smart Visual Regression Testing on cloud
256 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
257 | * Automated Screenshot testing across multiple browsers in a single click.
258 | * Local testing of web and mobile apps.
259 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
260 | * Geolocation testing of web and mobile apps across 53+ countries.
261 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports
262 |
263 | [
](https://accounts.lambdatest.com/register)
264 |
265 | ## We are here to help you :headphones:
266 |
267 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
268 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=nodejs-selenium-sample)
269 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | LambdaTest selenium automation sample example
3 | Configuration
4 | ----------
5 | username: Username can be found at automation dashboard
6 | accessKey: AccessKey can be generated from automation dashboard or profile section
7 |
8 | Result
9 | -------
10 | Execute NodeJS Automation Tests on LambdaTest Cloud Grid
11 | */
12 |
13 | const webdriver = require('selenium-webdriver');
14 |
15 | // username: Username can be found at automation dashboard
16 | const username = process.env.LT_USERNAME;
17 |
18 | // AccessKey: AccessKey can be generated from automation dashboard or profile section
19 | const accessKey = process.env.LT_ACCESS_KEY;
20 |
21 | async function todoTest() {
22 | // Setup Input capabilities, Know more about LamdbdaTest Capabilities: https://www.lambdatest.com/capabilities-generator/
23 | const capabilities = {
24 | "browserName": "Chrome",
25 | // "browserVersion": "latest", #Uncomment to Specify Browser Version
26 | "LT:Options": {
27 | name: 'NodeJS Get Set Go', // name of the test
28 | build: 'NodeJS Loves LambdaTest', // name of the build
29 | "project": "Build-With-LambdaTtest",
30 | "w3c": true,
31 | "plugin": "NodeJS",
32 | "customData": {
33 | "buildNumber": "1234",
34 | "environment": "Staging",
35 | "apiVersion": "v1.2.3",
36 | "releaseTag": "v1.2.3-rc1"
37 | },
38 |
39 | }
40 | }
41 |
42 | const gridUrl = 'https://' + username + ':' + accessKey + '@hub.lambdatest.com/wd/hub';
43 |
44 | // Setup and build selenium driver object
45 | const driver = new webdriver.Builder()
46 | .usingServer(gridUrl)
47 | .withCapabilities(capabilities)
48 | .build();
49 |
50 | try {
51 | // Navigate to a URL, click on the first and second list items and add a new one in the list.
52 | await driver.get('https://lambdatest.github.io/sample-todo-app/');
53 | await driver.findElement(webdriver.By.name('li1')).click();
54 | console.log("Successfully clicked first list item.");
55 | await driver.findElement(webdriver.By.name('li2')).click();
56 | console.log("Successfully clicked second list item.");
57 |
58 | await driver.findElement(webdriver.By.id('sampletodotext')).sendKeys('Complete Lambdatest Tutorial\n');
59 | await driver.findElement(webdriver.By.id('addbutton')).click();
60 | console.log("Successfully added a new task.");
61 | await driver.executeScript('lambda-status=passed');
62 | } catch (err) {
63 | console.log("test failed with reason " + err);
64 | await driver.executeScript('lambda-status=failed');
65 | } finally {
66 | await driver.quit();
67 | }
68 | }
69 |
70 | todoTest();
71 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nodejs-selenium-sample",
3 | "version": "1.0.1",
4 | "lockfileVersion": 3,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "nodejs-selenium-sample",
9 | "version": "1.0.1",
10 | "license": "ISC",
11 | "dependencies": {
12 | "selenium-webdriver": "^4.9.0"
13 | }
14 | },
15 | "node_modules/balanced-match": {
16 | "version": "1.0.2",
17 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
18 | "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
19 | },
20 | "node_modules/brace-expansion": {
21 | "version": "1.1.11",
22 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
23 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
24 | "dependencies": {
25 | "balanced-match": "^1.0.0",
26 | "concat-map": "0.0.1"
27 | }
28 | },
29 | "node_modules/concat-map": {
30 | "version": "0.0.1",
31 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
32 | "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
33 | },
34 | "node_modules/core-util-is": {
35 | "version": "1.0.3",
36 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
37 | "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
38 | },
39 | "node_modules/fs.realpath": {
40 | "version": "1.0.0",
41 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
42 | "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
43 | },
44 | "node_modules/glob": {
45 | "version": "7.2.3",
46 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
47 | "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
48 | "dependencies": {
49 | "fs.realpath": "^1.0.0",
50 | "inflight": "^1.0.4",
51 | "inherits": "2",
52 | "minimatch": "^3.1.1",
53 | "once": "^1.3.0",
54 | "path-is-absolute": "^1.0.0"
55 | },
56 | "engines": {
57 | "node": "*"
58 | },
59 | "funding": {
60 | "url": "https://github.com/sponsors/isaacs"
61 | }
62 | },
63 | "node_modules/immediate": {
64 | "version": "3.0.6",
65 | "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
66 | "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
67 | },
68 | "node_modules/inflight": {
69 | "version": "1.0.6",
70 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
71 | "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
72 | "dependencies": {
73 | "once": "^1.3.0",
74 | "wrappy": "1"
75 | }
76 | },
77 | "node_modules/inherits": {
78 | "version": "2.0.4",
79 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
80 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
81 | },
82 | "node_modules/isarray": {
83 | "version": "1.0.0",
84 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
85 | "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
86 | },
87 | "node_modules/jszip": {
88 | "version": "3.10.1",
89 | "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
90 | "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
91 | "dependencies": {
92 | "lie": "~3.3.0",
93 | "pako": "~1.0.2",
94 | "readable-stream": "~2.3.6",
95 | "setimmediate": "^1.0.5"
96 | }
97 | },
98 | "node_modules/lie": {
99 | "version": "3.3.0",
100 | "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
101 | "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
102 | "dependencies": {
103 | "immediate": "~3.0.5"
104 | }
105 | },
106 | "node_modules/minimatch": {
107 | "version": "3.1.2",
108 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
109 | "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
110 | "dependencies": {
111 | "brace-expansion": "^1.1.7"
112 | },
113 | "engines": {
114 | "node": "*"
115 | }
116 | },
117 | "node_modules/once": {
118 | "version": "1.4.0",
119 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
120 | "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
121 | "dependencies": {
122 | "wrappy": "1"
123 | }
124 | },
125 | "node_modules/pako": {
126 | "version": "1.0.11",
127 | "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
128 | "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
129 | },
130 | "node_modules/path-is-absolute": {
131 | "version": "1.0.1",
132 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
133 | "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
134 | "engines": {
135 | "node": ">=0.10.0"
136 | }
137 | },
138 | "node_modules/process-nextick-args": {
139 | "version": "2.0.1",
140 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
141 | "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
142 | },
143 | "node_modules/readable-stream": {
144 | "version": "2.3.8",
145 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
146 | "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
147 | "dependencies": {
148 | "core-util-is": "~1.0.0",
149 | "inherits": "~2.0.3",
150 | "isarray": "~1.0.0",
151 | "process-nextick-args": "~2.0.0",
152 | "safe-buffer": "~5.1.1",
153 | "string_decoder": "~1.1.1",
154 | "util-deprecate": "~1.0.1"
155 | }
156 | },
157 | "node_modules/rimraf": {
158 | "version": "3.0.2",
159 | "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
160 | "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
161 | "dependencies": {
162 | "glob": "^7.1.3"
163 | },
164 | "bin": {
165 | "rimraf": "bin.js"
166 | },
167 | "funding": {
168 | "url": "https://github.com/sponsors/isaacs"
169 | }
170 | },
171 | "node_modules/safe-buffer": {
172 | "version": "5.1.2",
173 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
174 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
175 | },
176 | "node_modules/selenium-webdriver": {
177 | "version": "4.9.0",
178 | "resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.9.0.tgz",
179 | "integrity": "sha512-QGaPoREo7sgOVhTiAvCasoi1f4ruTaJDtp0RKNFIbfyns5smK5+iCwnRTIPXb0R3CAYdaqUXd6BHduh37DorzQ==",
180 | "dependencies": {
181 | "jszip": "^3.10.1",
182 | "tmp": "^0.2.1",
183 | "ws": ">=8.13.0"
184 | },
185 | "engines": {
186 | "node": ">= 14.20.0"
187 | }
188 | },
189 | "node_modules/setimmediate": {
190 | "version": "1.0.5",
191 | "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
192 | "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA=="
193 | },
194 | "node_modules/string_decoder": {
195 | "version": "1.1.1",
196 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
197 | "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
198 | "dependencies": {
199 | "safe-buffer": "~5.1.0"
200 | }
201 | },
202 | "node_modules/tmp": {
203 | "version": "0.2.1",
204 | "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz",
205 | "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==",
206 | "dependencies": {
207 | "rimraf": "^3.0.0"
208 | },
209 | "engines": {
210 | "node": ">=8.17.0"
211 | }
212 | },
213 | "node_modules/util-deprecate": {
214 | "version": "1.0.2",
215 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
216 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
217 | },
218 | "node_modules/wrappy": {
219 | "version": "1.0.2",
220 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
221 | "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
222 | },
223 | "node_modules/ws": {
224 | "version": "8.18.0",
225 | "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
226 | "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
227 | "license": "MIT",
228 | "engines": {
229 | "node": ">=10.0.0"
230 | },
231 | "peerDependencies": {
232 | "bufferutil": "^4.0.1",
233 | "utf-8-validate": ">=5.0.2"
234 | },
235 | "peerDependenciesMeta": {
236 | "bufferutil": {
237 | "optional": true
238 | },
239 | "utf-8-validate": {
240 | "optional": true
241 | }
242 | }
243 | }
244 | }
245 | }
246 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nodejs-selenium-sample",
3 | "version": "1.0.1",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "node index.js"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/4msha/nodejs-selenium-sample.git"
12 | },
13 | "author": "",
14 | "license": "ISC",
15 | "bugs": {
16 | "url": "https://github.com/4msha/nodejs-selenium-sample/issues"
17 | },
18 | "homepage": "https://github.com/4msha/nodejs-selenium-sample#readme",
19 | "dependencies": {
20 | "selenium-webdriver": "^4.9.0"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | const webdriver = require('selenium-webdriver');
2 | const By = webdriver.By;
3 |
4 | // Setup LambdaTest authentication and grid URL
5 | const USERNAME = process.env.LT_USERNAME;
6 | const KEY = process.env.LT_ACCESS_KEY;
7 | const GRID_HOST = 'hub.lambdatest.com/wd/hub';
8 |
9 | async function pdfWebTest() {
10 | // Setup Input capabilities, Know more about LamdbdaTest Capabilities: https://www.lambdatest.com/capabilities-generator/
11 | const capabilities = {
12 | "browserName": "Chrome",
13 | // "browserVersion": "latest", #Uncomment to Specify Browser Version
14 | "LT:Options": {
15 | name: 'NodeJS Get Set Go', // name of the test
16 | build: 'NodeJS Loves LambdaTest', // name of the build
17 | "project": "Build-With-LambdaTtest",
18 | "w3c": true,
19 | "plugin": "NodeJS",
20 | "customData":
21 | {
22 | _id: "5f46aaa69adf77cfe2bb4fd6",
23 | index: "0",
24 | guid: "9451b204-12f0-4177-8fe9-fb019b3e4bf3",
25 | isActive: "False",
26 | picture: "http://placehold.it/32x32",
27 | },
28 |
29 | }
30 | };
31 |
32 | const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;
33 |
34 | // Setup and build selenium driver object
35 | const driver = new webdriver.Builder()
36 | .usingServer(gridUrl)
37 | .withCapabilities(capabilities)
38 | .build();
39 |
40 | try {
41 | await driver.get('https://pdfstandalone.com/#/');
42 |
43 | // Get the elements with the specified XPath
44 | const elements = await driver.findElements(By.xpath('//span[@title="Language"]'));
45 |
46 | // Click on the first element (index 0)
47 | if (elements.length > 0) {
48 | await elements[0].click();
49 | console.log("Successfully clicked first list item.");
50 | }
51 | driver.executeScript('lambda-status=passed');
52 |
53 | // Close the browser
54 | await driver.quit();
55 | } catch (err) {
56 | console.log("test failed with reason " + err);
57 | driver.executeScript('lambda-status=failed');
58 | driver.quit();
59 | }
60 | }
61 |
62 | pdfWebTest();
63 |
--------------------------------------------------------------------------------
/tutorial-images/automation testing logs.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LambdaTest/nodejs-selenium-sample/ea0cdf1ea0d7213ede07e443d1f20de29d3cee6a/tutorial-images/automation testing logs.PNG
--------------------------------------------------------------------------------
/tutorial-images/cmd.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LambdaTest/nodejs-selenium-sample/ea0cdf1ea0d7213ede07e443d1f20de29d3cee6a/tutorial-images/cmd.PNG
--------------------------------------------------------------------------------
/tutorial-images/lambdaTest desired capabilities generator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LambdaTest/nodejs-selenium-sample/ea0cdf1ea0d7213ede07e443d1f20de29d3cee6a/tutorial-images/lambdaTest desired capabilities generator.png
--------------------------------------------------------------------------------