Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Updating for Yadda 0.6.2 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"description": "Packages used for running web acceptance tests",
"author": "Colin Vipurs <[email protected]>",
"devDependencies": {
"yadda": "~0.5.2",
"yadda": "~0.6.2",
"mocha": "~1.12.0",
"selenium-webdriver": "2.35.x",
"glob": "~3.2.x",
"xunit-file" : "0.0.4"
},
"engine": "node >= 0.8.0"
"engine": "node >= 0.8.0",
"scripts": {
"test": "make test"
}
}
32 changes: 16 additions & 16 deletions runtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
*Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

var Yadda = require('yadda').Yadda;
require('yadda').plugins.mocha();
var glob = require('glob');
var Library = require('yadda').localisation.English;
var library = new Library();
var Yadda = require('yadda');
Yadda.plugins.mocha();

var context = {};
var webcontext = require('./weblibrary').library.init(context);
var yadda = new Yadda(library, context);
var libraries = stepDefs().reduce(importStepDef, []);
var context = require('./weblibrary').library.init();
var yadda = new Yadda.Yadda(libraries, context);

stepDefs().forEach(importStepDef);
featureFiles().forEach(executeFeature);
featureFiles().forEach(function(file) {
feature(file, function(feature) {
scenarios(feature.scenarios, function(scenario, done) {
yadda.yadda(scenario.steps, done);
})
})
});

function featureFiles() {
return glob.sync("features/**/*.feature");
Expand All @@ -29,11 +32,8 @@ function stepDefs() {
return glob.sync("stepdefs/**/*.js")
};

function importStepDef(stepdef) {
function importStepDef(stepdefs, stepdef) {
var fileName = stepdef.replace('.js', '');
require('./' + fileName).steps.using(library, context);
};

function executeFeature(featureFile) {
yadda.mocha('Bootstrap', featureFile);
};
var library = require('./' + fileName);
return stepdefs.concat(library);
};
40 changes: 18 additions & 22 deletions stepdefs/Sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,27 @@
*/
var webdriver = require('selenium-webdriver');
var assert = require('selenium-webdriver/testing/assert');
var library = new require('yadda').localisation.English();

var Steps = {
using: function(library, ctx) {
library.given("I am on google", function(next) {
ctx.driver.get("http://www.google.co.uk")
.then(function() {
next();
});
});
module.exports = library

library.when("I search for $query", function(query, next) {
ctx.driver.findElement(webdriver.By.css("#gbqfq")).sendKeys(query);
ctx.driver.findElement(webdriver.By.css("#gbqfb")).click().then(function() {
next();
});
.given("I am on google", function(next) {
this.driver.get("http://www.google.co.uk")
.then(function() {
next();
});
})

library.then("I should see the yadda github in the results", function(next) {
ctx.driver.findElement(webdriver.By.css("cite")).getText().then(function(text) {
assert(text).contains("https://github.com/acuminous/");

next();
});
.when("I search for $query", function(query, next) {
this.driver.findElement(webdriver.By.css("#gbqfq")).sendKeys(query);
this.driver.findElement(webdriver.By.css("#gbqfb")).click().then(function() {
next();
});
}
};
})

exports.steps = Steps;
.then("I should see the yadda github in the results", function(next) {
this.driver.findElement(webdriver.By.css("cite")).getText().then(function(text) {
assert(text).contains("https://github.com/acuminous/");
next();
});
});
11 changes: 6 additions & 5 deletions weblibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ var context;
var webdriver = require('selenium-webdriver');

var weblibrary = {
init: function(context) {
var self = this;
self.context = context;
init: function() {
var context = {};

// mocha lifecycle operations
function initBrowser(done) {
Expand All @@ -22,18 +21,20 @@ var weblibrary = {
.withCapabilities({'browserName': 'chrome'})
.build();
driver.manage().timeouts().implicitlyWait(15000);
self.context.driver = driver;
context.driver = driver;
done();
}

function shutdownBrowser(done) {
self.context.driver.quit().then(function() {
context.driver.quit().then(function() {
done();
});
}

before(initBrowser);
after(shutdownBrowser);

return context;
}
};

Expand Down