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

Links, @alias para os path, #11

Merged
merged 8 commits into from
Aug 30, 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
4 changes: 2 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { defineConfig } from 'cypress';
import 'module-alias/register';

require('dotenv').config();

export default defineConfig({
Expand All @@ -7,11 +9,9 @@ export default defineConfig({
pageLoadTimeout: 10000,
baseUrl: 'https://demoqa.com',
setupNodeEvents(on, config) {
// implement node event listeners here
on('task', {
pause(ms) {
return new Promise((resolve) => {
// tasks should not resolve with undefined
setTimeout(() => resolve(null), ms);
});
},
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/elements/apresentacao.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ElementsLink from '../../support/Enum/links/Elements';
import ElementsLink from '@enum/links/Elements';

beforeEach(() => {
cy.visitarToolsQA(ElementsLink.Elements);
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/elements/buttons.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ButtonsPage from '../../pageObjects/buttons/ButtonsPage';
import ElementsLink from '../../support/Enum/links/Elements';
import ButtonsPage from '@pageObject/buttons/ButtonsPage';
import ElementsLink from '@enum/links/Elements';

const Buttons = new ButtonsPage();

Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/elements/checkBox.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ElementsLink from '../../support/Enum/links/Elements';
import CheckBoxPage from '../../pageObjects/checkBox/CheckBoxPage';
import CheckBoxText from '../../support/Enum/CheckBoxText';
import ElementsLink from '@enum/links/Elements';
import CheckBoxPage from '@pageObject/checkBox/CheckBoxPage';
import CheckBoxText from '@enum/CheckBoxText';

const CheckBox = new CheckBoxPage();

Expand Down
138 changes: 138 additions & 0 deletions cypress/e2e/elements/links.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import LinksPage from '@pageObject/links/LinksPage';
import ElementsLinks from '@enum/links/Elements';
import Link from '@enum/links/Link';

const Links = new LinksPage();
const baseUrl = Cypress.config('baseUrl');

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

describe('Open new tab', () => {
describe('Simple Link', () => {
it.only('Check FrontEnd (Opens New Tab)', () => {
Links.getsimpleLink().then(($link) => {
cy.visit(Links.getPropHref($link));
cy.url().should('be.equal', `${baseUrl}/`);
Links.checkRedirectFrontHome();
});
});

it('Check Backend (API)', () => {
Links.getsimpleLink().then(($link) => {
cy.request(Links.getPropHref($link)).as('request');

cy.get('@request').then((response) => {
//@ts-ignore
let urlRecebida = response.allRequestResponses[0]['Request URL'];
//@ts-ignore
Links.expectStatus(response.status, 200);
Links.expectUrl(urlRecebida, `${baseUrl}/`);
});
});
});
});

describe('Dynamic Link', () => {
it('Check FrontEnd (Opens New Tab)', () => {
Links.getDynamicLink().then(($link) => {
cy.visit(Links.getPropHref($link));
cy.url().should('be.equal', `${baseUrl}/`);
Links.checkRedirectFrontHome();
});
});
it('Check Backend (API)', () => {
Links.getDynamicLink().then(($link) => {
cy.request(Links.getPropHref($link)).as('request');

cy.get('@request').then((response) => {
//@ts-ignore
let urlRecebida = response.allRequestResponses[0]['Request URL'];
//@ts-ignore
Links.expectStatus(response.status, 200);
Links.expectUrl(urlRecebida, `${baseUrl}/`);
});
});
});
});
});

describe('Send an api call', () => {
it('Created', () => {
cy.intercept('GET', `**${Link.Created}`).as('intercept');

Links.createdLink();

cy.wait('@intercept').then(({ request, response }) => {
Links.expectUrl(request.url, `${baseUrl}${Link.Created}`);
Links.expectStatus(response?.statusCode, 201);
});
});

it('No Content', () => {
cy.intercept('GET', `**${Link.NoContent}`).as('intercept');

Links.noContentLink();

cy.wait('@intercept').then(({ request, response }) => {
Links.expectUrl(request.url, `${baseUrl}${Link.NoContent}`);
Links.expectStatus(response?.statusCode, 204);
});
});

it('Moved', () => {
cy.intercept('GET', `**${Link.Moved}`).as('intercept');

Links.movedLink();

cy.wait('@intercept').then(({ request, response }) => {
Links.expectUrl(request.url, `${baseUrl}${Link.Moved}`);
Links.expectStatus(response?.statusCode, 301);
});
});

it('Bad Request', () => {
cy.intercept('GET', `**${Link.BadRequest}`).as('intercept');

Links.badRequestLink();

cy.wait('@intercept').then(({ request, response }) => {
Links.expectUrl(request.url, `${baseUrl}${Link.BadRequest}`);
Links.expectStatus(response?.statusCode, 400);
});
});

it('Unauthorized', () => {
cy.intercept('GET', `**${Link.Unauthorized}`).as('intercept');

Links.unauthorizedLink();

cy.wait('@intercept').then(({ request, response }) => {
Links.expectUrl(request.url, `${baseUrl}${Link.Unauthorized}`);
Links.expectStatus(response?.statusCode, 401);
});
});

it('Forbidden', () => {
cy.intercept('GET', `**${Link.Forbidden}`).as('intercept');

Links.forbiddenLink();

cy.wait('@intercept').then(({ request, response }) => {
Links.expectUrl(request.url, `${baseUrl}${Link.Forbidden}`);
Links.expectStatus(response?.statusCode, 403);
});
});

it('Not Found', () => {
cy.intercept('GET', `**${Link.NotFound}`).as('intercept');

Links.notFoundLink();

cy.wait('@intercept').then(({ request, response }) => {
Links.expectUrl(request.url, `${baseUrl}${Link.NotFound}`);
Links.expectStatus(response?.statusCode, 404);
});
});
});
4 changes: 2 additions & 2 deletions cypress/e2e/elements/radioButton.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ElementsLink from '../../support/Enum/links/Elements';
import RadioButtonPage from '../../pageObjects/radioButton/RadioBtnPage';
import ElementsLink from '@enum/links/Elements';
import RadioButtonPage from '@pageObject/radioButton/RadioBtnPage';

const RadioButton = new RadioButtonPage();

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/elements/textBox.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TextBoxPage from '../../pageObjects/textBox/TextBoxPage';
import ElementsLink from '../../support/Enum/links/Elements';
import TextBoxPage from '@pageObject/textBox/TextBoxPage';
import ElementsLink from '@enum/links/Elements';

const TextBox = new TextBoxPage();
const usuarioValidoFixture = '/usuarios/valido';
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/elements/webTables.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import WebTablesPage from '../../pageObjects/webTables/WebTablePage';
import ElementsLink from '../../support/Enum/links/Elements';
import WebTablesPage from '@pageObject/webTables/WebTablePage';
import ElementsLink from '@enum/links/Elements';

const WebTables = new WebTablesPage();

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HomePage from '../pageObjects/home/HomePage';
import HomeLinks from '../support/Enum/links/Home';
import HomePage from '@pageObject/home/HomePage';
import HomeLinks from '@enum/links/Home';

const Home = new HomePage();

Expand Down
2 changes: 1 addition & 1 deletion cypress/pageObjects/buttons/ButtonsPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import locator from './ButtonsLocatos';
import mensagens from '../../support/Enum/ButtonsMsg';
import mensagens from '@enum/ButtonsMsg';

class ButtonsPage {
dbClickButton(dbClick: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion cypress/pageObjects/checkBox/CheckBoxPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CheckBoxNode from '../../support/Types/CheckBoxNode';
import CheckBoxNode from '@type/CheckBoxNode';
import locators from './CheckBoxLocators';

class CheckBoxPage {
Expand Down
2 changes: 2 additions & 0 deletions cypress/pageObjects/home/HomeLocators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const HomeLocators = {
homeBanner: (link: string | undefined) => {
return `div.home-banner a[href="${link}"]`;
},

// TODO: mudar o tipo para os tipos de card existentes 'Elements', 'Forms', etc
cardXpath: (title: string) => {
return `//div[contains(@class, 'card-body')][contains(.,'${title}')]`;
},
Expand Down
2 changes: 1 addition & 1 deletion cypress/pageObjects/home/HomePage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import locators from './HomeLocators';
import Cards from '../../support/Enum/Cards';
import Cards from '@enum/Cards';

class HomePage {
link?: string;
Expand Down
13 changes: 13 additions & 0 deletions cypress/pageObjects/links/LinksLocators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const LinksLocators = {
simple: 'p>a#simpleLink',
dynamic: 'p>a#dynamicLink',
created: 'p>a#created',
noContent: 'p>a#no-content',
moved: 'p>a#moved',
badRequest: 'p>a#bad-request',
unauthorized: 'p>a#unauthorized',
forbidden: 'p>a#forbidden',
notFound: 'p>a#invalid-url',
};

export default LinksLocators;
63 changes: 63 additions & 0 deletions cypress/pageObjects/links/LinksPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import locators from './LinksLocators';
import homeLocators from '@pageObject/home/HomeLocators';
import Cards from '@enum/Cards';

class LinksPage {
getsimpleLink() {
return cy.get(locators.simple).click();
}

getDynamicLink() {
return cy.get(locators.dynamic).click();
}

getPropHref($link: JQuery<HTMLElement>) {
return $link.prop('href');
}

createdLink() {
cy.get(locators.created).click();
}

noContentLink() {
cy.get(locators.noContent).click();
}

movedLink() {
cy.get(locators.moved).click();
}

badRequestLink() {
cy.get(locators.badRequest).click();
}

unauthorizedLink() {
cy.get(locators.unauthorized).click();
}

forbiddenLink() {
cy.get(locators.forbidden).click();
}

notFoundLink() {
cy.get(locators.notFound).click();
}

expectStatus(statusRecebido: number | undefined, cod: number) {
expect(statusRecebido).be.equal(cod);
}

expectUrl(urlRecebida: string | undefined, urlEsperada: string) {
expect(urlRecebida).be.equal(urlEsperada);
}

expectRequestUrl(requestUrl: string, urlEsperada: string) {
expect(requestUrl).be.equal(urlEsperada);
}

checkRedirectFrontHome() {
cy.xpath(homeLocators.cardXpath(Cards.Elements)).should('be.visible');
}
}

export default LinksPage;
2 changes: 1 addition & 1 deletion cypress/pageObjects/textBox/TextBoxPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Colors from '../../support/Enum/Colors';
import Colors from '@enum/Colors';
import locators from './TextBoxLocators';

class ElementsPage {
Expand Down
1 change: 1 addition & 0 deletions cypress/support/Enum/links/Elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum Elements {
RadioButton = '/radio-button',
WebTables = '/webtables',
Buttons = '/buttons/',
Links = '/links',
}

export default Elements;
11 changes: 11 additions & 0 deletions cypress/support/Enum/links/Link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enum Links {
Created = '/created',
NoContent = '/no-content',
Moved = '/moved',
BadRequest = '/bad-request',
Unauthorized = '/unauthorized',
Forbidden = '/forbidden',
NotFound = '/invalid-url',
}

export default Links;
6 changes: 3 additions & 3 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Import commands.js using ES2015 syntax:
import './commands';

require('@cypress/xpath');

beforeEach(() => {
cy.session(
'performance',
() => {
cy.visit('/', { timeout: 100000 });
},
{ cacheAcrossSpecs: true }
}
// { cacheAcrossSpecs: true }
);
});

Expand Down
Loading