Skip to content

Commit 33c4c63

Browse files
authored
Merge pull request #3 from Devansh013/patch-1
Updated Cucumber Selenium README File
2 parents 48ccc29 + db2d60d commit 33c4c63

1 file changed

Lines changed: 264 additions & 41 deletions

File tree

README.md

Lines changed: 264 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,305 @@
1-
# NodeJs-Cucumber-Selenium-Sample
1+
# Run Selenium Tests With Cucumber for BDD On LambdaTest
22

3-
Node.js is an efficient, light weight and cross platform runtime environment for executing JavaScript code. npm(node package manager) is the largest ecosystem of open source libraries. LambdaTest enables node.js scripts to run on the Selenium automation grid. This tutorial will help you run Nodejs automation scripts over LambdaTest Selenium Grid.
3+
![JavaScript](https://user-images.githubusercontent.com/95698164/172134732-2e9c780e-10ac-4956-b366-86ffc25bf070.png)
44

5-
## Prerequisites
5+
<p align="center">
6+
<a href="https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium" target="_bank">Blog</a>
7+
&nbsp; &#8901; &nbsp;
8+
<a href="https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium" target="_bank">Docs</a>
9+
&nbsp; &#8901; &nbsp;
10+
<a href="https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium" target="_bank">Learning Hub</a>
11+
&nbsp; &#8901; &nbsp;
12+
<a href="https://www.lambdatest.com/newsletter/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium" target="_bank">Newsletter</a>
13+
&nbsp; &#8901; &nbsp;
14+
<a href="https://www.lambdatest.com/certifications/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium" target="_bank">Certifications</a>
15+
&nbsp; &#8901; &nbsp;
16+
<a href="https://www.youtube.com/c/LambdaTest" target="_bank">YouTube</a>
17+
</p>
18+
&emsp;
19+
&emsp;
20+
&emsp;
621

7-
1. Install npm.
22+
*Learn how to use Cucumber for BDD framework to configure and run your JavaScript automation testing scripts on the LambdaTest platform*
823

9-
```
10-
sudo apt install npm
11-
```
24+
[<img height="58" width="200" src="https://user-images.githubusercontent.com/70570645/171866795-52c11b49-0728-4229-b073-4b704209ddde.png">](https://accounts.lambdatest.com/register)
1225

13-
2. Install NodeJS.
26+
## Table Of Contents
1427

15-
```
16-
sudo apt install nodejs
17-
```
28+
* [Pre-requisites](#pre-requisites)
29+
* [Run Your First Test](#run-your-first-test)
30+
* [Running Your Parallel Tests Using Cucumber Framework](#running-your-parallel-tests-using-cucumber-framework)
31+
* [Testing Locally Hosted or Privatley Hosted Projects](#testing-locally-hosted-or-privately-hosted-projects)
32+
33+
## Pre-requisites
1834

19-
## Steps to Run your First Test
35+
Before getting started with Selenium automation testing on LambdaTest, you need to:
2036

21-
Step 1. Clone the NodeJs Cucumber Selenium Repository.
37+
* Download and install **NodeJS**. You should be having **NodeJS v6** or newer. Click [here](https://nodejs.org/en/) to download.
38+
* Make sure you are using the latest version of **JavaScript**.
39+
* Install **npm** from the official website by clicking [here](https://www.npmjs.com/).
40+
* 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.
2241

42+
### Installing Selenium Dependencies and tutorial repo
43+
44+
Clone the LambdaTest’s [NodeJs-Cucumber-Selenium repository](https://github.com/LambdaTest/NodeJs-Cucumber-Selenium) and navigate to the code directory as shown below:
45+
```bash
46+
git clone https://github.com/LambdaTest/NodeJs-Cucumber-Selenium
47+
cd NodeJs-Cucumber-Selenium
2348
```
24-
git clone https://github.com/LambdaTest/NodeJs-Cucumber-Selenium.git
49+
Install the required project dependencies using the command below:
50+
```bash
51+
npm install
2552
```
2653

27-
Step 2. Export the Lambda-test Credentials. You can get these from your automation dashboard.
54+
### Setting up Your Authentication
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) or through [LambdaTest Profile](https://accounts.lambdatest.com/login).
2856

29-
<p align="center">
30-
<b>For Linux/macOS:</b>:
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 CucumberJS
70+
The example mentioned below would help you to execute your **Cucumber JS** Testing automation testing-
71+
```bash
72+
//nodejs-cucumber-todo/features/todo.feature
73+
Feature: Automate a website
74+
Scenario: perform click events
75+
When visit url "https://lambdatest.github.io/sample-todo-app"
76+
When field with name "First Item" is present check the box
77+
When field with name "Second Item" is present check the box
78+
When select the textbox add "Let's add new to do item" in the box
79+
Then click the "addbutton"
80+
Then I must see title "Sample page - lambdatest.com"
81+
```
82+
Now create `step definition` file.
83+
```js
84+
//nodejs-cucumber-todo/features/step_definitions/todo.js
85+
/*
86+
This file contains the code which automate the sample app.
87+
It reads instructions form feature file and find matching
88+
case and execute it.
89+
*/
90+
91+
92+
'use strict';
93+
94+
const assert = require('cucumber-assert');
95+
const webdriver = require('selenium-webdriver');
3196

97+
module.exports = function() {
98+
99+
this.When(/^visit url "([^"]*)"$/, function (url, next) {
100+
this.driver.get('https://lambdatest.github.io/sample-todo-app').then(next);
101+
});
102+
103+
this.When(/^field with name "First Item" is present check the box$/, function (next) {
104+
this.driver.findElement({ name: 'li1' })
105+
.click().then(next);
106+
});
107+
108+
this.When(/^field with name "Second Item" is present check the box$/, function (next) {
109+
this.driver.findElement({ name: 'li3' })
110+
.click().then(next);
111+
});
112+
113+
this.When(/^select the textbox add "([^"]*)" in the box$/, function (text, next) {
114+
this.driver.findElement({ id: 'sampletodotext' }).click();
115+
this.driver.findElement({ id: 'sampletodotext' }).sendKeys(text).then(next);
116+
});
117+
118+
this.Then(/^click the "([^"]*)"$/, function (button, next) {
119+
this.driver.findElement({ id: button }).click().then(next);
120+
});
121+
122+
this.Then(/^I must see title "([^"]*)"$/, function (titleMatch, next) {
123+
this.driver.getTitle()
124+
.then(function(title) {
125+
assert.equal(title, titleMatch, next, 'Expected title to be ' + titleMatch);
126+
});
127+
});
128+
};
32129
```
33-
export LT_USERNAME="YOUR_USERNAME"
34-
export LT_ACCESS_KEY="YOUR ACCESS KEY"
130+
Now create `cucumber js` framework `runner` file.
131+
```js
132+
//nodejs-cucumber-todo/scripts/cucumber-runner.js
133+
#!/usr/bin/env node
134+
/*
135+
This is parallel test runner file.
136+
It creates child processes equals the number of
137+
test environments passed.
138+
*/
139+
let child_process = require('child_process');
140+
let config_file = '../conf/' + (process.env.CONFIG_FILE || 'single') + '.conf.js';
141+
let config = require(config_file).config;
142+
143+
process.argv[0] = 'node';
144+
process.argv[1] = './node_modules/.bin/cucumber-js';
145+
146+
const getValidJson = function(jenkinsInput) {
147+
let json = jenkinsInput;
148+
json = json.replace(/\\n/g, "");
149+
json = json.replace('\\/g', '');
150+
return json;
151+
};
152+
153+
let lt_browsers = null;
154+
if(process.env.LT_BROWSERS) {
155+
let jsonInput = getValidJson(process.env.LT_BROWSERS);
156+
lt_browsers = JSON.parse(jsonInput);
157+
}
158+
159+
for( let i in (lt_browsers || config.capabilities) ){
160+
let env = Object.create( process.env );
161+
env.TASK_ID = i.toString();
162+
let p = child_process.spawn('/usr/bin/env', process.argv, { env: env } );
163+
p.stdout.pipe(process.stdout);
164+
}
35165
```
36-
<p align="center">
37-
<b>For Windows:</b>
38166
167+
### Configuration of Your Test Capabilities
168+
In `conf/single.conf.js` file, 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:
169+
```js
170+
capabilities: [{
171+
browserName: 'chrome',
172+
platform: 'Windows 10',
173+
version: 'latest',
174+
name: "cucumber-js-single-test",
175+
build: "cucumber-js-LambdaTest-single"
176+
}]
39177
```
40-
set LT_USERNAME="YOUR_USERNAME"
41-
set LT_ACCESS_KEY="YOUR ACCESS KEY"
42-
```
178+
> You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/)**.
43179
44-
Step 3. Inside Nodejs.Ccumber.Selenium repository install necessary packages.
180+
### Executing the Test
45181
182+
The tests can be executed in the terminal using the following command
183+
```bash
184+
npm run single
46185
```
47-
cd NodeJs-Cucumber-Selenium
48-
npm i
49-
```
186+
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). LambdaTest Automation Dashboard will help you view all your text logs, screenshots and video recording for your entire automation tests.
50187
51-
Step 4. To run your First Test.
188+
## Running Your Parallel Tests Using Cucumber Framework
52189
190+
### Executing Parallel Tests with Cucumber
191+
192+
To run parallel tests using **CucumberJS**, we would have to execute the below command in the terminal:
193+
```bash
194+
npm run parallel
53195
```
54-
npm run single
55-
```
196+
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).
197+
198+
## Testing Locally Hosted or Privately Hosted Projects
199+
200+
You can test your locally hosted or privately hosted projects with [LambdaTest Selenium grid cloud](https://www.lambdatest.com/selenium-automation) 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.
56201
57-
Step 5. To run parallel Test.
202+
>Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information.
58203
204+
Here’s how you can establish LambdaTest Tunnel.
205+
206+
>Download the binary file of:
207+
* [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip)
208+
* [LambdaTest Tunnel for Mac](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip)
209+
* [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip)
210+
211+
Open command prompt and navigate to the binary folder.
212+
213+
Run the following command:
214+
```bash
215+
LT -user {user’s login email} -key {user’s access key}
59216
```
60-
npm run parallel
217+
So if your user name is lambdatest@example.com and key is 123456, the command would be:
218+
```bash
219+
LT -user lambdatest@example.com -key 123456
61220
```
221+
Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below :
62222
63-
Step 6. To run your test locally.
64-
223+
**Tunnel Capability**
224+
```js
225+
const capabilities = {
226+
tunnel: true,
227+
}
65228
```
229+
### Executing the local tests
230+
To run local tests using **CucumberJS**, we would have to execute the below command in the terminal:
231+
```bash
66232
npm run local
67233
```
68234
69-
Step 7. Or, you can run all three test.
235+
## Executing all the tests
236+
To run all the tests at once using **CucumberJS**, we would have to execute the below command in the terminal:
70237
71-
```
238+
```bash
72239
npm run test
73240
```
74241
75-
## See the Results
242+
>If you wish to set up your CucumberJS testing through Jenkins, then refer to our [Jenkins documentation](https://www.lambdatest.com/support/docs/jenkins-with-lambdatest/).
243+
76244
77-
You can check your test results on the [Automation Dashboard](https://automation.lambdatest.com/build).
78-
![Automation Testing Logs](https://github.com/LambdaTest/NodeJs-Cucumber-Selenium/dashboard.png)
245+
## Additional Links
79246
247+
* [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/selenium-automation-capabilities/)
248+
* [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/)
249+
* [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/)
250+
251+
## Tutorials 📙
252+
253+
Check out our latest tutorials on TestNG automation testing 👇
254+
255+
* [How To Perform Automation Testing With Cucumber And Nightwatch JS?](https://www.lambdatest.com/blog/automation-testing-with-cucumber-and-nightwatchjs/#Cucumberjs)
256+
* [Configure Cucumber Setup In Eclipse And IntelliJ [Tutorial]](https://www.lambdatest.com/blog/configure-cucumber-setup-in-eclipse-and-intellij/)
257+
* [Cucumber.js Tutorial with Examples For Selenium JavaScript](https://www.lambdatest.com/blog/cucumberjs-tutorial-selenium/)
258+
* [How To Use Annotations In Cucumber Framework [Tutorial]](https://www.lambdatest.com/blog/cucumber-annotations-hooks-tutorial/)
259+
* [How To Perform Automation Testing With Cucumber And Nightwatch JS?](https://www.lambdatest.com/blog/automation-testing-with-cucumber-and-nightwatchjs/)
260+
* [Automation Testing With Selenium, Cucumber & TestNG](https://www.lambdatest.com/blog/automation-testing-with-selenium-cucumber-testng/)
261+
* [How To Integrate Cucumber With Jenkins?](https://www.lambdatest.com/blog/cucumber-with-jenkins-integration/)
262+
* [Top 5 Cucumber Best Practices For Selenium Automation](https://www.lambdatest.com/blog/cucumber-best-practices/)
263+
264+
## Documentation & Resources :books:
265+
266+
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.
267+
268+
* [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium)
269+
* [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium)
270+
* [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium)
271+
272+
## LambdaTest Community :busts_in_silhouette:
273+
274+
The [LambdaTest Community](https://community.lambdatest.com/) 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 🌎
275+
276+
## What's New At LambdaTest ❓
277+
278+
To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
279+
80280
## About LambdaTest
81281
82-
[LambdaTest](https://www.lambdatest.com/) is a cloud based Selenium Grid Infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [Selenium test automation](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel.
282+
[LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 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.
283+
284+
### Features
285+
286+
* Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
287+
* Real-time cross browser testing on 3000+ environments.
288+
* Test on Real device cloud
289+
* Blazing fast test automation with HyperExecute
290+
* Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
291+
* Smart Visual Regression Testing on cloud
292+
* 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
293+
* Automated Screenshot testing across multiple browsers in a single click.
294+
* Local testing of web and mobile apps.
295+
* Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
296+
* Geolocation testing of web and mobile apps across 53+ countries.
297+
* LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports
298+
299+
300+
[<img height="58" width="200" src="https://user-images.githubusercontent.com/70570645/171866795-52c11b49-0728-4229-b073-4b704209ddde.png">](https://accounts.lambdatest.com/register)
301+
302+
## We are here to help you :headphones:
303+
304+
* Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com)
305+
* For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium)

0 commit comments

Comments
 (0)