How to override the default timeout for protragraph?

How can I override the default timeout ( defaultTimeoutInterval ) for the it and describe methods in Protractor? By default, it is 2500ms .

+10
source share
2 answers

I myself found the answer.

In config.js :

 jasmineNodeOpts: { defaultTimeoutInterval: 25000 }, 
+17
source

You can override the default timeout in a particular it test using these two functions to override and restore the default value: (Only testing in Chrome)

 import { browser } from 'protractor'; export function DefaultTimeoutOverride(milliseconds: number) { browser.driver.manage().timeouts().setScriptTimeout(milliseconds); } export function DefaultTimeoutRestore() { browser.driver.manage().timeouts().setScriptTimeout(browser.allScriptsTimeout); } 

EDIT

Now I have created a helper function ('itTO') that wraps the Jasmine 'it' statement and automatically applies the timeout :)

 import { browser } from 'protractor'; export function itTO(expectation: string, assertion: (done: DoneFn) => void, timeout: number): void { it(expectation, AssertionWithTimeout(assertion, timeout), timeout); } function AssertionWithTimeout<T extends Function>(fn: T, timeout: number): T { return <any>function(...args) { DefaultTimeoutOverride(timeout); const response = fn(...args); DefaultTimeoutRestore(); return response; }; } function DefaultTimeoutOverride(milliseconds: number) { browser.driver.manage().timeouts().setScriptTimeout(milliseconds); } function DefaultTimeoutRestore() { browser.driver.manage().timeouts().setScriptTimeout(browser.allScriptsTimeout); } 

use like this:

 itTO('should run longer than protractors default', async () => { await delay(14000); }, 15000); const delay = ms => new Promise(res => setTimeout(res, ms)) 
0
source

All Articles