Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 4: Topic 5 #3

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Cloned feature/alerts-and-frames into feature/alerts-and-frames-with-…
…plugin
aasimsyed committed Apr 13, 2024
commit 505bb2654efce1e20278560da2aa5b62b8ef69ce
2 changes: 2 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
supportFile: 'cypress/support/commands.js',
specPattern: 'cypress/integration/**/*.spec.js',
setupNodeEvents(on, config) {
// implement node event listeners here
},
28 changes: 27 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -22,4 +22,30 @@
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

// visitWithAdBlocker: Visits a page and blocks ads
Cypress.Commands.add('visitWithAdBlocker', (url) => {
// Setup intercepts
cy.intercept('https://pagead2.googlesyndication.com/**', {statusCode: 200, body: ''}).as('blockAds');
cy.intercept('https://www.googletagservices.com/tag/js/gpt.js', {statusCode: 200, body: ''}).as('blockGpt');
cy.intercept('https://www.googletagmanager.com/gtm.js?id=GTM-MX8DD4S', {statusCode: 200, body: ''}).as('blockGtm');
cy.intercept('https://cdn.ad.plus/player/adplus.js', {statusCode: 200, body: ''}).as('blockAdPlus');
cy.intercept('**/*.gif', {statusCode: 200, body: ''}).as('blockGif');
cy.intercept('**/usermatch.gif**', {statusCode: 200, body: ''}).as('blockUserMatch');
cy.intercept('**/merge**', {statusCode: 200, body: ''}).as('blockMerge');
cy.intercept('**/*.js', (req) => {
if (req.url.includes('google') || req.url.includes('adsbygoogle')) {
req.destroy();
}
}).as('blockScripts');

// Visit the page
cy.visit(url);
});

// enterFrame: Enters a frame by its selector
Cypress.Commands.add('enterFrame', (selector) => {
return cy.get(selector).its('0.contentDocument.body').should('not.be.undefined')
.then(cy.wrap);
});