Skip to content

Commit

Permalink
[] Add tests for click and hover in iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
istateside committed Feb 18, 2021
1 parent b3e50ee commit 0b33d92
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cypress/integration/click.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,33 @@ describe("cy.realClick", () => {
});
});
});

describe('iframe behavior', () => {
beforeEach(() => {
cy.visit('./cypress/fixtures/iframe-page.html');
});

it('clicks elements inside iframes', () => {
cy.get('iframe').then(($firstIframe) => {
return cy.wrap($firstIframe.contents().find('iframe'));
}).then(($secondIframe) => {
return cy.wrap($secondIframe.contents().find('body'));
}).within(() => {
cy.get('#target').contains('clicked').should('not.exist');
cy.get('#target').realClick().contains('clicked').should('exist');
});
});

it('clicks elements inside transformed iframes', () => {
cy.get('iframe').then(($firstIframe) => {
$firstIframe.css('transform', 'scale(.5)');
return cy.wrap($firstIframe.contents().find('iframe'));
}).then(($secondIframe) => {
$secondIframe.css('transform', 'scale(.75)');
return cy.wrap($secondIframe.contents().find('body'));
}).within(() => {
cy.get('#target').contains('clicked').should('not.exist');
cy.get('#target').realClick().contains('clicked').should('exist');
});
});
});
40 changes: 40 additions & 0 deletions cypress/integration/hover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,43 @@ describe("cy.realHover", () => {
});
});
});

describe('iframe behavior', () => {
beforeEach(() => {
cy.visit('./cypress/fixtures/iframe-page.html');
});

it('hovers elements inside iframes', () => {
cy.get('iframe').then(($firstIframe) => {
return cy.wrap($firstIframe.contents().find('iframe'));
}).then(($secondIframe) => {
return cy.wrap($secondIframe.contents().find('body'));
}).within(() => {
cy.get('#target').then(($target) => {
expect($target.css('background-color')).to.equal('rgb(0, 128, 0)');
});

cy.get('#target').realHover().then(($target) => {
expect($target.css('background-color')).to.equal('rgb(255, 192, 203)');
});
});
});

it('hovers elements inside transformed iframes', () => {
cy.get('iframe').then(($firstIframe) => {
$firstIframe.css('transform', 'scale(.5)');
return cy.wrap($firstIframe.contents().find('iframe'));
}).then(($secondIframe) => {
$secondIframe.css('transform', 'scale(.75)');
return cy.wrap($secondIframe.contents().find('body'));
}).within(() => {
cy.get('#target').then(($target) => {
expect($target.css('background-color')).to.equal('rgb(0, 128, 0)');
});

cy.get('#target').realHover().then(($target) => {
expect($target.css('background-color')).to.equal('rgb(255, 192, 203)');
});
});
});
});

0 comments on commit 0b33d92

Please sign in to comment.