-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Upgrade Nightwatch to v1.2 and update bundled config and generated tests #4541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
haoqunjiang
merged 10 commits into
vuejs:dev
from
beatfactor:feat/nightwatch-upgrade-v1.2
Sep 9, 2019
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e20b2cf
feat: Upgraded Nightwatch to version 1.2; updated distributed config;…
beatfactor db8bf9e
Merge branch 'dev' into feat/nightwatch-upgrade-v1.2
beatfactor 410c8a9
docs: updated nightwatch plugin readme
beatfactor 11cab76
feat: add chromedriver and geckodriver as peer dependencies
beatfactor d179074
Merge branch 'dev' into feat/nightwatch-upgrade-v1.2
beatfactor 57f7dec
updated readme and driver depedencies
beatfactor 271264e
updated optional dependencies
beatfactor 44e1984
fixed failing tests
beatfactor 7bb7f32
updated generated tests
beatfactor 1830e59
updated tests
beatfactor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
packages/@vue/cli-plugin-e2e-nightwatch/__tests__/lib/globals-gecko.js
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* This file is copied during the firefox test inside the project folder and used to inspect the results | ||
*/ | ||
const fs = require('fs') | ||
|
||
module.exports = { | ||
reporter (results, cb) { | ||
fs.writeFile('test_results_gecko.json', JSON.stringify(results), cb) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/@vue/cli-plugin-e2e-nightwatch/__tests__/lib/globals-generated.js
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* This file is copied during the test inside the project folder and used to inpsect the results | ||
*/ | ||
const fs = require('fs') | ||
|
||
module.exports = { | ||
afterEach (browser, cb) { | ||
fs.writeFile('test_settings.json', JSON.stringify(browser.options), cb) | ||
}, | ||
|
||
reporter (results, cb) { | ||
fs.writeFile('test_results.json', JSON.stringify(results), cb) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/@vue/cli-plugin-e2e-nightwatch/__tests__/lib/nightwatch.conf.js
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* This file is copied during the test inside the project folder | ||
*/ | ||
module.exports = { | ||
globals_path: './tests/e2e/globals-gecko.js' | ||
} |
101 changes: 94 additions & 7 deletions
101
packages/@vue/cli-plugin-e2e-nightwatch/__tests__/nightwatchPlugin.spec.js
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,100 @@ | ||
jest.setTimeout(40000) | ||
jest.setTimeout(process.env.APPVEYOR ? 300000 : 120000) | ||
|
||
const fs = require('fs-extra') | ||
const path = require('path') | ||
const create = require('@vue/cli-test-utils/createTestProject') | ||
|
||
test('should work', async () => { | ||
const project = await create('e2e-nightwatch', { | ||
plugins: { | ||
'@vue/cli-plugin-babel': {}, | ||
'@vue/cli-plugin-e2e-nightwatch': {} | ||
describe('nightwatch e2e plugin', () => { | ||
let project | ||
|
||
beforeAll(async () => { | ||
project = await create('e2e-nightwatch', { | ||
plugins: { | ||
'@vue/cli-plugin-babel': {}, | ||
'@vue/cli-plugin-e2e-nightwatch': {} | ||
} | ||
}) | ||
|
||
await fs.copy(path.join(__dirname, './lib/globals-generated.js'), | ||
path.join(project.dir, 'tests/e2e/globals-generated.js')) | ||
|
||
const config = { | ||
globals_path: './tests/e2e/globals-generated.js' | ||
} | ||
await project.write('nightwatch.json', JSON.stringify(config)) | ||
}) | ||
|
||
test('should run all tests successfully', async () => { | ||
await project.run(`vue-cli-service test:e2e --headless`) | ||
let results = await project.read('test_results.json') | ||
results = JSON.parse(results) | ||
expect(Object.keys(results.modules)).toEqual([ | ||
'test-with-pageobjects', | ||
'test' | ||
]) | ||
}) | ||
|
||
test('should run single test with custom nightwatch.json', async () => { | ||
await project.run(`vue-cli-service test:e2e --headless -t tests/e2e/specs/test.js`) | ||
let results = await project.read('test_results.json') | ||
results = JSON.parse(results) | ||
expect(Object.keys(results.modules)).toEqual([ | ||
'test' | ||
]) | ||
}) | ||
|
||
test('should run single test with custom nightwatch.json and selenium server', async () => { | ||
await project.run(`vue-cli-service test:e2e --headless --with-selenium -t tests/e2e/specs/test.js`) | ||
let results = await project.read('test_results.json') | ||
results = JSON.parse(results) | ||
|
||
let testSettings = await project.read('test_settings.json') | ||
testSettings = JSON.parse(testSettings) | ||
|
||
expect(testSettings).toHaveProperty('selenium') | ||
expect(testSettings.selenium.start_process).toStrictEqual(true) | ||
expect(testSettings.selenium).toHaveProperty('cli_args') | ||
expect(Object.keys(results.modules)).toEqual([ | ||
'test' | ||
]) | ||
}) | ||
|
||
test('should run tests in parallel', async () => { | ||
await project.run(`vue-cli-service test:e2e --headless --parallel`) | ||
let results = await project.read('test_results.json') | ||
results = JSON.parse(results) | ||
|
||
let testSettings = await project.read('test_settings.json') | ||
testSettings = JSON.parse(testSettings) | ||
|
||
expect(testSettings.parallel_mode).toStrictEqual(true) | ||
expect(testSettings.test_workers).toStrictEqual(true) | ||
|
||
expect(Object.keys(results.modules)).toEqual([ | ||
'test', 'test-with-pageobjects' | ||
]) | ||
}) | ||
|
||
// This test requires Firefox to be installed | ||
const testFn = process.env.APPVEYOR ? test.skip : test | ||
testFn('should run single test with custom nightwatch.conf.js in firefox', async () => { | ||
// nightwatch.conf.js take priority over nightwatch.json | ||
const copyConfig = fs.copy(path.join(__dirname, './lib/nightwatch.conf.js'), | ||
path.join(project.dir, 'nightwatch.conf.js')) | ||
|
||
const copyGlobals = fs.copy(path.join(__dirname, './lib/globals-gecko.js'), | ||
path.join(project.dir, 'tests/e2e/globals-gecko.js')) | ||
|
||
await Promise.all([copyConfig, copyGlobals]) | ||
|
||
await project.run(`vue-cli-service test:e2e --headless --env firefox -t tests/e2e/specs/test.js`) | ||
let results = await project.read('test_results_gecko.json') | ||
results = JSON.parse(results) | ||
|
||
expect(Object.keys(results.modules)).toEqual([ | ||
'test' | ||
]) | ||
expect(results.modules.test).toHaveProperty('reportPrefix') | ||
expect(results.modules.test.reportPrefix).toMatch(/^FIREFOX_.+/) | ||
}) | ||
await project.run(`vue-cli-service test:e2e`) | ||
}) |
This file contains hidden or 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
32 changes: 23 additions & 9 deletions
32
.../cli-plugin-e2e-nightwatch/generator/template/tests/e2e/custom-assertions/elementCount.js
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
...e/cli-plugin-e2e-nightwatch/generator/template/tests/e2e/custom-commands/customExecute.js
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* A very basic Nightwatch custom command. The command name is the filename and the | ||
* exported "command" function is the command. | ||
* | ||
* Example usage: | ||
* browser.customExecute(function() { | ||
* console.log('Hello from the browser window') | ||
* }); | ||
* | ||
* For more information on writing custom commands see: | ||
* https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands | ||
* | ||
* @param {*} data | ||
*/ | ||
exports.command = function(data) { | ||
// Other Nightwatch commands are available via "this" | ||
|
||
// .execute() inject a snippet of JavaScript into the page for execution. | ||
// the executed script is assumed to be synchronous. | ||
// | ||
// See https://nightwatchjs.org/api/execute.html for more info. | ||
// | ||
this.execute( | ||
// The function argument is converted to a string and sent to the browser | ||
function(argData) {return argData;}, | ||
|
||
// The arguments for the function to be sent to the browser are specified in this array | ||
[data], | ||
|
||
function(result) { | ||
// The "result" object contains the result from the what we have sent back from the browser window | ||
console.log('custom execute result:', result.value) | ||
} | ||
); | ||
|
||
return this; | ||
}; |
22 changes: 22 additions & 0 deletions
22
...ue/cli-plugin-e2e-nightwatch/generator/template/tests/e2e/custom-commands/openHomepage.js
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* A basic Nightwatch custom command which demonstrates usage of ES6 async/await instead of using callbacks. | ||
* The command name is the filename and the exported "command" function is the command. | ||
* | ||
* Example usage: | ||
* browser.openHomepage(); | ||
* | ||
* For more information on writing custom commands see: | ||
* https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands | ||
* | ||
*/ | ||
module.exports = { | ||
command: async function () { | ||
// Other Nightwatch commands are available via "this" | ||
// .init() simply calls .url() command with the value of the "launch_url" setting | ||
this.init(); | ||
this.waitForElementVisible('#app'); | ||
|
||
const result = await this.elements('css selector', '#app ul'); | ||
this.assert.strictEqual(result.value.length, 3); | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the tests are run in parallel, the order of
results.modules
is nondeterministic, which could cause test failures.