-
-
Save atrunelle/df22680c3fcb9574dd4bd6796dc412e7 to your computer and use it in GitHub Desktop.
This file contains 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
const axios = require('axios'); | |
const browserstackConfig = require('./tests/e2e/browserstack.config'); | |
const path = require('path'); | |
const testConfig = require('dotenv').config({ path: path.resolve(process.cwd(), '.env.test') }).parsed; | |
const prodConfig = require('dotenv').config({ path: path.resolve(process.cwd(), '.env.prod') }).parsed; | |
const packageVersion = process.env.npm_package_version; | |
const buildName = `Ver_${packageVersion}`; | |
// http://nightwatchjs.org/gettingstarted#settings-file | |
const nightwatchConfig = { | |
src_folders: ['tests/e2e/specs'], | |
output_folder: 'tests/e2e/reports', | |
custom_commands_path: ['tests/e2e/custom-command'], | |
page_objects_path: 'tests/e2e/pages', | |
test_workers: { | |
enabled: true, | |
workers: 'auto', | |
}, | |
test_settings: { | |
default: { | |
end_session_on_fail: false, // /!\ Important to get the session id back and update browserstack status on fail | |
launch_url: process.env.VUE_DEV_SERVER_URL, | |
desiredCapabilities: { | |
browserName: process.env.BROWSER || 'chrome', | |
}, | |
globals: { | |
...testConfig, | |
waitForConditionTimeout: 25000, | |
after: async (done) => { | |
if (process.env.RUNNER !== browserstackConfig.RUNNER) { return; } | |
const response = await axios.get( | |
'https://api.browserstack.com/automate/builds.json', | |
{ | |
auth: { | |
username: browserstackConfig.USER, | |
password: browserstackConfig.KEY, | |
}, | |
} | |
); | |
const build = response.data | |
.find((item) => item.automation_build.name === buildName); | |
console.log(`Browserstack session: https://automate.browserstack.com/builds/${build.automation_build.hashed_id}`); | |
done(); | |
}, | |
afterEach(client, done) { | |
if (process.env.RUNNER === browserstackConfig.RUNNER) { | |
if (client.currentTest.results.failed > 0 && client.sessionId) { | |
try { | |
axios.put( | |
`https://api.browserstack.com/automate/sessions/${client.sessionId}.json`, | |
{ | |
status: 'error', | |
reason: '', | |
}, | |
{ | |
auth: { | |
username: browserstackConfig.USER, | |
password: browserstackConfig.KEY, | |
}, | |
} | |
); | |
} catch(error) { | |
console.error(error); | |
} | |
} | |
const cliOptions = process.argv.slice(2); | |
const envIndex = cliOptions.indexOf('--env'); | |
const envName = cliOptions[envIndex + 1]; | |
try { | |
if (client.sessionId) { | |
axios.put( | |
`https://api.browserstack.com/automate/sessions/${client.sessionId}.json`, | |
{ | |
name: `${envName} env: ${client.currentTest.module}`, | |
}, | |
{ | |
auth: { | |
username: browserstackConfig.USER, | |
password: browserstackConfig.KEY, | |
}, | |
} | |
); | |
} | |
} catch(error) { | |
console.error(error); | |
} | |
} | |
client.end(); | |
done(); | |
}, | |
}, | |
}, | |
headless: { | |
desiredCapabilities: { | |
browserName: 'chrome', | |
chromeOptions: { | |
args: [ | |
'--headless', '--no-sandbox', | |
], | |
}, | |
}, | |
}, | |
test: { | |
launch_url: 'https://test-env.url', | |
}, | |
prod: { | |
launch_url: 'https://prod-env.url', | |
filter: 'smoketests/*', | |
globals: { | |
...prodConfig, | |
}, | |
}, | |
}, | |
}; | |
if (process.env.RUNNER === browserstackConfig.RUNNER) { | |
nightwatchConfig.selenium = { | |
start_process: false, | |
host: 'hub-cloud.browserstack.com', | |
port: 80, | |
}; | |
nightwatchConfig.custom_assertions_path = ['tests/e2e/custom-assertions']; | |
nightwatchConfig.test_workers.enabled = false; | |
const defaultTestSettings = nightwatchConfig.test_settings.default; | |
defaultTestSettings.selenium_host = nightwatchConfig.selenium.host; | |
defaultTestSettings.selenium_port = nightwatchConfig.selenium.port; | |
const browserStackDesiredCapabilities = { | |
build: `${buildName}`, | |
project: 'SmartMatch_Admin2', | |
'browserstack.user': browserstackConfig.USER, | |
'browserstack.key': browserstackConfig.KEY, | |
'browserstack.local': true, | |
browserName: process.env.BROWSER || 'chrome', | |
browser: process.env.BROWSER || 'Chrome', | |
chromeOptions: {}, | |
}; | |
nightwatchConfig.test_settings.test.desiredCapabilities = browserStackDesiredCapabilities; | |
nightwatchConfig.test_settings.prod.desiredCapabilities = browserStackDesiredCapabilities; | |
} | |
module.exports = nightwatchConfig; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment