From eea946e823b75c4eb044194e99003a119c1abdfb Mon Sep 17 00:00:00 2001 From: "B.J. Rossiter" Date: Thu, 20 Sep 2012 07:56:50 +1000 Subject: [PATCH] Updated integration tests to run chrome when tested locally --- integration.sh | 9 ++-- tests/integration/CreateBudget.js | 89 +++++++++++++++++-------------- tests/integration/helper.js | 16 +++--- 3 files changed, 64 insertions(+), 50 deletions(-) diff --git a/integration.sh b/integration.sh index 672fd68..790f565 100755 --- a/integration.sh +++ b/integration.sh @@ -1,7 +1,10 @@ #!/bin/bash npm install -./server.sh devserver & -# for local testing +# For local testing, download and install selenium and the chrome driver and +# then make sure the dev server is running +# java -Dwebdriver.chrome.driver=/path/to/chromedriver -jar ~/path/to/selenium-server-standalone-2.25.0.jar #./node_modules/.bin/mocha -R spec -t 40000 tests/integration/CreateBudget.js -# for sauce testing + +# For sauce testing. This tests using the budget2012-dev site. This will be +# deployed to after a push and should be up to date before this is triggerd by jenkins ./node_modules/.bin/mocha -R spec -t 1200000 tests/integration/CreateBudget.js --with-sauce diff --git a/tests/integration/CreateBudget.js b/tests/integration/CreateBudget.js index daf3d2c..3a44a2e 100644 --- a/tests/integration/CreateBudget.js +++ b/tests/integration/CreateBudget.js @@ -3,66 +3,73 @@ var should = require('should'); var async = require('async'); var browser; -describe('Loading the home page and clicking SAVE & SHARE', function(){ +async.forEachSeries(helper.config.browsers, function(browserEnv, suiteDone){ - before(function(done){ - helper.startBrowser(function(err, webdriver){ - browser = webdriver; - browser.elementByCssSelector('a[href="/budget/save"]', function(err, el){ - should.exist(el); - browser.clickElement(el, function(err){ - setTimeout(function(){ done(); }, 500); + describe('In ' + browserEnv.browserName + ' load the home page and clicking SAVE & SHARE', function(){ + + before(function(done){ + helper.startBrowser('Create Budget', browserEnv, function(err, webdriver){ + browser = webdriver; + browser.elementByCssSelector('a[href="/budget/save"]', function(err, el){ + should.exist(el); + browser.clickElement(el, function(err){ + setTimeout(function(){ done(); }, 500); + }); }); }); }); - }); - it("should display the 'Save your budget form'", function(done){ - browser.active(function(err, input){ - if (err) return next(err); - browser.getAttribute(input, 'name', function(err, value){ - value.should.equal('yourName'); - done(); + it("should display the 'Save your budget form' and focus on 'Your Name'", function(done){ + browser.active(function(err, input){ + if (err) return next(err); + browser.getAttribute(input, 'name', function(err, value){ + value.should.equal('yourName'); + done(); + }); }); }); - }); - describe('with the form filled out and save clicked', function(){ + describe('with the form filled out and save clicked', function(){ - var details = [ - ['yourName', 'B.J. Rossiter' ], - ['yourState', 'NSW' ], - ['yourEmail', 'bj.rossiter@theglobalmail.org' ], - ['budgetDescription', 'testing!' ] - ]; + var details = [ + ['yourName', 'B.J. Rossiter' ], + ['yourState', 'NSW' ], + ['yourEmail', 'bj.rossiter@theglobalmail.org' ], + ['budgetDescription', 'testing!' ] + ]; - var budgetUrlSel = 'input[name="budget-url"]'; + var budgetUrlSel = 'input[name="budget-url"]'; - before(function(done){ - async.forEachSeries(details, function(detail, next){ - helper.inputText(browser, detail[0], detail[1], next); - }, function(err){ - should.not.exist(err); - helper.click(browser, 'submit-save-budget', function(err){ - browser.waitForConditionInBrowser("$('" + budgetUrlSel + "').length", function(err, met){ - done(); + before(function(done){ + async.forEachSeries(details, function(detail, next){ + helper.inputText(browser, detail[0], detail[1], next); + }, function(err){ + should.not.exist(err); + helper.click(browser, 'submit-save-budget', function(err){ + browser.waitForConditionInBrowser("$('" + budgetUrlSel + ":visible').length > 0", 3000, 100, function(err, met){ + done(); + }); }); }); }); - }); - it('should display a link to share', function(done){ - browser.elementByCssSelector(budgetUrlSel, function(err, el){ - el.text(function(err, text){ - text.should.match(/^http:.*\/budget\/\S+/); - done(); + it('should display a link to share', function(done){ + browser.elementByCssSelector(budgetUrlSel, function(err, el){ + el.getValue(function(err, text){ + console.log("got text: " + text); + text.should.match(/^http:.*\/budget\/\S+/); + text.should.not.match(/undefined/); + done(); + }); }); }); + }); + after(function(done){ + browser.quit(done); + suiteDone(); + }); }); - after(function(done){ - browser.quit(done); - }); }); diff --git a/tests/integration/helper.js b/tests/integration/helper.js index 6d4bde0..5e910c1 100644 --- a/tests/integration/helper.js +++ b/tests/integration/helper.js @@ -4,8 +4,9 @@ var args = nopt(null, null, process.argv, 2); var configs = { 'local': { - desired: [ - {browserName: "firefox"} + browsers: [ + {browserName: "firefox"}, + {browserName: "chrome"} ], url: 'http://localhost:5000' }, @@ -17,7 +18,7 @@ var configs = { processes: 23, maxTests: false, serviceName: 'sauce', - desired: [ + browsers: [ {browserName: "internet explorer", version: '8', platform: "XP", proxy: {proxyType: 'direct'}, 'selenium-version': '2.21.0'}, {browserName: "firefox", version: '10', platform: "Windows 2003", proxy: {proxyType: 'direct'}}, {browserName: "chrome", version: '', platform: "VISTA", proxy: {proxyType: 'direct'}} @@ -26,13 +27,14 @@ var configs = { } }; +var conf = exports.config = args['with-sauce'] ? configs.sauce : configs.local; + /* * Return a webdriver browser. The browser will either connect to a local * selenium server or sauce depending on arguments */ -exports.startBrowser = function(cb){ +exports.startBrowser = function(name, browserEnv, cb){ - var conf = args['with-sauce'] ? configs.sauce : configs.local; var browser = webdriver.remote(conf.host, conf.port, conf.username, conf.accessKey); if (args['debug-wd']){ @@ -45,7 +47,9 @@ exports.startBrowser = function(cb){ }); } - browser.init(conf.desired, function(){ + browserEnv.tags = ['budget2012']; + browserEnv.name = name; + browser.init(browserEnv, function(){ browser.get(conf.url, function(err){ cb(err, browser); });