Skip to content

Commit e3a954d

Browse files
author
John Doherty
committed
updated page object documentation
1 parent f9aedde commit e3a954d

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

README.MD

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,40 @@ An example page object:
114114

115115
module.exports = {
116116

117+
url: 'http://www.google.co.uk',
118+
117119
elements: {
118-
searchInput: by.name('q')
120+
searchInput: by.name('q'),
121+
searchResultLink: by.css('div.g > h3 > a')
119122
},
120123

121-
preformSearch: function (keywords) {
124+
/**
125+
* enters a search term into Google's search box and presses enter
126+
* @param {string} searchQuery
127+
* @returns {Promise} a promise to enter the search values
128+
*/
129+
preformSearch: function (searchQuery) {
122130

123-
// notice the element path below use the full page qualifier
124-
var input = driver.findElement(page.googleSearch.elements.searchInput);
131+
var selector = page.googleSearch.elements.searchInput;
125132

126-
input.sendKeys(keywords);
127-
input.sendKeys(selenium.Key.ENTER);
133+
// return a promise so the calling function knows the task has completed
134+
return driver.findElement(selector).sendKeys(searchQuery, selenium.Key.ENTER);
128135
}
129136
};
130137
```
131138

132139
And its usage within a step definition:
133140

134141
```js
135-
module.exports = function () {
136-
137-
this.When(/^I search Google for "([^"]*)"$/, function (searchQuery, done) {
142+
// ./step-definitions/google-search-steps.js
143+
this.When(/^I search Google for "([^"]*)"$/, function (searchQuery) {
138144

139-
page.googleSearch.preformSearch(searchQuery);
145+
return helpers.loadPage('http://www.google.com').then(function() {
140146

141-
done(); // <<- let cucumber know you're done
142-
});
143-
};
147+
// use a method on the page object which also returns a promise
148+
return page.googleSearch.preformSearch(searchQuery);
149+
})
150+
});
144151
```
145152

146153
### Shared objects

page-objects/google-search.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ module.exports = {
77
searchResultLink: by.css('div.g > h3 > a')
88
},
99

10-
preformSearch: function (keywords) {
10+
/**
11+
* enters a search term into Google's search box and presses enter
12+
* @param {string} searchQuery
13+
* @returns {Promise} a promise to enter the search values
14+
*/
15+
preformSearch: function (searchQuery) {
1116

1217
var selector = page.googleSearch.elements.searchInput;
1318

14-
return driver.findElement(selector).sendKeys(keywords, selenium.Key.ENTER);
19+
// return a promise so the calling function knows the task has completed
20+
return driver.findElement(selector).sendKeys(searchQuery, selenium.Key.ENTER);
1521
}
1622
};

0 commit comments

Comments
 (0)