Skip to content

Commit ab24a51

Browse files
authored
Waiter fixes (#947)
* updated waitUntilExists functionality * deprecated waitUntilExist, waitForStaleness
1 parent c717e61 commit ab24a51

File tree

5 files changed

+65
-32
lines changed

5 files changed

+65
-32
lines changed

docs/pageobjects.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ At initialization you were asked to create custom steps file. If you accepted th
231231
See how `login` method can be added to `I`:
232232

233233
```js
234-
'use strict';
235-
// in this file you can append custom step methods to 'I' object
236-
237234
module.exports = function() {
238235
return actor({
239236

@@ -248,4 +245,36 @@ module.exports = function() {
248245

249246
Please notice that instead of `I` you should use `this` in current context.
250247

248+
## Dependency Injection
249+
250+
### Configuration
251+
252+
All objects described here are injected with Dependency Injection. The similar way it happens in AngularJS framework.
253+
If you want an object to be injected in scenario by its name add it to configuration:
254+
255+
```js
256+
"include": {
257+
"I": "./custom_steps.js",
258+
"Smth": "./pages/Smth.js",
259+
"loginPage": "./pages/Login.js",
260+
"signinFragment": "./fragments/Signin.js"
261+
}
262+
```
263+
264+
Now this objects can be retrieved by the name specified in configuration.
265+
CodeceptJS generator commands (like `codeceptjs gpo`) will update configuration for you.
266+
267+
### Dynamic Injection
268+
269+
You can inject objects per test by calling `injectDependencies` function on Scenario:
270+
271+
```js
272+
Scenario('search @grop', (I, Data) => {
273+
I.fillField('Username', Data.username);
274+
I.pressKey('Enter');
275+
}).injectDependencies({ Data: require('./data.js') });
276+
```
277+
278+
This requires `./data.js` module and assigns it to `Data` argument in a test.
279+
251280
### done()

docs/webapi/waitForStalenessOf.mustache renamed to docs/webapi/waitForDetached.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Waits for an element to become not attached to the DOM on a page (by default wai
22
Element can be located by CSS or XPath.
33

44
```
5-
I.waitForStalenessOf('#popup');
5+
I.waitForDetached('#popup');
66
```
77

88
@param locator element located by CSS|XPath|strict locator

docs/webapi/waitUntilExists.mustache

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/helper/Protractor.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -899,19 +899,30 @@ class Protractor extends Helper {
899899
return this.browser.wait(EC.presenceOf(el), aSec * 1000);
900900
}
901901

902+
async waitUntilExists(locator, sec = null) {
903+
console.log(`waitUntilExists deprecated:
904+
* use 'waitForElement' to wait for element to be attached
905+
* use 'waitForDetached to wait for element to be removed'`);
906+
return this.waitForDetached(locator, sec);
907+
}
908+
902909
/**
903-
* {{> ../webapi/waitUntilExists }}
910+
* {{> ../webapi/waitForDetached }}
904911
*/
905-
waitUntilExists(locator, sec = null) {
912+
async waitForDetached(locator, sec = null) {
906913
const aSec = sec || this.options.waitForTimeout;
907914
const el = global.element(guessLocator(locator) || global.by.css(locator));
908915
return this.browser.wait(EC.not(EC.presenceOf(el)), aSec * 1000);
909916
}
910917

911918
/**
912919
* Waits for element to become clickable for number of seconds.
920+
*
921+
* ```js
922+
* I.waitForClickable('#link');
923+
* ```
913924
*/
914-
waitForClickable(locator, sec = null) {
925+
async waitForClickable(locator, sec = null) {
915926
const aSec = sec || this.options.waitForTimeout;
916927
const el = global.element(guessLocator(locator) || global.by.css(locator));
917928
return this.browser.wait(EC.elementToBeClickable(el), aSec * 1000);
@@ -920,7 +931,7 @@ class Protractor extends Helper {
920931
/**
921932
* {{> ../webapi/waitForVisible }}
922933
*/
923-
waitForVisible(locator, sec = null) {
934+
async waitForVisible(locator, sec = null) {
924935
const aSec = sec || this.options.waitForTimeout;
925936
const el = global.element(guessLocator(locator) || global.by.css(locator));
926937
return this.browser.wait(EC.visibilityOf(el), aSec * 1000);
@@ -929,23 +940,23 @@ class Protractor extends Helper {
929940
/**
930941
* {{> ../webapi/waitForInvisible }}
931942
*/
932-
waitForInvisible(locator, sec = null) {
943+
async waitForInvisible(locator, sec = null) {
933944
const aSec = sec || this.options.waitForTimeout;
934945
const el = global.element(guessLocator(locator) || global.by.css(locator));
935946
return this.browser.wait(EC.invisibilityOf(el), aSec * 1000);
936947
}
937948

938-
/**
939-
* {{> ../webapi/waitForStalenessOf }}
940-
*/
941-
waitForStalenessOf(locator, sec = null) {
949+
async waitForStalenessOf(locator, sec = null) {
950+
console.log(`waitForStalenessOf deprecated.
951+
* Use waitForDetached to wait for element to be removed from page
952+
* Use waitForInvisible to wait for element to be hidden on page`);
942953
return this.waitForInvisible(locator, sec);
943954
}
944955

945956
/**
946957
* {{> ../webapi/waitForText }}
947958
*/
948-
waitForText(text, sec = null, context = null) {
959+
async waitForText(text, sec = null, context = null) {
949960
if (!context) {
950961
context = this.context;
951962
}

lib/helper/WebDriverIO.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,13 +1419,11 @@ class WebDriverIO extends Helper {
14191419
}, aSec * 1000, `element (${locator}) still not present on page after ${aSec} sec`);
14201420
}
14211421

1422-
/**
1423-
* {{> ../webapi/waitUntilExists }}
1424-
* Appium: support
1425-
*/
14261422
async waitUntilExists(locator, sec = null) {
1427-
const aSec = sec || this.options.waitForTimeout;
1428-
return this.browser.waitForExist(locator, aSec * 1000);
1423+
console.log(`waitUntilExists deprecated:
1424+
* use 'waitForElement' to wait for element to be attached
1425+
* use 'waitForDetached to wait for element to be removed'`);
1426+
return this.waitForStalenessOf(locator, sec);
14291427
}
14301428

14311429

@@ -1594,11 +1592,16 @@ class WebDriverIO extends Helper {
15941592
return this.waitForInvisible(locator, sec);
15951593
}
15961594

1595+
async waitForStalenessOf(locator, sec = null) {
1596+
console.log('waitForStalenessOf deprecated. Use waitForDetached instead');
1597+
return this.waitForDetached(locator, sec);
1598+
}
1599+
15971600
/**
1598-
* {{> ../webapi/waitForStalenessOf }}
1601+
* {{> ../webapi/waitForDetached }}
15991602
* Appium: support
16001603
*/
1601-
async waitForStalenessOf(locator, sec = null) {
1604+
async waitForDetached(locator, sec = null) {
16021605
const aSec = sec || this.options.waitForTimeout;
16031606
return this.browser.waitUntil(async () => {
16041607
const res = await this.browser.elements(withStrictLocator.call(this, locator));

0 commit comments

Comments
 (0)