|
|
@@ -143,7 +143,7 @@ const modalClosed = async text => { |
|
|
|
|
|
|
|
const shouldSeeText = async text => { |
|
|
|
const { page } = scope.context; |
|
|
|
const content = await page.content(); |
|
|
|
const content = String(await page.$eval('*', el => el.innerText)).replace(/[\t\s\n\r]+/g, ' '); |
|
|
|
if (!content.includes(text)) |
|
|
|
throw new Error( |
|
|
|
`Expected page to contain text: ${text}, but page contains only: ${content}` |
|
|
@@ -152,18 +152,22 @@ const shouldSeeText = async text => { |
|
|
|
|
|
|
|
const shouldSeeTextAt = async (text, wrapper) => { |
|
|
|
const { page } = scope.context; |
|
|
|
const [el] = await page.$x(`//*[contains(@class, '${selectors.wrappers[wrapper]}')]//*[contains(., '${text}')]`); |
|
|
|
if (!el) { |
|
|
|
const content = await page.content(); |
|
|
|
const content = await page.evaluate(selector => { |
|
|
|
const elements = document.querySelectorAll(selector); |
|
|
|
if (!elements) return ''; |
|
|
|
const aTexts = [...elements].map(el => el.textContent); |
|
|
|
return aTexts.join(' | ').replace(/[\t\s\n\r]+/g, ' '); |
|
|
|
}, `.${selectors.wrappers[wrapper]}`); |
|
|
|
if (!content.includes(text)) { |
|
|
|
throw new Error( |
|
|
|
`Expected wrapper ${wrapper} to contain text: ${text}, but page contains only: ${content}` |
|
|
|
`Expected wrapper ${wrapper} to contain text: ${text}, but it contains only: ${content}` |
|
|
|
); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const shouldNotSeeText = async text => { |
|
|
|
const { page } = scope.context; |
|
|
|
const content = await page.content(); |
|
|
|
const content = String(await page.$eval('*', el => el.innerText)).replace(/[\t\s\n\r]+/g, ' '); |
|
|
|
if (content.includes(text)) |
|
|
|
throw new Error( |
|
|
|
`Expected page to not contain text: ${text}, but page contains: ${content}` |
|
|
@@ -172,11 +176,15 @@ const shouldNotSeeText = async text => { |
|
|
|
|
|
|
|
const shouldNotSeeTextAt = async (text, wrapper) => { |
|
|
|
const { page } = scope.context; |
|
|
|
const [el] = await page.$x(`//*[contains(@class, '${selectors.wrappers[wrapper]}')]//*[contains(., '${text}')]`); |
|
|
|
if (el) { |
|
|
|
const content = await page.content(); |
|
|
|
const content = await page.evaluate(selector => { |
|
|
|
const elements = document.querySelectorAll(selector); |
|
|
|
if (!elements) return ''; |
|
|
|
const aTexts = [...elements].map(el => el.innerText); |
|
|
|
return aTexts.join(' | ').replace(/[\t\s\n\r]+/g, ' '); |
|
|
|
}, `.${selectors.wrappers[wrapper]}:not(.sr-only)`); |
|
|
|
if (content.includes(text)) { |
|
|
|
throw new Error( |
|
|
|
`Expected wrapper ${wrapper} to not contain text: ${text}, but page contains: ${content}` |
|
|
|
`Expected wrapper ${wrapper} to not contain text: ${text}, but it contains: ${content}` |
|
|
|
); |
|
|
|
} |
|
|
|
}; |