When using manage().window().getSize()
in Protractor, it must be within the control flow of Protractor. If you attempt to call it outside of before*()
, after*()
, or it()
contexts, the control flow may not be initialized yet.
One solution is to include your condition inside the test itself:
function getWidth() {
return browser.manage().window().getSize().then(function(size) {
return size.width
});
}
it ('test following', () => {
getWidth().then(function (width) {
if (width > 500) {
// test something
}
else {
console.log("Skipped testing something");
}
});
})
Alternatively, depending on your specific use case, you can set the browser window dimensions for a particular capability in your Protractor configuration (example). By specifying tests to run for this capability, you can avoid needing to perform this check within each individual test.