Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update packages * compiler -> require-module * Downgrade jsdom to 11.5.1 * Fix require-module config * Fix execution result handling * Update peer dependencies * Add Section cinstructor to API * Fix code-style issues * Add missing run to page object test * Add documentation on the Section object (#343) * Add documentation on the Section object * Fix section test * Add @amurdock as a contributor * Add @clayreimann as a contributor * Fix contributors * Fix eslint issue
- Loading branch information
Igor Muchychka
committed
Feb 7, 2018
1 parent
e180976
commit d319afe
Showing
8 changed files
with
181 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
## Creating dynamic sections | ||
|
||
You can create sections dynamically by using the modified Nightwatch `Section` | ||
constructor exported by Nightwatch Cucumber. Consider the following example | ||
using nightwatch to test Wikipedia. | ||
|
||
```javascript | ||
//page-objects/wikipedia.js | ||
const { Section } = require('nightwatch-cucumber') | ||
module.exports = { | ||
url: 'https://en.wikipedia.org/wiki/Cucumber_(software)', | ||
elements: { | ||
toc: 'div#toc' | ||
}, | ||
commands: [{ | ||
getHeading: function(heading) { | ||
const props = { | ||
parent: this, | ||
selector: `//h2/*[text()="${heading}"]/..`, | ||
using: 'xpath', | ||
elements: { | ||
editLink: { | ||
selector: '//*[@class="mw-editsection"]//a[text()="edit"]', | ||
locateStrategy: 'xpath' | ||
} | ||
}, | ||
commands: [{ | ||
verifyEditSection: function() { | ||
return Promise.resolve(true); | ||
} | ||
}] | ||
} | ||
return new Section(props); | ||
}, | ||
getSectionTitles: function() { | ||
return Promise.resolve([/* MAGIC! */]); | ||
} | ||
}] | ||
} | ||
``` | ||
|
||
Now we can use the `getHeading` command to test each of the edit links to ensure | ||
that they edit the appropriate section. | ||
|
||
```javascript | ||
//step-definitions/yahoo.js | ||
|
||
const { client } = require('nightwatch-cucumber'); | ||
const { Given, Then, When } = require('cucumber'); | ||
const wikipedia = client.page.wikipedia(); | ||
|
||
Given(/^I open each section's edit link$/, () => { | ||
wikipedia.navigate(); | ||
return Promise.all( | ||
wikipedia.getSectionTitles() | ||
.map((title) => wikipedia.getHeading(title).verifyEditSection()) | ||
); | ||
}); | ||
``` | ||
The advantage of creating sections of the fly like this that your page object | ||
code can be much DRYer, especially when there are many similar objects on the | ||
page that you want to test. |
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
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
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