Skip to content

Instantly share code, notes, and snippets.

@vjwilson
Created September 20, 2017 00:42
Show Gist options
  • Save vjwilson/590b26a4e74d5151c5bdc148103733b0 to your computer and use it in GitHub Desktop.
Save vjwilson/590b26a4e74d5151c5bdc148103733b0 to your computer and use it in GitHub Desktop.
Setup Cucumber.js for functional testing
# add libraries
npm install --save-dev chromedriver cucumber selenium-webdriver
# add support file
touch features/support/world.js
# add hooks file
touch features/step_definitions/hooks.js
# add feature file
touch features/documentation.feature
# add step definitions
touch features/step_definitions/browser_steps.js
var seleniumWebdriver = require('selenium-webdriver');
var {defineSupportCode} = require('cucumber');
defineSupportCode(function({Given, When, Then}) {
Given('I am on the Cucumber.js GitHub repository', function() {
return this.driver.get('https://github.com/cucumber/cucumber-js/tree/master');
});
When('I click on {string}', function (text) {
return this.driver.findElement({linkText: text}).then(function(element) {
return element.click();
});
});
Then('I should see {string}', function (text) {
var xpath = "//*[contains(text(),'" + text + "')]";
var condition = seleniumWebdriver.until.elementLocated({xpath: xpath});
return this.driver.wait(condition, 5000);
});
});
Feature: Example feature
As a user of Cucumber.js
I want to have documentation on Cucumber
So that I can concentrate on building awesome applications
Scenario: Reading documentation
Given I am on the Cucumber.js GitHub repository
When I click on "CLI"
Then I should see "Running specific features"
var {defineSupportCode} = require('cucumber');
defineSupportCode(function({After}) {
After(function() {
return this.driver.quit();
});
});
require('chromedriver')
var seleniumWebdriver = require('selenium-webdriver');
var {defineSupportCode} = require('cucumber');
function CustomWorld() {
this.driver = new seleniumWebdriver.Builder()
.forBrowser('chrome')
.build();
}
defineSupportCode(function({setWorldConstructor}) {
setWorldConstructor(CustomWorld)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment