Skip to content

Instantly share code, notes, and snippets.

@kbingman
Last active August 5, 2019 16:51
Show Gist options
  • Save kbingman/730b9f2307ef776f1f66 to your computer and use it in GitHub Desktop.
Save kbingman/730b9f2307ef776f1f66 to your computer and use it in GitHub Desktop.
A basic test runner to use Yadda with the Nightwatch selenium testing framework.
Feature: Google Demo
Scenario: Google home page
When I open http://google.com
and I should see #viewport
var Yadda = require('yadda');
var English = Yadda.localisation.English;
var Dictionary = Yadda.Dictionary;
module.exports.init = function() {
var dictionary = new Dictionary();
var library = English.library()
// Opens a given URL in the nightwatch browser and then waits
// until it is mobified
//
.when("I open $URL", function(url) {
this.browser.url(url)
})
// Waits for the correct element, then test for the text
//
.then("the title should be $TITLE", function(title){
this.browser.assert.title(title)
})
// Makes a screenshot and saves it with a given title and timestamp
//
.then("it should make a screenshot titled $TITLE", function(title) {
var filename = title + '.png';
this.browser.saveScreenshot('screenshots/' + filename);
})
// Closes the browser
//
.then("close the browser", function() {
this.browser.closeWindow();
})
.then("end the session", function() {
this.browser.end();
})
// Pauses for the give amount of seconds
//
.then("wait $SECONDS seconds", function(seconds){
this.browser.pause(seconds * 1000)
})
.when("I click on $SELECTOR", function(selector){
this.browser.click(selector);
})
.then("I should see $SELECTOR", function(selector){
this.browser.assert.visible(selector);
});
return library;
};
var fs = require('fs');
var utils = require('utils');
var Yadda = require('yadda');
var parser = new Yadda.parsers.FeatureParser();
var library = require('./library').init();
var yadda = new Yadda.Yadda(library);
module.exports = (function(){
var features = new Yadda.FeatureFileSearch('features').list();
var steps = {};
features.forEach(function(file){
var text = fs.readFileSync(file, 'utf8');
var feature = parser.parse(text);
utils.puts(feature.title);
feature.scenarios.forEach(function(scenario) {
steps[scenario.title] = function(browser) {
yadda.yadda(scenario.steps, { browser: browser });
};
});
});
// Close the session when done
steps['Close Session'] = function(browser){
browser.end();
};
return steps;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment