Skip to content

Commit f9aedde

Browse files
author
John Doherty
committed
updated google-search-steps to include comments and updated related readme section"
1 parent 6a4f416 commit f9aedde

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

README.MD

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,25 @@ The browser automatically closes after each scenario to ensure the next scenario
6060

6161
Step definitions act as the glue between features files and the actual system under test.
6262

63-
_To avoid confusion **always** call the callback/done method within your step definition to let cucumber know when you're done._
63+
_To avoid confusion **always** return a JavaScript promise your step definition in order to let cucumber know when your task has completed._
6464

6565
```javascript
66-
// ./step-definitions/google-search.js
66+
// ./step-definitions/google-search-steps.js
6767

6868
module.exports = function () {
6969

70-
this.When(/^I search Google for "([^"]*)"$/, function (searchQuery, done) {
71-
72-
driver.get('http://www.google.com');
73-
74-
var input = driver.findElement(by.name('q'));
70+
this.Then(/^I should see some results$/, function () {
7571

76-
input.sendKeys(searchQuery);
77-
input.sendKeys(selenium.Key.ENTER);
72+
// driver wair returns a promise so return that
73+
return driver.wait(until.elementsLocated(by.css('div.g')), 10000).then(function(){
7874

79-
done(); // <<- let cucumber know you're done
80-
});
81-
82-
this.Then(/^I should see some results$/, function (done) {
83-
84-
driver.wait(until.elementsLocated(by.css('div.g')), 10000);
75+
// return the promise of an element to the following then.
76+
return driver.findElements(by.css('div.g'));
77+
})
78+
.then(function (elements) {
8579

86-
driver.findElements(by.css('div.g')).then(function (elements) {
80+
// verify this element has children
8781
expect(elements.length).to.not.equal(0);
88-
89-
done(); // <<- let cucumber know you're done
9082
});
9183
});
9284
};

step-definitions/google-search-steps.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@ module.exports = function () {
22

33
this.When(/^I search Google for "([^"]*)"$/, function (searchQuery) {
44

5-
return driver.get('http://www.google.com').then(function(){
5+
return helpers.loadPage('http://www.google.com').then(function() {
6+
7+
// use a method on the page object which also returns a promise
68
return page.googleSearch.preformSearch(searchQuery);
79
})
810
});
911

1012
this.Then(/^I should see some results$/, function () {
1113

12-
return driver.wait(until.elementsLocated(by.css('div.g')), 10000).then(function(){
14+
// driver wair returns a promise so return that
15+
return driver.wait(until.elementsLocated(by.css('div.g')), 10000).then(function() {
16+
17+
// return the promise of an element to the following then.
1318
return driver.findElements(by.css('div.g'));
1419
})
1520
.then(function (elements) {
21+
22+
// verify this element has children
1623
expect(elements.length).to.not.equal(0);
17-
});
24+
});
1825
});
1926
};

0 commit comments

Comments
 (0)