First of all here is my code....
describe('Details page', function () {
//
// Email Field
//
it('Entering Email', function (done) {
browser.driver
.then(() => utils.presenceOf(detailsSpecs.getEmail()))
.then(() => utils.sendKeys(detailsSpecs.getEmail(), userData.email))
.then(() => done());
});
//
// Click Next Step Button
//
it('Clicking Next Step button', function (done) {
browser.driver
.then(() => utils.click(detailsSpecs.getNextStepButton()))
.then(() => done());
});
//
// Wait for stock to fully load
//
it('Waiting for stock to fully load', function (done) {
setTimeout(function () {
done();
}, 5000);
});
if (element.all(by.className("generic-error-heading")).first()) {
it('Clicked all remove button', function (done) {
let allBtns = detailsSpecs.getRemoveButtonDesktop();
allBtns.count()
.then(function (countElement) {
console.log('Find buttons: ', countElement)
for (let i = 0; i < countElement; i++) { // let variables are scoped to the immediate enclosing block denoted by { }
utils.click(detailsSpecs.getRemoveButtonDesktop().first())
browser.sleep(1000) // sleep 1s
}
})
.then(() => {
done();
})
});
//
// Click Next Step Button - Not needed if two above is returning 0
//
it('Clicking Next Step button', function (done) {
browser.driver
.then(() => utils.elementToBeClickable(detailsSpecs.getNextStepButton()))
.then(() => utils.click(detailsSpecs.getNextStepButton()))
.then(() => done());
});
} else {
it('DONE', function (done) {
browser.driver
.then(() => console.log("YES"))
.then(() => done());
});
}
});
I have been trying to speed up my test cases by skipping if a element is not presented. If its not presented then we skip everything inside the if-statement else we do the test cases.
I have a element that I want to look after which is element.all(by.className("generic-error-heading")).first()
(Should be 2 but for me its just matters that it is presented or not)
My problem is that right now it just skips it and does the Else statement even though the element is presented in the HTML.
My question is, How can I make a correct if-else statement where it actually do the if-statements if there is a element presented else skip?