diff --git a/docs/advanced.md b/docs/advanced.md index c89d6500a..9ffc99438 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -367,7 +367,7 @@ Scenario('should create data via v2 version of API', (I) => { ``` Config can also be set by a function, in this case you can get a test object and specify config values based on it. -This is very useful when running tests against cloud providers, like BrowserStack. +This is very useful when running tests against cloud providers, like BrowserStack. This function can also be asynchronous. ```js Scenario('should report to BrowserStack', (I) => { diff --git a/lib/interfaces/scenarioConfig.js b/lib/interfaces/scenarioConfig.js index 568ab7d6b..05cbf8cd7 100644 --- a/lib/interfaces/scenarioConfig.js +++ b/lib/interfaces/scenarioConfig.js @@ -58,13 +58,13 @@ class ScenarioConfig { * Configures a helper. * Helper name can be omitted and values will be applied to first helper. */ - config(helper, obj) { + async config(helper, obj) { if (!obj) { obj = helper; helper = 0; } if (typeof obj === 'function') { - obj = obj(this.test); + obj = await obj(this.test); } if (!this.test.config) { this.test.config = {}; diff --git a/test/acceptance/config_test.js b/test/acceptance/config_test.js index 38128868e..090671190 100644 --- a/test/acceptance/config_test.js +++ b/test/acceptance/config_test.js @@ -29,3 +29,11 @@ Scenario('change config 5 @WebDriverIO @Puppeteer @Protractor @Nightmare', (I) = I.dontSeeInCurrentUrl('github.com'); I.seeInCurrentUrl('google.com'); }); + +Scenario('change config 6 @WebDriverIO @Puppeteer @Protractor @Nightmare', (I) => { + I.amOnPage('/'); + I.seeInCurrentUrl('github.com'); +}).config(async (test) => { + await new Promise(r => setTimeout(r, 50)); + return { url: 'https://github.com' }; +});