Skip to content

Commit 9ea7e71

Browse files
authored
Merge pull request #4 from MarCassMari/feat/cenarios-item-carrinho
feat/cenarios-fluxos-pages
2 parents ec69d60 + f2d6c0f commit 9ea7e71

File tree

6 files changed

+117
-2
lines changed

6 files changed

+117
-2
lines changed

fluxos/cartilhaFluxos.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Page } from '@playwright/test';
2+
import { ItensPage } from '../pages/ItensPage';
3+
4+
export class CartFlows {
5+
readonly page: Page;
6+
readonly ItensPage: ItensPage;
7+
8+
constructor(page: Page) {
9+
this.page = page;
10+
this.ItensPage = new ItensPage(page);
11+
}
12+
13+
async adicionarKitBasicoAoCarrinho() {
14+
await this.ItensPage.backpackAddToCartBtn.click();
15+
await this.ItensPage.bikeLightAddToCartBtn.click();
16+
await this.ItensPage.boltTshirtAddToCartBtn.click();
17+
await this.ItensPage.cartLink.click();
18+
}
19+
}

pages/CheckoutPage.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Page, Locator } from '@playwright/test';
2+
3+
export class CheckoutPage {
4+
readonly page: Page;
5+
readonly firstNameInput: Locator;
6+
readonly lastNameInput: Locator;
7+
readonly zipCodeInput: Locator;
8+
readonly continueBtn: Locator;
9+
readonly subtotalLabel: Locator;
10+
11+
constructor(page: Page) {
12+
this.page = page;
13+
this.firstNameInput = page.locator('[data-test="firstName"]');
14+
this.lastNameInput = page.locator('[data-test="lastName"]');
15+
this.zipCodeInput = page.locator('[data-test="postalCode"]');
16+
this.continueBtn = page.locator('[data-test="continue"]');
17+
this.subtotalLabel = page.locator('[data-test="subtotal-label"]');
18+
}
19+
20+
async preencherDadosEContinuar(first: string, last: string, zip: string) {
21+
await this.firstNameInput.fill(first);
22+
await this.lastNameInput.fill(last);
23+
await this.zipCodeInput.fill(zip);
24+
await this.continueBtn.click();
25+
}
26+
}

pages/ItensPage.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Page, Locator } from '@playwright/test';
2+
3+
export class ItensPage {
4+
readonly page: Page;
5+
readonly backpackAddToCartBtn: Locator;
6+
readonly cartBadge: Locator;
7+
readonly bikeLightAddToCartBtn: Locator;
8+
readonly boltTshirtAddToCartBtn: Locator;
9+
readonly cartLink: Locator;
10+
11+
constructor(page: Page) {
12+
this.page = page;
13+
this.backpackAddToCartBtn = page.locator('[data-test="add-to-cart-sauce-labs-backpack"]');
14+
this.cartBadge = page.locator('[data-test="shopping-cart-badge"]');
15+
16+
this.bikeLightAddToCartBtn = page.locator('[data-test="add-to-cart-sauce-labs-bike-light"]');
17+
this.boltTshirtAddToCartBtn = page.locator('[data-test="add-to-cart-sauce-labs-bolt-t-shirt"]');
18+
this.cartLink = page.locator('[data-test="shopping-cart-link"]');
19+
}
20+
21+
async adicionarBackpackAoCarrinho() {
22+
await this.backpackAddToCartBtn.click();
23+
await this.bikeLightAddToCartBtn.click();
24+
await this.boltTshirtAddToCartBtn.click();
25+
}
26+
}

tests/e2e/checkout.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { test, expect } from '@playwright/test';
2+
import { CartFlows } from '../../fluxos/cartilhaFluxos';
3+
import { CheckoutPage } from '../../pages/CheckoutPage';
4+
import { LoginPage } from '../../pages/LoginPage';
5+
6+
test.describe('Cenários de Checkout', () => {
7+
// Setup de Login obrigatório para acessar o inventário
8+
test.beforeEach(async ({ page }) => {
9+
const loginPage = new LoginPage(page);
10+
await loginPage.acessarPagina();
11+
await loginPage.realizarLogin('standard_user', 'secret_sauce');
12+
});
13+
14+
test('Deve validar valor total com kit de 3 itens', async ({ page }) => {
15+
const cartFlow = new CartFlows(page);
16+
const checkout = new CheckoutPage(page);
17+
18+
await cartFlow.adicionarKitBasicoAoCarrinho();
19+
20+
await page.locator('[data-test="checkout"]').click();
21+
await checkout.preencherDadosEContinuar('Marcus', 'Machado', '30000-000');
22+
23+
await expect(checkout.subtotalLabel).toContainText('55.97');
24+
});
25+
});

tests/e2e/itensCarrinho.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { test, expect } from '@playwright/test';
2+
import { LoginPage } from '../../pages/LoginPage';
3+
import { ItensPage } from '../../pages/ItensPage';
4+
5+
test.describe('Cenários de adicionar itens no Carrinho', () => {
6+
test.beforeEach(async ({ page }) => {
7+
const loginPage = new LoginPage(page);
8+
await loginPage.acessarPagina();
9+
await loginPage.realizarLogin('standard_user', 'secret_sauce');
10+
});
11+
12+
test('Deve adicionar a mochila ao carrinho com sucesso', async ({ page }) => {
13+
const item = new ItensPage(page);
14+
15+
await item.adicionarBackpackAoCarrinho();
16+
17+
await expect(item.cartBadge).toHaveText('3');
18+
await expect(page.locator('[data-test="remove-sauce-labs-backpack"]')).toBeVisible();
19+
});
20+
});

tests/e2e/login.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test, expect } from '@playwright/test';
22
import { LoginPage } from '../../pages/LoginPage';
3-
// Importando a massa de dados
3+
44
import usuarios from '../../data/users.json';
55

66
test.describe('Cenários de Login - Swag Labs', () => {
@@ -11,7 +11,6 @@ test.describe('Cenários de Login - Swag Labs', () => {
1111
await loginPage.acessarPagina();
1212
});
1313

14-
// Loop usando os dados do JSON
1514
for (const usuario of usuarios.valid_users) {
1615
test(`Deve realizar login com sucesso para o perfil: ${usuario}`, async ({ page }) => {
1716
await loginPage.realizarLogin(usuario, usuarios.default_password);

0 commit comments

Comments
 (0)