Browse Source

fixed should(Not)SeeTextAt actions in the tests

master
ChiefRed 3 years ago
parent
commit
bf3f139d9f
4 changed files with 23 additions and 14 deletions
  1. +2
    -2
      features/config.js
  2. +1
    -1
      features/feedback.feature
  3. +18
    -10
      features/support/actions.js
  4. +2
    -1
      src/components/forms/FormFeedback.jsx

+ 2
- 2
features/config.js View File

module.exports = { module.exports = {
port: 8989, port: 8989,


headless: false,
//headless: false,
slowMo: 0, slowMo: 0,


//close: true,
close: true,
}; };

+ 1
- 1
features/feedback.feature View File

* button "Send" at "Feedback form" is enabled * button "Send" at "Feedback form" is enabled


# reCaptcha badge replacement warning # reCaptcha badge replacement warning
* see "This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply." at "Feedback form"
* see "This site is protected by invisible reCAPTCHA and the Google Privacy Policy and Terms of Service apply." at "Feedback form"

+ 18
- 10
features/support/actions.js View File



const shouldSeeText = async text => { const shouldSeeText = async text => {
const { page } = scope.context; 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)) if (!content.includes(text))
throw new Error( throw new Error(
`Expected page to contain text: ${text}, but page contains only: ${content}` `Expected page to contain text: ${text}, but page contains only: ${content}`


const shouldSeeTextAt = async (text, wrapper) => { const shouldSeeTextAt = async (text, wrapper) => {
const { page } = scope.context; 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( 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 shouldNotSeeText = async text => {
const { page } = scope.context; 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)) if (content.includes(text))
throw new Error( throw new Error(
`Expected page to not contain text: ${text}, but page contains: ${content}` `Expected page to not contain text: ${text}, but page contains: ${content}`


const shouldNotSeeTextAt = async (text, wrapper) => { const shouldNotSeeTextAt = async (text, wrapper) => {
const { page } = scope.context; 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( 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}`
); );
} }
}; };

+ 2
- 1
src/components/forms/FormFeedback.jsx View File

{(!formik.isValid || !formik.dirty) {(!formik.isValid || !formik.dirty)
? <div className="error text-center text-sm text-red-700 mt-1 mr-1">Please fill all necessary form fields</div> ? <div className="error text-center text-sm text-red-700 mt-1 mr-1">Please fill all necessary form fields</div>
: <div className="text-gray-900 text-center text-sm mt-1 mr-1"> : <div className="text-gray-900 text-center text-sm mt-1 mr-1">
<div>This site is protected by reCAPTCHA and the Google </div>
<div>This site is protected by invisible reCAPTCHA and </div>
<div> <div>
<span> the Google </span>
<a href="https://policies.google.com/privacy" className="mx-1 hover:underline" rel="noopener noreferrer nofollow" target="_blank">Privacy Policy</a> <a href="https://policies.google.com/privacy" className="mx-1 hover:underline" rel="noopener noreferrer nofollow" target="_blank">Privacy Policy</a>
<span> and </span> <span> and </span>
<a href="https://policies.google.com/terms" className="mx-1 hover:underline" rel="noopener noreferrer nofollow" target="_blank">Terms of Service</a> apply. <a href="https://policies.google.com/terms" className="mx-1 hover:underline" rel="noopener noreferrer nofollow" target="_blank">Terms of Service</a> apply.

Loading…
Cancel
Save