Created
September 20, 2017 00:42
-
-
Save vjwilson/590b26a4e74d5151c5bdc148103733b0 to your computer and use it in GitHub Desktop.
Setup Cucumber.js for functional testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var {defineSupportCode} = require('cucumber'); | |
defineSupportCode(function({After}) { | |
After(function() { | |
return this.driver.quit(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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