I just do afterTest hook (depends on your test runner), where i set everything back to its starting state, so if i even forgot to switch back in test, or test crashed for some reason on any point - next tests wont be affected:
My code for jasmine. Protractor config:
onPrepare() {
...
afterEach(function () {
// Setting ignoreSychronization back to true, in case it was changed in tests
browser.waitForAngularEnabled(true);
// Setting back to default frame. In case test was working in iframe
browser.switchTo().defaultContent();
// This depends on your architecture. We do clean run for each test.
browser.manage().deleteAllCookies();
browser.executeScript('window.sessionStorage.clear(); window.localStorage.clear();').then(
undefined,
function (err) {
// Errors will be thrown when browser is on default data URL.
// Session and Local storage is disabled for data URLs
// This callback is needed to not crash test, and just ignore error.
});
browser.manage().timeouts().implicitlyWait(5000); // I even rewrite implicit wait back to default value, in case i touched it in tests
// Also you might want to clear indexdb storage after tests.
})
In real code i would wrap this into function called resetBrowser
or something like this. Also you can return promise from it, and then return that promise from hook - so new test wont start until promise resolved
withoutSync(() => { ... })
that turns it off at the start and back on at the end - this can then wrap whole expectation callbacks or just parts of them. Then you only set the attribute directly in that one function.it()
s in a row..thanks.afterEach()
orafterAll()
of every test. Turning the sync on in a global "before each" or "after each" sounds like it should work..thanks.