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

cenários de broken links - images adicionados #12

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require('dotenv').config();

export default defineConfig({
projectId: process.env.CYPRESS_PROJECT_ID,
chromeWebSecurity: false,
e2e: {
pageLoadTimeout: 10000,
baseUrl: 'https://demoqa.com',
Expand Down
26 changes: 26 additions & 0 deletions cypress/e2e/elements/brokenLinks.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import BrokenLinksPage from '@pageObject/brokenLinks/BrokenLinksPage';
import ElementsLinks from '@enum/links/Elements';

const brokenLinks = new BrokenLinksPage();

beforeEach(() => {
cy.visitarToolsQA(ElementsLinks.BrokenLinks);
});

describe('Broken Links', () => {
it('Check Valid Image', () => {
brokenLinks.checkValidImage();
});

it.skip('Check Broken Image', () => {
brokenLinks.checkBrokenImage();
});

it('Check Valid Link', () => {
brokenLinks.checkValidLink();
});

it('Check Broken Link - 500 status code', () => {
brokenLinks.checkInvalidLink();
});
});
9 changes: 9 additions & 0 deletions cypress/pageObjects/brokenLinks/BrokenLinksLocators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const BrokenLinksLocators = {
validImage: 'div>img[src="/images/Toolsqa.jpg"]',
brokenImage: 'div>img[src="/images/Toolsqa_1.jpg"]',
validLinkXpath: '//a[contains(.,"Click Here for Valid Link")]',
invalidLinkXpath: '//a[contains(.,"Click Here for Broken Link")]',
pragrafoBrokenLink: 'div.example>p',
};

export default BrokenLinksLocators;
47 changes: 47 additions & 0 deletions cypress/pageObjects/brokenLinks/BrokenLinksPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import locators from './BrokenLinksLocators';

class BrokenLinksPage {
checkValidImage() {
cy
.get(locators.validImage)
.should('exist')
.and('be.visible')
//@ts-ignore
.and(($img) => expect($img[0].naturalWidth).to.be.gt(0));
}

checkBrokenImage() {
cy
.get(locators.brokenImage)
.should('exist')
.and('be.visible')
//@ts-ignore
.and(($img) => expect($img[0].naturalWidth).to.be.gt(0));
}

checkValidLink() {
cy
.xpath(locators.validLinkXpath)
.click()
.then(
//@ts-ignore com o {timeout}
() => {
cy.url().should('be.contains', Cypress.config('baseUrl'));
},
{ timeout: 10000 }
);
}

checkInvalidLink() {
cy
.xpath(locators.invalidLinkXpath)
.click()
.then(() => {
cy
.get(locators.pragrafoBrokenLink)
.should('contain.text', '500 status code');
});
}
}

export default BrokenLinksPage;
1 change: 1 addition & 0 deletions cypress/support/Enum/links/Elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum Elements {
WebTables = '/webtables',
Buttons = '/buttons/',
Links = '/links',
BrokenLinks = '/broken',
}

export default Elements;