diff --git a/.prettierrc.json b/.prettierrc.json index d50a919..c50384f 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,5 +1,5 @@ { - "trailingComma": "all", + "trailingComma": "none", "tabWidth": 2, "semi": false, "singleQuote": true diff --git a/package.json b/package.json index 008e75c..72d9e5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cypress-ncatestify-plugin", - "version": "2.0.37", + "version": "2.0.38", "description": "NCA TESTIFY commands and tests", "main": "src", "types": "src", diff --git a/src/commands.js b/src/commands.js index 26f66d9..7a95a2e 100644 --- a/src/commands.js +++ b/src/commands.js @@ -41,10 +41,11 @@ import { ttCookieAllAcceptClick } from './commands/tt-cookie-all-accept'; Cypress.Commands.add('ttEveryInternalLinkStatusOk', ttEveryInternalLinkStatusOk); Cypress.Commands.add('ttValidateAllImagesResponseStatusOk', ttValidateAllImagesResponseStatusOk); Cypress.Commands.add('ttEveryInternalLinkIsLoading', ttEveryInternalLinkIsLoading); +// @ts-ignore +Cypress.Commands.add('ttElementExists', ttElementExists); Cypress.Commands.add('ttGetInternalLinks', ttGetInternalLinks); Cypress.Commands.add('ttValidateImprintClickable', ttValidateImprintClickable); Cypress.Commands.add('ttValidateNoGoogleServices', ttValidateNoGoogleServices); -Cypress.Commands.add('ttElementExists', ttElementExists); Cypress.Commands.add('ttRunTestifyBaseTests', ttRunTestifyBaseTests); Cypress.Commands.add('ttAccessibility', ttAccessibility); Cypress.Commands.add('ttValidatePageContent', ttValidatePageContent); @@ -53,3 +54,9 @@ Cypress.Commands.add('ttInvalidPath404', ttInvalidPath404); Cypress.Commands.add('ttValidateLanguageTag', ttValidateLanguageTag); Cypress.Commands.add('ttDetectHttp', ttDetectHttp); Cypress.Commands.add('ttCookieAllAcceptClick', ttCookieAllAcceptClick); +Cypress.Commands.add('ttValidatePageContent', ttValidatePageContent); +Cypress.Commands.add('ttOnlyOneH1', ttOnlyOneH1); +Cypress.Commands.add('ttInvalidPath404', ttInvalidPath404); +Cypress.Commands.add('ttValidateLanguageTag', ttValidateLanguageTag); +Cypress.Commands.add('ttDetectHttp', ttDetectHttp); +Cypress.Commands.add('ttCookieAllAcceptClick', ttCookieAllAcceptClick); diff --git a/src/commands.ts b/src/commands.ts index fce70fd..55bbaa0 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -43,16 +43,17 @@ import { ttCookieAllAcceptClick } from './commands/tt-cookie-all-accept' Cypress.Commands.add('ttEveryInternalLinkStatusOk', ttEveryInternalLinkStatusOk) Cypress.Commands.add( 'ttValidateAllImagesResponseStatusOk', - ttValidateAllImagesResponseStatusOk, + ttValidateAllImagesResponseStatusOk ) Cypress.Commands.add( 'ttEveryInternalLinkIsLoading', - ttEveryInternalLinkIsLoading, + ttEveryInternalLinkIsLoading ) +// @ts-ignore +Cypress.Commands.add('ttElementExists', ttElementExists) Cypress.Commands.add('ttGetInternalLinks', ttGetInternalLinks) Cypress.Commands.add('ttValidateImprintClickable', ttValidateImprintClickable) Cypress.Commands.add('ttValidateNoGoogleServices', ttValidateNoGoogleServices) -Cypress.Commands.add('ttElementExists', ttElementExists) Cypress.Commands.add('ttRunTestifyBaseTests', ttRunTestifyBaseTests) Cypress.Commands.add('ttAccessibility', ttAccessibility) Cypress.Commands.add('ttValidatePageContent', ttValidatePageContent) @@ -61,3 +62,9 @@ Cypress.Commands.add('ttInvalidPath404', ttInvalidPath404) Cypress.Commands.add('ttValidateLanguageTag', ttValidateLanguageTag) Cypress.Commands.add('ttDetectHttp', ttDetectHttp) Cypress.Commands.add('ttCookieAllAcceptClick', ttCookieAllAcceptClick) +Cypress.Commands.add('ttValidatePageContent', ttValidatePageContent) +Cypress.Commands.add('ttOnlyOneH1', ttOnlyOneH1) +Cypress.Commands.add('ttInvalidPath404', ttInvalidPath404) +Cypress.Commands.add('ttValidateLanguageTag', ttValidateLanguageTag) +Cypress.Commands.add('ttDetectHttp', ttDetectHttp) +Cypress.Commands.add('ttCookieAllAcceptClick', ttCookieAllAcceptClick) diff --git a/src/commands/tt-element-exists.js b/src/commands/tt-element-exists.js index a9ef28c..da2ec79 100644 --- a/src/commands/tt-element-exists.js +++ b/src/commands/tt-element-exists.js @@ -1,6 +1,6 @@ export const ttElementExists = (selector) => { cy.log('ttElementExists - NCA TESTIFY'); - cy.window().then(($window) => { - return $window.document.querySelector(selector); + return cy.window().then(($window) => { + return $window.document.querySelector(selector) !== null; }); }; diff --git a/src/commands/tt-element-exists.ts b/src/commands/tt-element-exists.ts index 528fa86..75bb1b0 100644 --- a/src/commands/tt-element-exists.ts +++ b/src/commands/tt-element-exists.ts @@ -1,6 +1,8 @@ -export const ttElementExists = (selector: string): boolean => { +export const ttElementExists = ( + selector: string +): Cypress.Chainable => { cy.log('ttElementExists - NCA TESTIFY') - cy.window().then(($window) => { - return $window.document.querySelector(selector) + return cy.window().then(($window) => { + return $window.document.querySelector(selector) !== null }) } diff --git a/src/commands/tt-validate-imprint-clickable.js b/src/commands/tt-validate-imprint-clickable.js index e257401..b7cecfa 100644 --- a/src/commands/tt-validate-imprint-clickable.js +++ b/src/commands/tt-validate-imprint-clickable.js @@ -1,14 +1,19 @@ +/** + * Validates that the 'impressum' link is clickable and redirects to the correct page. + * @returns A Cypress Chainable that resolves to a boolean indicating whether the link is clickable and redirects to the correct page. + */ export const ttValidateImprintClickable = () => { cy.log('validateImprintClickable - NCA TESTIFY'); - cy.ttElementExists('.sg-cookie-optin-box-footer-links').then((htmlElement) => { - if (htmlElement) { - cy.contains('.sg-cookie-optin-box-footer-links a', 'impressum', { - matchCase: false, - }).click(); - } - else { - cy.wait(5000); - cy.contains('a:visible', 'impressum', { matchCase: false }).click(); - } + if (cy.ttElementExists('.sg-cookie-optin-box-footer-links')) { + cy.contains('.sg-cookie-optin-box-footer-links a', 'impressum', { + matchCase: false + }).click(); + } + else { + cy.wait(5000); + cy.contains('a:visible', 'impressum', { matchCase: false }).click(); + } + return cy.window().then((win) => { + return win.location.href.includes('/impressum'); }); }; diff --git a/src/commands/tt-validate-imprint-clickable.ts b/src/commands/tt-validate-imprint-clickable.ts index 30947fe..e43def6 100644 --- a/src/commands/tt-validate-imprint-clickable.ts +++ b/src/commands/tt-validate-imprint-clickable.ts @@ -1,16 +1,20 @@ -export const ttValidateImprintClickable = () => { +/** + * Validates that the 'impressum' link is clickable and redirects to the correct page. + * @returns A Cypress Chainable that resolves to a boolean indicating whether the link is clickable and redirects to the correct page. + */ +export const ttValidateImprintClickable = (): Cypress.Chainable => { cy.log('validateImprintClickable - NCA TESTIFY') - cy.ttElementExists('.sg-cookie-optin-box-footer-links').then( - (htmlElement) => { - if (htmlElement) { - cy.contains('.sg-cookie-optin-box-footer-links a', 'impressum', { - matchCase: false, - }).click() - } else { - cy.wait(5000) - cy.contains('a:visible', 'impressum', { matchCase: false }).click() - } - }, - ) + if (cy.ttElementExists('.sg-cookie-optin-box-footer-links')) { + cy.contains('.sg-cookie-optin-box-footer-links a', 'impressum', { + matchCase: false + }).click() + } else { + cy.wait(5000) + cy.contains('a:visible', 'impressum', { matchCase: false }).click() + } + + return cy.window().then((win) => { + return win.location.href.includes('/impressum') + }) } diff --git a/src/index.d.ts b/src/index.d.ts index 6375146..4fed82b 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -5,7 +5,7 @@ declare namespace Cypress { ttEveryInternalLinkStatusOk(): void ttEveryInternalLinkIsLoading(): void ttValidateNoGoogleServices(): void - ttElementExists(element: string): void + ttElementExists(element: string): boolean ttRunTestifyBaseTests(): void ttValidateAllImagesResponseStatusOk(): void ttAccessibility(context?: any, options?: any): Chainable diff --git a/update.md b/update.md index 4816e17..5db4c2a 100644 --- a/update.md +++ b/update.md @@ -1,5 +1,13 @@ # Update md file +2.0.38 +Fix typescript errors + +- ttElementExist boolean and null operator. +- ttValidateImprint use new method signature and improve. + 2.0.37 -Add cy.clearAllLocalStorage() to everyInternalLinkIsLoading for better memory handling. -Update npm dependencies. +Do something for the planet + +- Add cy.clearAllLocalStorage() to everyInternalLinkIsLoading for better memory handling. +- Update npm dependencies.