Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1152 from ONSdigital/browserstack-integration
Browse files Browse the repository at this point in the history
BrowserStack integration
  • Loading branch information
adoublebarrel authored Jun 29, 2017
2 parents 522b7ea + c11652f commit 86c29f4
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 40 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ language: node_js
node_js: 6
env:
global:
- EQ_ENABLE_CACHE=True
- EQ_RUN_LOCAL_LINT=True
- EQ_RUN_LOCAL_TESTS=True
- EQ_RUN_LOCAL=True
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Command | Task
`yarn test_unit` | Watches the unit tests via Karma
`yarn test_functional` | Runs the functional tests through a local Selenium instance (requires app running on localhost:5000)
`yarn test_functional_sauce` | Runs the functional tests through Sauce Labs (requires app running on localhost:5000)
`yarn test_functional_browserstack` | Runs the functional tests through BrowserStack (requires app running on localhost:5000)
`yarn lint` | Lints the JS, reporting errors/warnings.
`yarn format` | Format the json schemas.

Expand Down
5 changes: 5 additions & 0 deletions app/views/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def add_cache_control(response):
return response


@session_blueprint.route('/session', methods=['HEAD'])
def login_head():
return '', 204


@session_blueprint.route('/session', methods=['GET'])
def login():
"""
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test_unit_no_watch": "gulp test:scripts:unit",
"test_functional": "gulp test:scripts:functional",
"test_functional_sauce": "gulp test:scripts:functional --sauce",
"test_functional_browserstack": "gulp test:scripts:functional --browserstack",
"test_functional_headless": "gulp test:scripts:functional --headless",
"a11y": "gulp test:a11ym",
"format": "gulp format:json"
Expand All @@ -38,6 +39,7 @@
"browser-sync": "^2.11.0",
"browserify": "~13.1.0",
"browserify-shim": "^3.8.12",
"browserstack-local": "^1.3.0",
"chai": "^3.4.1",
"chai-as-promised": "^5.1.0",
"del": "^2.2.2",
Expand Down Expand Up @@ -125,6 +127,7 @@
"vinyl-source-stream": "~1.1.0",
"vinyl-transform": "^1.0.0",
"watchify": "~3.7.0",
"wdio-browserstack-service": "^0.1.4",
"wdio-dot-reporter": "^0.0.8",
"wdio-mocha-framework": "^0.5.10",
"wdio-phantomjs-service": "^0.2.2",
Expand Down
35 changes: 18 additions & 17 deletions tests/functional/capabilities.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const defaultCapabilities = {
'project': 'EQ Survey Runner',
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
'build': process.env.TRAVIS_BUILD_NUMBER,
'public': true,
'maxInstances': 1
'maxInstances': 1,
'browserstack.local': true
}

export const chrome = {
name: 'Chrome 48 | OS X 10.11',
browserName: 'chrome',
version: '48.0',
platform: 'OS X 10.11',
browser_version: '48.0',
os: 'OS X',
os_version: 'Yosemite',
...defaultCapabilities
}

export const chromeNoJS = {
...chrome,
name: 'Chrome (No JavaScript) 48 | OS X 10.11',
name: 'Chrome (No JavaScript)',
chromeOptions: {
prefs: {'profile.managed_default_content_settings.javascript': 2}
}
Expand All @@ -27,48 +29,47 @@ export const phantomjs = {
}

export const firefox = {
name: 'Firefox 43 | OS X 10.11',
browserName: 'firefox',
version: '43.0',
platform: 'OS X 10.11',
os: 'OS X',
...defaultCapabilities
}

export const edge = {
name: 'MS Edge | Windows 10',
browserName: 'microsoftedge',
platform: 'Windows 10',
os: 'Windows',
os_version: '10',
...defaultCapabilities
}

export const ie11 = {
name: 'IE11 | Windows 7',
browserName: 'internet explorer',
version: '11.0',
platform: 'Windows 7',
os: 'Windows',
os_version: '7',
...defaultCapabilities
}

export const ie10 = {
name: 'IE10 | Windows 7',
browserName: 'internet explorer',
version: '10.0',
platform: 'Windows 7',
os: 'Windows',
os_version: '7',
...defaultCapabilities
}

export const ie9 = {
name: 'IE9 | Windows 7',
browserName: 'internet explorer',
version: '9.0',
platform: 'Windows 7',
os: 'Windows',
os_version: '7',
...defaultCapabilities
}

export const ie8 = {
name: 'IE8 | Windows XP',
browserName: 'internet explorer',
version: '8.0',
platform: 'Windows XP',
os: 'Windows',
os_version: 'XP',
...defaultCapabilities
}
19 changes: 11 additions & 8 deletions tests/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ const sauceLabsConfig = {
capabilities: [firefox]
}

const browserStackConfig = {
services: ['browserstack'],
user: process.env.BROWSERSTACK_USER,
key: process.env.BROWSERSTACK_ACCESS_KEY,
browserstackLocal: true
}

const phantomjsConfig = {
services: ['phantomjs'],
waitforTimeout: 3000,
Expand All @@ -76,15 +83,11 @@ if (process.env.TRAVIS === 'true') {
}
} else {
if (argv.sauce) {
config = {
...config,
...sauceLabsConfig
}
config = Object.assign(config, sauceLabsConfig)
} else if (argv.browserstack) {
config = Object.assign(config, browserStackConfig)
} else if (argv.headless) {
config = {
...config,
...phantomjsConfig
}
config = Object.assign(config, phantomjsConfig)
}
}

Expand Down
6 changes: 2 additions & 4 deletions tests/functional/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import {generateToken} from './jwt_helper'

export {landingPage}

export const getUri = uri => browser.options.baseUrl + uri

export const getRandomString = length => sampleSize('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', length).join('')

export const startCensusQuestionnaire = (schema, sexualIdentity = false, region = 'GB-ENG', language = 'en') => {
generateToken(schema, getRandomString(10), getRandomString(10), null, null, region, language, sexualIdentity)
.then(function(token) {
return browser.url('http://localhost:5000/session?token=' + token)
return browser.url('/session?token=' + token)
})

browser.pause(1000) // Shudder!!!
Expand All @@ -20,7 +18,7 @@ export const startCensusQuestionnaire = (schema, sexualIdentity = false, region
export function openQuestionnaire(schema, userId = getRandomString(10), collectionId = getRandomString(10), periodId = '201605', periodStr = 'May 2016') {
generateToken(schema, userId, collectionId, periodId, periodStr)
.then(function(token) {
return browser.url('http://localhost:5000/session?token=' + token)
return browser.url('/session?token=' + token)
})

browser.pause(1000) // Shudder!!!
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/session/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ def test_login_with_valid_token_no_eq_id_and_form_type(self):

# Then
self.assertStatusNotFound()


def test_http_head_request_to_login_returns_successfully_and_get_still_works(self):
# Given
token = self.token_generator.create_token('0205', '1')

# When
self._client.head('/session?token=' + token.decode(), as_tuple=True, follow_redirects=True)
self.get('/session?token=' + token.decode())

# Then
self.assertStatusOK()
self.assertInUrl('/questionnaire/1/0205')
16 changes: 6 additions & 10 deletions tests/new_functional/capabilities.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const defaultCapabilities = {
'project': 'EQ Survey Runner',
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
'build': process.env.TRAVIS_BUILD_NUMBER,
'public': true,
'maxInstances': 1
'maxInstances': 1,
'browserstack.local': true
};

const chrome = Object.assign({
name: 'Chrome 48 | OS X 10.11',
browserName: 'chrome',
version: '48.0',
platform: 'OS X 10.11'
os: 'OS X',
os_version: 'Yosemite'
}, defaultCapabilities);

const chromeNoJS = Object.assign(
{
name: 'Chrome (No JavaScript) 48 | OS X 10.11',
name: 'Chrome (No JavaScript)',
chromeOptions: {
prefs: {'profile.managed_default_content_settings.javascript': 2}
}
Expand All @@ -29,46 +31,40 @@ const phantomjs = {

const firefox = Object.assign(
{
name: 'Firefox 43 | OS X 10.11',
browserName: 'firefox',
version: '43.0',
platform: 'OS X 10.11'
}, defaultCapabilities);

const edge = Object.assign(
{
name: 'MS Edge | Windows 10',
browserName: 'microsoftedge',
platform: 'Windows 10'
}, defaultCapabilities);

const ie11 = Object.assign(
{
name: 'IE11 | Windows 7',
browserName: 'internet explorer',
version: '11.0',
platform: 'Windows 7'
}, defaultCapabilities);

const ie10 = Object.assign(
{
name: 'IE10 | Windows 7',
browserName: 'internet explorer',
version: '10.0',
platform: 'Windows 7'
}, defaultCapabilities);

const ie9 = Object.assign(
{
name: 'IE9 | Windows 7',
browserName: 'internet explorer',
version: '9.0',
platform: 'Windows 7'
}, defaultCapabilities);

const ie8 = Object.assign(
{
name: 'IE8 | Windows XP',
browserName: 'internet explorer',
version: '8.0',
platform: 'Windows XP'
Expand Down
9 changes: 9 additions & 0 deletions tests/new_functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ const sauceLabsConfig = {
capabilities: [capabilities.firefox]
};

const browserStackConfig = {
services: ['browserstack'],
user: process.env.BROWSERSTACK_USER,
key: process.env.BROWSERSTACK_ACCESS_KEY,
browserstackLocal: true
}

const phantomjsConfig = {
services: ['phantomjs'],
waitforTimeout: 3000,
Expand Down Expand Up @@ -81,6 +88,8 @@ if (process.env.TRAVIS === 'true') {
} else {
if (argv.sauce) {
config = Object.assign(config, sauceLabsConfig);
} else if (argv.browserstack) {
config = Object.assign(config, browserStackConfig);
} else if (argv.headless) {
config = Object.assign(config, phantomjsConfig);
}
Expand Down

0 comments on commit 86c29f4

Please sign in to comment.