@@ -114,33 +114,40 @@ An example page object:
114114
115115module .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
132139And 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
0 commit comments