├── .gitignore ├── .gitpod.yml ├── .lambdatest ├── ltcomponent └── ltcomponent.zip ├── README.md ├── conf ├── local.conf.js ├── parallel.conf.js ├── parallelJenkins.conf.js ├── single.conf.js └── singleJenkins.conf.js ├── dashboard.png ├── features ├── local.feature ├── single.feature ├── step_definitions │ ├── localApp.js │ └── todo-list.js └── support │ ├── env.js │ └── hooks.js ├── package.json └── scripts └── cucumber-runner.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.DS_Store 3 | *.log 4 | .vscode/ 5 | 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 # runs during prebuild 5 | command: npm run single 6 | -------------------------------------------------------------------------------- /.lambdatest/ltcomponent: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LambdaTest/NodeJs-Cucumber-Selenium/6fa0d12c03accb017e34d6715464c7e848d8f89e/.lambdatest/ltcomponent -------------------------------------------------------------------------------- /.lambdatest/ltcomponent.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LambdaTest/NodeJs-Cucumber-Selenium/6fa0d12c03accb017e34d6715464c7e848d8f89e/.lambdatest/ltcomponent.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Run Selenium Tests With Cucumber for BDD On LambdaTest 2 | 3 | ![JavaScript](https://user-images.githubusercontent.com/95698164/172134732-2e9c780e-10ac-4956-b366-86ffc25bf070.png) 4 | 5 |

6 | Blog 7 |   ⋅   8 | Docs 9 |   ⋅   10 | Learning Hub 11 |   ⋅   12 | Newsletter 13 |   ⋅   14 | Certifications 15 |   ⋅   16 | YouTube 17 |

