I'm trying to verify selector NOT present in cucumberjs / puppeteer. How do you use the throws assertion using cucumber-assert?
I'm working on test automation to support testing an ember front-end application. I'm using cucumberjs, puppeteerjs, and cucumber-assert.
I've used the following before:
if (await page.waitForSelector('[data-test-text-title-refunded-widget-console="true"]')) {
let textContentOfElement = await page.evaluate(() => document.body.querySelector('[data-test-text-title-refunded-widget-console="true"]').textContent);
return assert.equal(textContentOfElement, widgetTitle, `title with text ${ widgetTitle } is not present`);
}
which works when I'm verifying the an element exists and the text is correct. For my current assert, I was using the following throws assert from the cucumber-assert npm package:
assert.throws(someFunctionThatThrows).then(callback);
I'm not sure how to handle the callback function - I have the following so far.
const assert = require('cucumber-assert');
return assert.throws(await page.waitForSelector('[data-test-text-title- import-payment-file-widget-console="true"]'))
.then(function(err) {
});
should I return a fail in the callback?
* UPDATE * I believe I found a different approach to solve my issue. Here it is shoudl anyone else have the same issue in the future.
if (await page.$('[data-test-text-title-import-payment-file-widget-console="true"]', { timeout: settings._30000 }) === null) {
return Promise.resolve();
}
return Promise.reject('Error: The widget is present');