@@ -60,33 +60,25 @@ The browser automatically closes after each scenario to ensure the next scenario
6060
6161Step 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
6868module .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};
0 commit comments