What I need:
Have an E2E Test in CodeceptJS with Nightmare as Main Helper verify the existence of an element, and depending on the result, continue doing a series of actions or others.
Sample code:
class EventsHelper extends Helper {
isExistsElement(selector) {
let browser = this.helpers['Nightmare'].browser;
return browser.evaluate((selector) => {
return new Promise(resolve => {
let element = document.querySelector(selector);
resolve(element || false);
});
}, selector);
}
}
module.exports = EventsHelper;
Scenario('Test 1', async (I) => {
const isButtonRendered = await I.isExistsElement('#button');
if (isButtonRendered) {
I.see('Message that is displayed only if the button exists.');
I.click('#button');
} else {
I.see('Alternative message that appears if this button does not exist.');
}
});
The current result of this example code is: - If the button exists.
Evaluation timed out after 30000msec. Are you calling done() or resolving your promises?
- Otherwise the button does not exist: PASS.
I am open to suggestions, corrections or different ideas to solve this problem. Thank you all! (and excuse me if my English is not very clear).