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

Adding some improvements #13

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
[![NPM Version](https://img.shields.io/npm/v/%40shopware-ag%2Facceptance-test-suite)](https://www.npmjs.com/package/@shopware-ag/acceptance-test-suite)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
[![License](https://img.shields.io/github/license/shopware/acceptance-test-suite.svg)](https://github.com/shopware/acceptance-test-suite/blob/trunk/LICENSE)

# Shopware Acceptance Test Suite
This test suite is an extension to [Playwright](https://playwright.dev/) to easily create end-to-end and API acceptance tests for [Shopware](https://github.com/shopware/shopware). It provides several useful Playwright [fixtures](https://playwright.dev/docs/test-fixtures) to start testing with Shopware right away, including page contexts and [page objects](https://playwright.dev/docs/pom) for Storefront and Administration, API clients, test data creation and reusable test logic.

## Table of contents

* [Installation](#installation)
* [Configuration](#configuration)
* [Usage](#usage)
* [General Fixtures](#general-fixtures)
* [Page Objects](#page-objects)
* [Actor Pattern](#actor-pattern)
* [Data Fixtures](#data-fixtures)
* [Code Contribution](#code-contribution)

## Installation
Start by creating your own [Playwright](https://playwright.dev/docs/intro) project.

Expand Down Expand Up @@ -354,4 +369,9 @@ test('Property group test scenario', async ({ PropertiesData }) => {
});
```

If you create your own data fixtures make sure to import and merge them in your base test file with other fixtures you created.
If you create your own data fixtures make sure to import and merge them in your base test file with other fixtures you created.

## Code Contribution
You can contribute to this project via its [official repository](https://github.com/shopware/acceptance-test-suite/) on GitHub.

This project uses [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). Please make sure to form your commits accordingly to the spec.
36 changes: 36 additions & 0 deletions src/data-fixtures/Category/Category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { test as base, expect } from '@playwright/test';
import type { FixtureTypes } from '../../types/FixtureTypes';
import type { components } from '@shopware/api-client/admin-api-types';

export const CategoryData = base.extend<FixtureTypes>({
CategoryData: async ({ IdProvider, AdminApiContext, DefaultSalesChannel, ProductData }, use) => {

const { id: categoryId, uuid: categoryUuid } = IdProvider.getIdPair();
const categoryName = `Category-${categoryId}`;

const categoryResponse = await AdminApiContext.post('category?_response', {
data: {
id: categoryUuid,
name: categoryName,
parentId: DefaultSalesChannel.salesChannel.navigationCategoryId,
displayNestedProducts: true,
type: 'page',
productAssignmentType: 'product',
visible: true,
active: true,
products: [{
id: ProductData.id,
}],
},
});

expect(categoryResponse.ok()).toBeTruthy();

const { data: category } = (await categoryResponse.json()) as { data: components['schemas']['Category'] };

await use(category);

const cleanupResponse = await AdminApiContext.delete(`category/${categoryUuid}`);
expect(cleanupResponse.ok()).toBeTruthy();
},
});
3 changes: 3 additions & 0 deletions src/data-fixtures/DataFixtures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mergeTests } from '@playwright/test';
import type { components } from '@shopware/api-client/admin-api-types';
import { ProductData } from './Product/Product';
import { CategoryData } from './Category/Category';
import { DigitalProductData } from './Product/DigitalProduct';
import { PropertiesData } from './Product/Properties';
import { CartWithProductData } from './Checkout/CartWithProduct';
Expand All @@ -11,6 +12,7 @@ import { TagData } from './Tag/Tag';

export interface DataFixtureTypes {
ProductData: components['schemas']['Product'],
CategoryData: components['schemas']['Category'],
DigitalProductData: {
product: components['schemas']['Product'],
fileContent: string
Expand All @@ -28,6 +30,7 @@ export interface DataFixtureTypes {

export const test = mergeTests(
ProductData,
CategoryData,
DigitalProductData,
CartWithProductData,
PromotionWithCodeData,
Expand Down
28 changes: 28 additions & 0 deletions src/page-objects/StorefrontPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,52 @@ import type { FixtureTypes } from '../types/FixtureTypes';

import { Home } from './storefront/Home';
import { ProductDetail } from './storefront/ProductDetail';
import { Category } from './storefront/Category';
import { CheckoutCart } from './storefront/CheckoutCart';
import { CheckoutConfirm } from './storefront/CheckoutConfirm';
import { CheckoutFinish } from './storefront/CheckoutFinish';
import { CheckoutRegister } from './storefront/CheckoutRegister';
import { Account } from './storefront/Account';
import { AccountLogin } from './storefront/AccountLogin';
import { AccountProfile } from './storefront/AccountProfile';
import { AccountOrder } from './storefront/AccountOrder';
import { AccountAddresses } from './storefront/AccountAddresses';
import { AccountPayment } from './storefront/AccountPayment';
import { Search } from './storefront/Search';
import { SearchSuggest } from './storefront/SearchSuggest';

export interface StorefrontPageTypes {
StorefrontHome: Home;
StorefrontProductDetail: ProductDetail;
StorefrontCategory: Category;
StorefrontCheckoutCart: CheckoutCart;
StorefrontCheckoutConfirm: CheckoutConfirm;
StorefrontCheckoutFinish: CheckoutFinish;
StorefrontCheckoutRegister: CheckoutRegister;
StorefrontAccount: Account;
StorefrontAccountLogin: AccountLogin;
StorefrontAccountProfile: AccountProfile;
StorefrontAccountOrder: AccountOrder;
StorefrontAccountAddresses: AccountAddresses;
StorefrontAccountPayment: AccountPayment;
StorefrontSearch: Search;
StorefrontSearchSuggest: SearchSuggest;
}

export const StorefrontPageObjects = {
Home,
ProductDetail,
Category,
CheckoutCart,
CheckoutConfirm,
CheckoutFinish,
CheckoutRegister,
Account,
AccountLogin,
AccountProfile,
AccountOrder,
AccountAddresses,
AccountPayment,
Search,
SearchSuggest,
}
Expand All @@ -51,6 +63,10 @@ export const test = base.extend<FixtureTypes>({
await use(new ProductDetail(StorefrontPage, ProductData));
},

StorefrontCategory: async ({ StorefrontPage, CategoryData }, use) => {
await use(new Category(StorefrontPage, CategoryData));
},

StorefrontCheckoutCart: async ({ StorefrontPage }, use) => {
await use(new CheckoutCart(StorefrontPage));
},
Expand All @@ -75,10 +91,22 @@ export const test = base.extend<FixtureTypes>({
await use(new AccountLogin(StorefrontPage));
},

StorefrontAccountProfile: async ({ StorefrontPage }, use) => {
await use(new AccountProfile(StorefrontPage));
},

StorefrontAccountOrder: async ({ StorefrontPage }, use) => {
await use(new AccountOrder(StorefrontPage));
},

StorefrontAccountAddresses: async ({ StorefrontPage }, use) => {
await use(new AccountAddresses(StorefrontPage));
},

StorefrontAccountPayment: async ({ StorefrontPage }, use) => {
await use(new AccountPayment(StorefrontPage));
},

StorefrontSearch: async ({ StorefrontPage }, use) => {
await use(new Search(StorefrontPage));
},
Expand Down
10 changes: 10 additions & 0 deletions src/page-objects/storefront/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ import type { PageObject } from '../../types/PageObject';
export class Account implements PageObject {
public readonly headline: Locator;
public readonly personalDataCardTitle: Locator;
public readonly paymentMethodCardTitle: Locator;
public readonly billingAddressCardTitle: Locator;
public readonly shippingAddressCardTitle: Locator;
public readonly newsletterCheckbox: Locator;
public readonly newsletterRegistrationSuccessMessage: Locator;

constructor(public readonly page: Page) {
this.headline = page.getByRole('heading', { name: 'Overview' });
this.personalDataCardTitle = page.getByRole('heading', { name: 'Personal data' });
this.paymentMethodCardTitle = page.getByRole('heading', { name: 'Default payment method' });
this.billingAddressCardTitle = page.getByRole('heading', { name: 'Default billing address' });
this.shippingAddressCardTitle = page.getByRole('heading', { name: 'Default shipping address' });
this.newsletterCheckbox = page.getByLabel('Yes, I would like to');
this.newsletterRegistrationSuccessMessage = page.getByText('You have successfully subscribed to the newsletter.');
}

async goTo() {
Expand Down
22 changes: 22 additions & 0 deletions src/page-objects/storefront/AccountAddresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';

export class AccountAddresses implements PageObject {
public readonly addNewAddressButton: Locator;
public readonly editBillingAddressButton: Locator;
public readonly editShippingAddressButton: Locator;
public readonly useDefaultBillingAddressButton: Locator;
public readonly useDefaultShippingAddressButton: Locator;

constructor(public readonly page: Page) {
this.addNewAddressButton = page.getByRole('link', { name: 'Add new address' });
this.editBillingAddressButton = page.getByRole('link', { name: 'Edit address' }).first();
this.editShippingAddressButton = page.getByRole('link', { name: 'Edit address' }).nth(1);
this.useDefaultBillingAddressButton = page.getByRole('button', { name: 'Use as default billing address' });
this.useDefaultShippingAddressButton = page.getByRole('button', { name: 'Use as default shipping address' });
}

async goTo() {
await this.page.goto('account/address');
}
}
20 changes: 20 additions & 0 deletions src/page-objects/storefront/AccountPayment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';

export class AccountPayment implements PageObject {
public readonly cashOnDeliveryOption: Locator;
public readonly paidInAdvanceOption: Locator;
public readonly invoiceOption: Locator;
public readonly changeDefaultPaymentButton: Locator;

constructor(public readonly page: Page) {
this.cashOnDeliveryOption = page.getByLabel('Cash on delivery');
this.paidInAdvanceOption = page.getByLabel('Paid in advance');
this.invoiceOption = page.getByLabel('Invoice');
this.changeDefaultPaymentButton = page.getByRole('button', { name: 'Change' });
}

async goTo() {
await this.page.goto('account/payment');
}
}
44 changes: 44 additions & 0 deletions src/page-objects/storefront/AccountProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';

export class AccountProfile implements PageObject {
public readonly salutationSelect: Locator;
public readonly firstNameInput: Locator;
public readonly lastNameInput: Locator;
public readonly saveProfileButton: Locator;

public readonly changeEmailButton: Locator;
public readonly emailAddressInput: Locator;
public readonly emailAddressConfirmInput: Locator;
public readonly emailConfirmPasswordInput: Locator;
public readonly saveEmailAddressButton: Locator;

public readonly changePasswordButton: Locator;
public readonly newPasswordInput: Locator;
public readonly newPasswordConfirmInput: Locator;
public readonly currentPasswordInput: Locator;
public readonly saveNewPasswordButton: Locator;

constructor(public readonly page: Page) {
this.salutationSelect = page.getByLabel('Salutation');
this.firstNameInput = page.getByPlaceholder('Enter first name...');
this.lastNameInput = page.getByPlaceholder('Enter last name...');
this.saveProfileButton = page.locator('#profilePersonalForm').getByRole('button', { name: 'Save changes' })

this.changeEmailButton = page.getByRole('button', { name: 'Change email address' });
this.emailAddressInput = page.getByPlaceholder('Enter email address...');
this.emailAddressConfirmInput = page.getByPlaceholder('Enter your email address once again...');
this.emailConfirmPasswordInput = page.getByPlaceholder('Enter password...');
this.saveEmailAddressButton = page.locator('#profileMailForm').getByRole('button', { name: 'Save changes' });

this.changePasswordButton = page.getByRole('button', { name: 'Change password' });
this.newPasswordInput = page.getByPlaceholder('Enter new password...');
this.newPasswordConfirmInput = page.getByPlaceholder('Enter your new password once again...');
this.currentPasswordInput = page.getByPlaceholder('Enter current password...');
this.saveNewPasswordButton = page.locator('#profilePasswordForm').getByRole('button', { name: 'Save changes' });
}

async goTo() {
await this.page.goto('account/profile');
}
}
24 changes: 24 additions & 0 deletions src/page-objects/storefront/Category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';
import type { components } from '@shopware/api-client/admin-api-types';

export class Category implements PageObject {
public readonly categoryData: components['schemas']['Category'];

public readonly sortingSelect: Locator;
public readonly firstProductBuyButton: Locator;
public readonly noProductsFoundAlert: Locator;

constructor(public readonly page: Page, CategoryData: components['schemas']['Category']) {
this.categoryData = CategoryData;

this.sortingSelect = page.getByLabel('Sorting');
this.firstProductBuyButton = page.getByRole('button', { name: 'Add to shopping cart' }).first();
this.noProductsFoundAlert = page.getByText('No products found.');
}

async goTo() {
const url = `${this.categoryData.name}`;
await this.page.goto(url);
}
}