18 |   19 |   20 |   21 | 22 | *Learn how to use Cucumber for BDD framework to configure and run your JavaScript automation testing scripts on the LambdaTest platform* 23 | 24 | [](https://accounts.lambdatest.com/register) 25 | 26 | ## Table Of Contents 27 | 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 34 | 35 | Before getting started with Selenium automation testing on LambdaTest, you need to: 36 | 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. 41 | 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 48 | ``` 49 | Install the required project dependencies using the command below: 50 | ```bash 51 | npm install 52 | ``` 53 | 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/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) or through [LambdaTest Profile](https://accounts.lambdatest.com/login/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium). 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 | $env:LT_USERNAME='YOUR USERNAME' 65 | $env:LT_ACCESS_KEY='YOUR ACCESS KEY' 66 | ``` 67 | 68 | ## Run Your First Test 69 | 70 | ### Sample Test with CucumberJS 71 | The example mentioned below would help you to execute your **Cucumber JS** Testing automation testing- 72 | ```bash 73 | //nodejs-cucumber-todo/features/todo.feature 74 | Feature: Automate a website 75 | Scenario: perform click events 76 | When visit url "https://lambdatest.github.io/sample-todo-app" 77 | When field with name "First Item" is present check the box 78 | When field with name "Second Item" is present check the box 79 | When select the textbox add "Let's add new to do item" in the box 80 | Then click the "addbutton" 81 | Then I must see title "Sample page - lambdatest.com" 82 | ``` 83 | Now create `step definition` file. 84 | ```js 85 | //nodejs-cucumber-todo/features/step_definitions/todo.js 86 | /* 87 | This file contains the code which automate the sample app. 88 | It reads instructions form feature file and find matching 89 | case and execute it. 90 | */ 91 | 92 | 93 | 'use strict'; 94 | 95 | const assert = require('cucumber-assert'); 96 | const webdriver = require('selenium-webdriver'); 97 | 98 | module.exports = function() { 99 | 100 | this.When(/^visit url "([^"]*)"$/, function (url, next) { 101 | this.driver.get('https://lambdatest.github.io/sample-todo-app').then(next); 102 | }); 103 | 104 | this.When(/^field with name "First Item" is present check the box$/, function (next) { 105 | this.driver.findElement({ name: 'li1' }) 106 | .click().then(next); 107 | }); 108 | 109 | this.When(/^field with name "Second Item" is present check the box$/, function (next) { 110 | this.driver.findElement({ name: 'li3' }) 111 | .click().then(next); 112 | }); 113 | 114 | this.When(/^select the textbox add "([^"]*)" in the box$/, function (text, next) { 115 | this.driver.findElement({ id: 'sampletodotext' }).click(); 116 | this.driver.findElement({ id: 'sampletodotext' }).sendKeys(text).then(next); 117 | }); 118 | 119 | this.Then(/^click the "([^"]*)"$/, function (button, next) { 120 | this.driver.findElement({ id: button }).click().then(next); 121 | }); 122 | 123 | this.Then(/^I must see title "([^"]*)"$/, function (titleMatch, next) { 124 | this.driver.getTitle() 125 | .then(function(title) { 126 | assert.equal(title, titleMatch, next, 'Expected title to be ' + titleMatch); 127 | }); 128 | }); 129 | }; 130 | ``` 131 | Now create `cucumber js` framework `runner` file. 132 | ```js 133 | //nodejs-cucumber-todo/scripts/cucumber-runner.js 134 | #!/usr/bin/env node 135 | /* 136 | This is parallel test runner file. 137 | It creates child processes equals the number of 138 | test environments passed. 139 | */ 140 | let child_process = require('child_process'); 141 | let config_file = '../conf/' + (process.env.CONFIG_FILE || 'single') + '.conf.js'; 142 | let config = require(config_file).config; 143 | 144 | process.argv[0] = 'node'; 145 | process.argv[1] = './node_modules/.bin/cucumber-js'; 146 | 147 | const getValidJson = function(jenkinsInput) { 148 | let json = jenkinsInput; 149 | json = json.replace(/\\n/g, ""); 150 | json = json.replace('\\/g', ''); 151 | return json; 152 | }; 153 | 154 | let lt_browsers = null; 155 | if(process.env.LT_BROWSERS) { 156 | let jsonInput = getValidJson(process.env.LT_BROWSERS); 157 | lt_browsers = JSON.parse(jsonInput); 158 | } 159 | 160 | for( let i in (lt_browsers || config.capabilities) ){ 161 | let env = Object.create( process.env ); 162 | env.TASK_ID = i.toString(); 163 | let p = child_process.spawn('/usr/bin/env', process.argv, { env: env } ); 164 | p.stdout.pipe(process.stdout); 165 | } 166 | ``` 167 | 168 | ### Configuration of Your Test Capabilities 169 | 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: 170 | ```js 171 | capabilities: [{ 172 | browserName: 'chrome', 173 | platform: 'Windows 10', 174 | version: 'latest', 175 | name: "cucumber-js-single-test", 176 | build: "cucumber-js-LambdaTest-single" 177 | }] 178 | ``` 179 | > 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-Cucumber-Selenium)**. 180 | 181 | ### Executing the Test 182 | 183 | The tests can be executed in the terminal using the following command 184 | ```bash 185 | npm run single 186 | ``` 187 | 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-Cucumber-Selenium). LambdaTest Automation Dashboard will help you view all your text logs, screenshots and video recording for your entire automation tests. 188 | 189 | ## Running Your Parallel Tests Using Cucumber Framework 190 | 191 | ### Executing Parallel Tests with Cucumber 192 | 193 | To run parallel tests using **CucumberJS**, we would have to execute the below command in the terminal: 194 | ```bash 195 | npm run parallel 196 | ``` 197 | 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-Cucumber-Selenium). 198 | 199 | ## Testing Locally Hosted or Privately Hosted Projects 200 | 201 | 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-Cucumber-Selenium) 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. 202 | 203 | >Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information. 204 | 205 | Here’s how you can establish LambdaTest Tunnel. 206 | 207 | >Download the binary file of: 208 | * [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip) 209 | * [LambdaTest Tunnel for Mac](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip) 210 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip) 211 | 212 | Open command prompt and navigate to the binary folder. 213 | 214 | Run the following command: 215 | ```bash 216 | LT -user {user’s login email} -key {user’s access key} 217 | ``` 218 | So if your user name is lambdatest@example.com and key is 123456, the command would be: 219 | ```bash 220 | LT -user lambdatest@example.com -key 123456 221 | ``` 222 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below : 223 | 224 | **Tunnel Capability** 225 | ```js 226 | const capabilities = { 227 | tunnel: true, 228 | } 229 | ``` 230 | ### Executing the local tests 231 | To run local tests using **CucumberJS**, we would have to execute the below command in the terminal: 232 | ```bash 233 | npm run local 234 | ``` 235 | 236 | ## Executing all the tests 237 | To run all the tests at once using **CucumberJS**, we would have to execute the below command in the terminal: 238 | 239 | ```bash 240 | npm run test 241 | ``` 242 | 243 | >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/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium). 244 | 245 | 246 | ## Additional Links 247 | 248 | * [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/selenium-automation-capabilities/) 249 | * [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) 250 | * [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/) 251 | 252 | ## Tutorials 📙 253 | 254 | Check out our latest tutorials on TestNG automation testing 👇 255 | 256 | * [How To Perform Automation Testing With Cucumber And Nightwatch JS?](https://www.lambdatest.com/blog/automation-testing-with-cucumber-and-nightwatchjs/#Cucumberjs/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 257 | * [Configure Cucumber Setup In Eclipse And IntelliJ [Tutorial]](https://www.lambdatest.com/blog/configure-cucumber-setup-in-eclipse-and-intellij/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 258 | * [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-Cucumber-Selenium) 259 | * [How To Use Annotations In Cucumber Framework [Tutorial]](https://www.lambdatest.com/blog/cucumber-annotations-hooks-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 260 | * [How To Perform Automation Testing With Cucumber And Nightwatch JS?](https://www.lambdatest.com/blog/automation-testing-with-cucumber-and-nightwatchjs/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 261 | * [Automation Testing With Selenium, Cucumber & TestNG](https://www.lambdatest.com/blog/automation-testing-with-selenium-cucumber-testng/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 262 | * [How To Integrate Cucumber With Jenkins?](https://www.lambdatest.com/blog/cucumber-with-jenkins-integration/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 263 | * [Top 5 Cucumber Best Practices For Selenium Automation](https://www.lambdatest.com/blog/cucumber-best-practices/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 264 | 265 | ## Documentation & Resources :books: 266 | 267 | 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. 268 | 269 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 270 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 271 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 272 | 273 | ## LambdaTest Community :busts_in_silhouette: 274 | 275 | The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 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 🌎 276 | 277 | ## What's New At LambdaTest ❓ 278 | 279 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) 280 | 281 | ## About LambdaTest 282 | 283 | [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. 284 | 285 | ### Features 286 | 287 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. 288 | * Real-time cross browser testing on 3000+ environments. 289 | * Test on Real device cloud 290 | * Blazing fast test automation with HyperExecute 291 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. 292 | * Smart Visual Regression Testing on cloud 293 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. 294 | * Automated Screenshot testing across multiple browsers in a single click. 295 | * Local testing of web and mobile apps. 296 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. 297 | * Geolocation testing of web and mobile apps across 53+ countries. 298 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports 299 | 300 | 301 | [](https://accounts.lambdatest.com/register) 302 | 303 | ## We are here to help you :headphones: 304 | 305 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 306 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=NodeJs-Cucumber-Selenium) 307 | -------------------------------------------------------------------------------- /conf/local.conf.js: -------------------------------------------------------------------------------- 1 | exports.config = { 2 | user: process.env.LT_USERNAME || '', 3 | key: process.env.LT_ACCESS_KEY || '', 4 | server: 'hub.lambdatest.com', 5 | 6 | capabilities: [{ 7 | browserName: 'chrome', 8 | platform: 'Windows 10', 9 | version: 'latest', 10 | name: "cucumebrjs-local-test", 11 | build: "cucumber-js-LambdaTest", 12 | tunnel: 'true', 13 | }] 14 | } 15 | -------------------------------------------------------------------------------- /conf/parallel.conf.js: -------------------------------------------------------------------------------- 1 | exports.config = { 2 | user: process.env.LT_USERNAME || '', 3 | key: process.env.LT_ACCESS_KEY || '', 4 | server: 'hub.lambdatest.com', 5 | 6 | commonCapabilities: { 7 | name: "cucumber-js-LambdaTest-parallel-tests", 8 | build: "cucumber-js-LambdaTest-parallel", 9 | }, 10 | 11 | capabilities: [{ 12 | browserName: 'chrome', 13 | platform: 'Windows 10', 14 | version: 'latest' 15 | },{ 16 | browserName: 'firefox', 17 | platform: 'Windows 10', 18 | version: 'latest' 19 | },{ 20 | browserName: 'safari', 21 | platform: 'macOS 10.14', 22 | version: 'latest' 23 | },{ 24 | browserName: 'internet explorer', 25 | platform: 'Windows 10', 26 | version: 'latest' 27 | }] 28 | } 29 | 30 | // Code to support common capabilities 31 | exports.config.capabilities.forEach(function(caps){ 32 | for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i]; 33 | }); 34 | 35 | -------------------------------------------------------------------------------- /conf/parallelJenkins.conf.js: -------------------------------------------------------------------------------- 1 | let myStr = process.env.LT_BROWSERS; 2 | myStr = myStr.replace(/operatingSystem/g, 'platform'); 3 | myStr = myStr.replace(/browserVersion/g, 'version'); 4 | myStr = myStr.replace(/resolution/g, 'screen_resolution'); 5 | console.log(myStr); 6 | 7 | const fs = require('fs'); 8 | let jsonData = JSON.parse(myStr); 9 | 10 | exports.config = { 11 | user: process.env.LT_USERNAME || '', 12 | key: process.env.LT_ACCESS_KEY || '', 13 | server: 'hub.lambdatest.com', 14 | 15 | commonCapabilities: { 16 | name: "parallel_cucumber-js-LambdaTest-parallel-tests", 17 | build: "cucumber-js-LambdaTest-parallel", 18 | }, 19 | 20 | capabilities: jsonData, 21 | } 22 | 23 | // Code to support common capabilities 24 | exports.config.capabilities.forEach(function(caps){ 25 | for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i]; 26 | }); 27 | 28 | -------------------------------------------------------------------------------- /conf/single.conf.js: -------------------------------------------------------------------------------- 1 | exports.config = { 2 | user: process.env.LT_USERNAME || '', 3 | key: process.env.LT_ACCESS_KEY || '', 4 | server: 'hub.lambdatest.com', 5 | 6 | capabilities: [{ 7 | browserName: 'chrome', 8 | platform: 'Windows 10', 9 | version: 'latest', 10 | name: "cucumber-js-single-test", 11 | build: "cucumber-js-LambdaTest-single" 12 | }] 13 | } 14 | -------------------------------------------------------------------------------- /conf/singleJenkins.conf.js: -------------------------------------------------------------------------------- 1 | exports.config = { 2 | user: process.env.LT_USERNAME || '', 3 | key: process.env.LT_ACCESS_KEY || '', 4 | server: 'hub.lambdatest.com', 5 | 6 | capabilities: [{ 7 | browserName: process.env.LT_BROWSER_NAME, 8 | platform: process.env.LT_PLATFORM, 9 | version: process.env.LT_BROWSER_VERSION, 10 | name: "cucumber-js-single-test", 11 | build: "cucumber-js-LambdaTest-single" 12 | }] 13 | } 14 | -------------------------------------------------------------------------------- /dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LambdaTest/NodeJs-Cucumber-Selenium/6fa0d12c03accb017e34d6715464c7e848d8f89e/dashboard.png -------------------------------------------------------------------------------- /features/local.feature: -------------------------------------------------------------------------------- 1 | Feature: Add to Todo list functionality on local app 2 | 3 | Scenario: Add Todo List on local app 4 | When I click on first item on local app 5 | When I click on second item on local app 6 | When I add new item "New item to the list" on local app 7 | Then I should see new item in list "New item to the list" on local app 8 | -------------------------------------------------------------------------------- /features/single.feature: -------------------------------------------------------------------------------- 1 | Feature: Add to Todo list functionality 2 | 3 | Scenario: Add Todo List 4 | When I click on first item 5 | When I click on second item 6 | When I add new item "New item to the list" 7 | Then I should see new item in list "New item to the list" 8 | -------------------------------------------------------------------------------- /features/step_definitions/localApp.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var assert = require("cucumber-assert"); 4 | 5 | module.exports = function() { 6 | this.When(/^I click on first item on local app$/, function(next) { 7 | this.driver.get("https://lambdatest.github.io/sample-todo-app/"); 8 | this.driver 9 | .findElement({ name: "li1" }) 10 | .click() 11 | .then(next); 12 | }); 13 | 14 | this.When(/^I click on second item on local app$/, function(next) { 15 | this.driver 16 | .findElement({ name: "li2" }) 17 | .click() 18 | .then(next); 19 | }); 20 | 21 | this.When(/^I add new item "([^"]*)" on local app$/, function( 22 | newItemName, 23 | next 24 | ) { 25 | var self = this; 26 | this.driver 27 | .findElement({ id: "sampletodotext" }) 28 | .sendKeys(newItemName + "\n") 29 | .then(next); 30 | this.driver 31 | .findElement({ id: "addbutton" }) 32 | .click() 33 | .then(next); 34 | }); 35 | 36 | this.Then(/^I should see new item in list "([^"]*)" on local app$/, function( 37 | item, 38 | next 39 | ) { 40 | var self = this; 41 | this.driver 42 | .findElement({ xpath: "//html/body/div/div/div/ul/li[6]/span" }) 43 | .getText() 44 | .then(function(text) { 45 | console.log(text); 46 | assert.equal(text, item, next, "Expected title to be " + item); 47 | }); 48 | }); 49 | }; 50 | -------------------------------------------------------------------------------- /features/step_definitions/todo-list.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var assert = require("cucumber-assert"); 4 | module.exports = function() { 5 | this.When(/^I click on first item$/, function(next) { 6 | this.driver.get("https://lambdatest.github.io/sample-todo-app/"); 7 | this.driver 8 | .findElement({ name: "li1" }) 9 | .click() 10 | .then(next); 11 | }); 12 | 13 | this.When(/^I click on second item$/, function(next) { 14 | this.driver 15 | .findElement({ name: "li2" }) 16 | .click() 17 | .then(next); 18 | }); 19 | 20 | this.When(/^I add new item "([^"]*)"$/, function(newItemName, next) { 21 | var self = this; 22 | this.driver 23 | .findElement({ id: "sampletodotext" }) 24 | .sendKeys(newItemName + "\n") 25 | this.driver 26 | .findElement({ id: "addbutton" }) 27 | .click() 28 | .then(next); 29 | }); 30 | 31 | this.Then(/^I should see new item in list "([^"]*)"$/, function(item, next) { 32 | var self = this; 33 | this.driver 34 | .findElement({ xpath: "//html/body/div/div/div/ul/li[6]/span" }) 35 | .getText() 36 | .then(function(text) { 37 | console.log(text); 38 | assert.equal(text, item, next, "Expected title to be " + item); 39 | }); 40 | }); 41 | }; 42 | -------------------------------------------------------------------------------- /features/support/env.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var configure = function() { 4 | this.setDefaultTimeout(60 * 1000); 5 | }; 6 | 7 | module.exports = configure; 8 | -------------------------------------------------------------------------------- /features/support/hooks.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const webdriver = require("selenium-webdriver"); 4 | const lambdaTunnel = require("@lambdatest/node-tunnel"); 5 | 6 | const config_file = 7 | "../../conf/" + (process.env.CONFIG_FILE || "single") + ".conf.js"; 8 | const config = require(config_file).config; 9 | const tunnelArguments = { user: config.user, key: config.key }; 10 | 11 | const myTunnel = new lambdaTunnel(); 12 | 13 | var createLambdaTestSession = function(config, caps) { 14 | console.log( 15 | "https://" + 16 | config.user + 17 | ":" + 18 | config.key + 19 | "@" + 20 | config.server + 21 | "/wd/hub" 22 | ); 23 | return new webdriver.Builder() 24 | .usingServer( 25 | "https://" + 26 | config.user + 27 | ":" + 28 | config.key + 29 | "@" + 30 | config.server + 31 | "/wd/hub" 32 | ) 33 | .withCapabilities(caps) 34 | .build(); 35 | }; 36 | 37 | var myHooks = function() { 38 | this.Before(function(scenario, callback) { 39 | var world = this; 40 | var task_id = parseInt(process.env.TASK_ID || 0); 41 | var caps = config.capabilities[task_id]; 42 | 43 | if (caps["tunnel"]) { 44 | // Code to start LambdaTest Tunnel before start of test and stop LambdaTest Tunnel after end of test 45 | 46 | myTunnel.start(tunnelArguments, function(e, status) { 47 | if (e) return console.log(e); 48 | console.log("Started Tunnel " + status); 49 | console.log( 50 | "TUNNELLLLL" + caps["tunnel"] + caps["browserName"] + caps["build"] 51 | ); 52 | world.driver = createLambdaTestSession(config, caps); 53 | callback(); 54 | }); 55 | } else { 56 | world.driver = createLambdaTestSession(config, caps); 57 | callback(); 58 | } 59 | }); 60 | 61 | console.log("TUNNEL STATUS" + myTunnel.isRunning()); 62 | this.After(function(scenario, callback) { 63 | console.log("Started Tunnel AFTER " + myTunnel.isRunning()); 64 | this.driver.quit().then(function() { 65 | if (myTunnel) { 66 | myTunnel.stop(callback); 67 | } 68 | callback(); 69 | }); 70 | }); 71 | }; 72 | 73 | module.exports = myHooks; 74 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cucumber-js-lambdatest", 3 | "version": "0.1.0", 4 | "readme": "Cucumber-JS Integration with [lambdatest](https://www.lambdatest.com)", 5 | "description": "Selenium examples for Cucumber-JS and lambdatest Automate", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/lambdatest/cucumber-js-lambdatest.git" 9 | }, 10 | "scripts": { 11 | "test": "npm run single && npm run local && npm run parallel", 12 | "single": "cross-env CONFIG_FILE=single ./node_modules/cucumber/bin/cucumber.js features/single.feature", 13 | "local": "cross-env CONFIG_FILE=local ./node_modules/cucumber/bin/cucumber.js features/local.feature", 14 | "parallel": "cross-env CONFIG_FILE=parallel ./scripts/cucumber-runner.js features/single.feature", 15 | "parallelJenkins": "cross-env CONFIG_FILE=parallelJenkins ./scripts/cucumber-runner.js features/single.feature", 16 | "singleJenkins": "cross-env CONFIG_FILE=singleJenkins ./scripts/cucumber-runner.js features/single.feature" 17 | }, 18 | "devDependencies": { 19 | "cross-env": "^7.0.3", 20 | "cucumber": "^1.3.3", 21 | "cucumber-assert": "1.0.4", 22 | "selenium-webdriver": "^3.6.0" 23 | }, 24 | "dependencies": { 25 | "@lambdatest/node-tunnel": "^2.0.2" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /scripts/cucumber-runner.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var child_process = require("child_process"); 3 | var config_file = 4 | "../conf/" + (process.env.CONFIG_FILE || "single") + ".conf.js"; 5 | var config = require(config_file).config; 6 | 7 | process.argv[0] = "node"; 8 | process.argv[1] = "./node_modules/.bin/cucumber-js"; 9 | 10 | for (var i in config.capabilities) { 11 | var env = Object.create(process.env); 12 | env.TASK_ID = i.toString(); 13 | var p = child_process.spawn("/usr/bin/env", process.argv, { env: env }); 14 | p.stdout.pipe(process.stdout); 15 | } 16 | --------------------------------------------------------------------------------