├── .gitignore
├── .gitpod.yml
├── README.md
├── conf
├── parallel.conf.js
└── single.conf.js
├── package.json
├── scripts
└── lambdatest.js
└── tests
└── single_test.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | package-lock.json
--------------------------------------------------------------------------------
/.gitpod.yml:
--------------------------------------------------------------------------------
1 |
2 | # List the start up tasks. You can start them in parallel in multiple terminals. See https://www.gitpod.io/docs/config-start-tasks/
3 | tasks:
4 | - init: npm install
5 | command: npm run single
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Run Selenium Tests With WD On LambdaTest
2 | 
3 |
4 |
5 | Blog
6 | ⋅
7 | Docs
8 | ⋅
9 | Learning Hub
10 | ⋅
11 | Newsletter
12 | ⋅
13 | Certifications
14 | ⋅
15 | YouTube
16 |
17 |
18 |
19 |
20 |
21 | *Learn how to use WD framework to configure and run your JavaScript automation testing scripts on the LambdaTest platform*
22 |
23 | [
](https://accounts.lambdatest.com/register)
24 |
25 | ## Table Of Contents
26 |
27 | * [Pre-requisites](#pre-requisites)
28 | * [Run Your First Test](#run-your-first-test)
29 | * [Running Your Parallel Tests Using WD Framework](#running-your-parallel-tests-using-wd-framework)
30 | * [Local Testing With TestNG](#testing-locally-hosted-or-privately-hosted-projects)
31 |
32 | ## Pre-requisites
33 |
34 | Before getting started with Automated Scripts using Selenium with **WD** framework on LambdaTest Automation, you need to:
35 |
36 | * Download and install **NodeJS**. You should be having **NodeJS v6** or newer. Click [here](https://nodejs.org/en/) to download.
37 | * Make sure you are using the latest version of **JavaScript**.
38 | * Install **npm** from the official website by clicking [here](https://www.npmjs.com/).
39 | * 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.
40 |
41 | ### Installing Selenium Dependencies and tutorial repo
42 |
43 | Clone the LambdaTest’s [wd-selenium-sample repository](https://github.com/LambdaTest/wd-selenium-sample) and navigate to the code directory as shown below:
44 | ```bash
45 | git clone https://github.com/LambdaTest/wd-selenium-sample
46 | cd wd-selenium-sample
47 | ```
48 | Install the required project dependencies using the command below:
49 | ```bash
50 | npm i
51 | ```
52 |
53 | ### Setting up Your Authentication
54 |
55 | 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=wd-selenium-sample) or through [LambdaTest Profile](https://accounts.lambdatest.com/login/?utm_source=github&utm_medium=repo&utm_campaign=wd-selenium-sample).
56 |
57 | Set LambdaTest `Username` and `Access Key` in environment variables.
58 | * For **Linux/macOS**:
59 | ```bash
60 | export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY"
61 | ```
62 | * For **Windows**:
63 | ```bash
64 | set LT_USERNAME="YOUR_USERNAME" set LT_ACCESS_KEY="YOUR ACCESS KEY"
65 | ```
66 |
67 | ## Run Your First Test
68 |
69 | ### Sample Test with WD
70 |
71 | **Test Scenario:** This is a simple WD automation script that tests a sample to-do list app. The code marks two list items as done, adds a list item and then finally gives the total number of pending items as output. Check out the [single_test.js](https://github.com/LambdaTest/wd-selenium-sample/blob/master/tests/single_test.js) file to run your first sample test script.
72 |
73 | ### Configuration of Your Test Capabilities
74 |
75 | In `conf/single.conf.js`, 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:
76 | ```js
77 | capabilities: [{
78 | browserName: 'chrome',
79 | platform: 'Windows 10',
80 | version: 'latest',
81 | name: "single-test",
82 | build: "wd-lambdatest-sample",
83 | geoLocation : "US"
84 | }]
85 | ```
86 | > 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=wd-selenium-sample)**.
87 |
88 | ## Executing the Test
89 |
90 | The tests can be executed in the terminal using the following command
91 | ```bash
92 | npm run single
93 | ```
94 | 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=wd-selenium-sample). LambdaTest Automation Dashboard will help you view all your text logs, screenshots and video recording for your entire automation tests.
95 |
96 | ## Running Your Parallel Tests Using WD Framework
97 |
98 | ### Setting up the Parallel Environment
99 | You can go to `conf/parallel.conf.js` file in the repo to configure your parallel test cases:
100 | ```js
101 | user= process.env.LT_USERNAME || "", // Your Username
102 | key= process.env.LT_ACCESS_KEY || "", // Your Access Key
103 |
104 | exports.config = {
105 |
106 | seleniumHost: 'hub.lambdatest.com',
107 | seleniumPort: 80,
108 |
109 | test: '../tests/single_test.js',
110 |
111 | commonCapabilities: {
112 | name: "parallel-test",
113 | build: "wd-lambdatest-sample"
114 | },
115 |
116 | capabilities: [{
117 | browserName: 'chrome',
118 | platform: 'Windows 10',
119 | version: 'latest',
120 | geoLocation : "US"
121 | },{
122 | browserName: 'chrome',
123 | platform: 'Windows 10',
124 | version: 'latest-1',
125 | geoLocation : "US"
126 | },{
127 | browserName: 'chrome',
128 | platform: 'Windows 10',
129 | version: 'latest-2',
130 | geoLocation : "US"
131 | }]
132 | }
133 |
134 | // Code to support common capabilities
135 | exports.config.capabilities.forEach(function(caps){
136 | for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i];
137 | });
138 | ```
139 | ### Executing Parallel Tests with WD
140 |
141 | To run parallel tests using **WD**, we would have to execute the below command in the terminal:
142 | ```bash
143 | npm run parallel
144 | ```
145 | 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=wd-selenium-sample).
146 |
147 | ## Testing Locally Hosted or Privately Hosted Projects
148 |
149 | 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=wd-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.
150 |
151 | >Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information.
152 |
153 | Here’s how you can establish LambdaTest Tunnel.
154 |
155 | >Download the binary file of:
156 | * [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip)
157 | * [LambdaTest Tunnel for Mac](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip)
158 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip)
159 |
160 | Open command prompt and navigate to the binary folder.
161 |
162 | Run the following command:
163 | ```bash
164 | LT -user {user’s login email} -key {user’s access key}
165 | ```
166 | So if your user name is lambdatest@example.com and key is 123456, the command would be:
167 | ```bash
168 | LT -user lambdatest@example.com -key 123456
169 | ```
170 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below :
171 |
172 | **Tunnel Capability**
173 | ```js
174 | const capabilities = {
175 | tunnel: true,
176 | }
177 | ```
178 |
179 | ## Additional Links
180 |
181 | * [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/selenium-automation-capabilities/)
182 | * [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/)
183 | * [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/)
184 |
185 | ## Tutorials 📙
186 |
187 | Check out our latest tutorials on TestNG automation testing 👇
188 |
189 | * [How To Use isDisplayed() In Selenium WebDriver](https://www.lambdatest.com/blog/isdisplayed-in-selenium/?utm_source=github&utm_medium=repo&utm_campaign=wd-selenium-sample)
190 | * [How To Find Element By Text In Selenium WebDriver](https://www.lambdatest.com/blog/how-to-find-element-by-text-in-selenium/?utm_source=github&utm_medium=repo&utm_campaign=wd-selenium-sample)
191 |
192 | ## Documentation & Resources :books:
193 |
194 | 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.
195 |
196 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=wd-selenium-sample)
197 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=wd-selenium-sample)
198 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=wd-selenium-sample)
199 |
200 | ## LambdaTest Community :busts_in_silhouette:
201 |
202 | The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=wd-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 🌎
203 |
204 | ## What's New At LambdaTest ❓
205 |
206 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
207 |
208 | ## About LambdaTest
209 |
210 | [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=wd-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.
211 |
212 | ### Features
213 |
214 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
215 | * Real-time cross browser testing on 3000+ environments.
216 | * Test on Real device cloud
217 | * Blazing fast test automation with HyperExecute
218 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
219 | * Smart Visual Regression Testing on cloud
220 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
221 | * Automated Screenshot testing across multiple browsers in a single click.
222 | * Local testing of web and mobile apps.
223 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
224 | * Geolocation testing of web and mobile apps across 53+ countries.
225 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports
226 |
227 |
228 | [
](https://accounts.lambdatest.com/register)
229 |
230 | ## We are here to help you :headphones:
231 |
232 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=wd-selenium-sample)
233 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=wd-selenium-sample)
234 |
--------------------------------------------------------------------------------
/conf/parallel.conf.js:
--------------------------------------------------------------------------------
1 | user= process.env.LT_USERNAME || "",
2 | key= process.env.LT_ACCESS_KEY || "",
3 |
4 | exports.config = {
5 |
6 | seleniumHost: 'hub.lambdatest.com',
7 | seleniumPort: 80,
8 |
9 | test: '../tests/single_test.js',
10 |
11 | commonCapabilities: {
12 | name: "parallel-test",
13 | build: "wd-lambdatest-sample"
14 | },
15 |
16 | capabilities: [{
17 | browserName: 'chrome',
18 | platform: 'Windows 10',
19 | version: 'latest',
20 | geoLocation : "US"
21 | },{
22 | browserName: 'chrome',
23 | platform: 'Windows 10',
24 | version: 'latest-1',
25 | geoLocation : "US"
26 | },{
27 | browserName: 'chrome',
28 | platform: 'Windows 10',
29 | version: 'latest-2',
30 | geoLocation : "US"
31 | }]
32 | }
33 |
34 | // Code to support common capabilities
35 | exports.config.capabilities.forEach(function(caps){
36 | for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i];
37 | });
38 |
--------------------------------------------------------------------------------
/conf/single.conf.js:
--------------------------------------------------------------------------------
1 | user= process.env.LT_USERNAME || "",
2 | key= process.env.LT_ACCESS_KEY || "",
3 |
4 | exports.config = {
5 |
6 | seleniumHost: 'hub.lambdatest.com',
7 | seleniumPort: 80,
8 |
9 | test: '../tests/single_test.js',
10 |
11 | capabilities: [{
12 | browserName: 'chrome',
13 | platform: 'Windows 10',
14 | version: 'latest',
15 | name: "single-test",
16 | build: "wd-lambdatest-sample",
17 | geoLocation : "US"
18 | }]
19 | }
20 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wd-lambdatest-sample",
3 | "version": "0.1.0",
4 | "readme": "WD Integration with [lambdatest](https://www.lambdatest.com)",
5 | "description": "Selenium examples for WD and lambdatest Automate",
6 | "repository": {
7 | "type": "git",
8 | "url": "git+https://github.com/lambdatest/wd-lambdatest-sample.git"
9 | },
10 | "keywords": [
11 | "wd",
12 | "lambdatest",
13 | "wd-lambdatest-sample",
14 | "webdriver",
15 | "selenium"
16 | ],
17 | "author": "lambdatest",
18 | "bugs": {
19 | "url": "https://github.com/lambdatest/wd-lambdatest-sample/issues"
20 | },
21 | "homepage": "https://github.com/lambdatest/wd-lambdatest-sample#readme",
22 | "scripts": {
23 | "test": "npm run single && npm run parallel",
24 | "single": "node scripts/lambdatest.js ../conf/single.conf.js",
25 | "parallel": "node scripts/lambdatest.js ../conf/parallel.conf.js"
26 | },
27 | "dependencies": {
28 | "chai": "^3.5.0",
29 | "chai-as-promised": "^5.2.0",
30 | "colors": "^1.1.2",
31 | "wd": "^1.11.1"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/scripts/lambdatest.js:
--------------------------------------------------------------------------------
1 | var chai = require("chai"),
2 | chaiAsPromised = require("chai-as-promised"),
3 | wd = require('wd'),
4 | colors = require('colors'),
5 | child_process = require('child_process')
6 |
7 | chai.use(chaiAsPromised);
8 | chai.should();
9 | chaiAsPromised.transferPromiseness = wd.transferPromiseness;
10 |
11 | wd.addPromiseChainMethod(
12 | 'onQuit', function (done) {
13 | if (done) done();
14 | return this;
15 | }
16 | );
17 |
18 | async function runOnlambdatest(caps, test, done) {
19 | console.log("Starting Test: " + test.name.green + '\n');
20 | var browser = wd.promiseChainRemote(config.seleniumHost, config.seleniumPort, username, accessKey);
21 |
22 | // optional extra logging
23 | browser.on('status', function (info) {
24 | console.log(info.cyan);
25 | });
26 | browser.on('command', function (eventType, command, response) {
27 | console.log(' > ' + eventType.green, command, (response || '').grey);
28 | });
29 | browser.on('http', function (meth, path, data) {
30 | console.log(' > ' + meth.yellow, path, (data || '').grey);
31 | });
32 |
33 | await test.run(browser.init(caps))
34 | return browser.quit();
35 | }
36 |
37 | var config_file = process.argv[2] || 'conf.js'
38 | var config = require(config_file).config;
39 | var test = require(config.test);
40 |
41 | var username = process.env.LT_USERNAME || config.user;
42 | var accessKey = process.env.LT_ACCESS_KEY || config.key;
43 |
44 | for (var i in config.capabilities) {
45 | var caps = config.capabilities[i];
46 | if (caps["tunnel"]) {
47 | //start tunnel
48 | }
49 | else {
50 | runOnlambdatest(caps, test);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/tests/single_test.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name: 'Wd-selenium-sample Todo Test',
3 | run : async function (browser) {
4 | await browser.get("https://lambdatest.github.io/sample-todo-app/")
5 | let li1 = await browser.elementByName('li1')
6 | await browser.clickElement(li1)
7 | console.log("Successfully clicked first list item.")
8 | let li2 = await browser.elementByName('li2')
9 | await browser.clickElement(li2)
10 | console.log("Successfully clicked second list item.");
11 | let textElem = await browser.elementById('sampletodotext')
12 | await textElem.sendKeys('Complete Lambdatest Tutorial\n')
13 | console.log("Successfully added a new task.")
14 | }
15 | };
--------------------------------------------------------------------------------