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

Added UI Tests #52

Merged
merged 1 commit into from
Mar 22, 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
102 changes: 102 additions & 0 deletions .github/workflows/ui-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: UI Tests
on:
## Check each PR
push:
pull_request:
## Manual execution on branch
workflow_dispatch:
## Nightly
### Needs secrets
#### GC_PROJECT_ID
#### GC_SERVICE_KEY
#### NIGHTLY_TOKEN
schedule:
- cron: '0 0 * * *'
jobs:
ui_test:
name: UI Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ps-version:
- '1.7.6.9'
- '1.7.7.8'
- '1.7.8.11'
- '8.0.5'
- '8.1.5'
- 'nightly'
env:
PS_VERSION: ${{ matrix.ps-version }}
steps:
- name: Checkout
uses: actions/[email protected]

- name: Start containers
working-directory: tests/UI/
run: |
docker-compose -f "docker-compose.yml" up -d --build
bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost/en/)" != "200" ]]; do sleep 5; done'

- name: Install dependencies
working-directory: tests/UI/
run: npm ci

- name: Install Playwright Browsers
working-directory: tests/UI/
run: npx playwright install chromium --with-deps

- name: Run Playwright tests
working-directory: tests/UI/
run: npx playwright test

- name: Export Docker errors
working-directory: tests/UI/
if: always()
run: docker-compose logs --no-color >& docker-compose.log

- name: Upload artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report-${{ env.PS_VERSION }}
path: |
tests/UI/reports/
tests/UI/report.json
tests/UI/docker-compose.log
retention-days: 30

# Nightly : Rename file
- name: "Nightly : Rename file"
working-directory: tests/UI/
if: ${{ github.event_name == 'schedule' }}
run: |
mkdir -p nightly
REPORT_NAME="ps_cashondelivery_$(date +%Y-%m-%d)-${{ env.PS_VERSION }}"
mv report.json nightly/${REPORT_NAME}.json

# Nightly : Auth GCP
- name: "Nightly : Auth GCP"
uses: google-github-actions/auth@v1
if: ${{ github.event_name == 'schedule' }}
with:
credentials_json: ${{ secrets.GC_SERVICE_KEY }}
project_id: ${{ secrets.GC_PROJECT_ID }}

# Nightly : Setup GCP
- name: "Nightly : Setup GCP"
uses: google-github-actions/setup-gcloud@v1
if: ${{ github.event_name == 'schedule' }}

# Nightly : Upload to Google Cloud Storage (GCS)
- name: "Nightly : Upload to Google Cloud Storage (GCS)"
working-directory: tests/UI/
if: ${{ github.event_name == 'schedule' }}
run: gsutil cp -r "nightly/**" gs://prestashop-core-nightly/reports

# Nightly : Push Report
- name: "Nightly : Push Report"
if: ${{ github.event_name == 'schedule' }}
run: |
REPORT_NAME="ps_cashondelivery_$(date +%Y-%m-%d)-${{ env.PS_VERSION }}"
curl -v "https://api-nightly.prestashop-project.org/import/report/playwright?token=${{ secrets.NIGHTLY_TOKEN }}&filename=${REPORT_NAME}.json"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/vendor/
/config_*.xml
/.php_cs.cache

## UI Tests
/tests/UI/.env
/tests/UI/node_modules/
/tests/UI/report.json
/tests/UI/reports/
/tests/UI/test-results/
190 changes: 190 additions & 0 deletions tests/UI/campaigns/01_installation/04_resetModule.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import {
// Import utils
testContext,
// Import BO pages
boDashboardPage,
boLoginPage,
boModuleManagerPage,
boModuleManagerUninstalledModulesPage,
// Import FO pages
foClassicCartPage,
foClassicHomePage,
foClassicLoginPage,
// Import data
dataCustomers,
dataModules,
foClassicCheckoutPage,
} from '@prestashop-core/ui-testing';

import { test, expect, Page, BrowserContext } from '@playwright/test';
import semver from 'semver';

const baseContext: string = 'modules_ps_cashondelivery_installation_resetModule';
const psVersion = testContext.getPSVersion();

test.describe('Cash on delivery (COD) module - Reset module', async () => {
let browserContext: BrowserContext;
let page: Page;

test.beforeAll(async ({ browser }) => {
browserContext = await browser.newContext();
page = await browserContext.newPage();
});
test.afterAll(async () => {
await page.close();
});

test('should login in BO', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);

await boLoginPage.goTo(page, global.BO.URL);
await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD);

const pageTitle = await boDashboardPage.getPageTitle(page);
expect(pageTitle).toContain(boDashboardPage.pageTitle);
});

if (semver.lt(psVersion, '8.0.0')) {
test('should go to \'Modules > Module Manager\' page for installing module', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'goToModuleManagerPageToInstall', baseContext);

await boDashboardPage.goToSubMenu(
page,
boDashboardPage.modulesParentLink,
boDashboardPage.moduleManagerLink,
);
await boModuleManagerPage.closeSfToolBar(page);

const pageTitle = await boModuleManagerPage.getPageTitle(page);
expect(pageTitle).toContain(boModuleManagerPage.pageTitle);
});

test('should install module', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'searchModuleToInstall', baseContext);

await boModuleManagerUninstalledModulesPage.goToTabUninstalledModules(page);

const isInstalled = await boModuleManagerUninstalledModulesPage.installModule(page, dataModules.psCashOnDelivery.tag);
expect(isInstalled).toBeTruthy();
});
}

test('should go to \'Modules > Module Manager\' page', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'goToModuleManagerPage', baseContext);

await boDashboardPage.goToSubMenu(
page,
boDashboardPage.modulesParentLink,
boDashboardPage.moduleManagerLink,
);
await boModuleManagerPage.closeSfToolBar(page);

const pageTitle = await boModuleManagerPage.getPageTitle(page);
expect(pageTitle).toContain(boModuleManagerPage.pageTitle);
});

test(`should search the module ${dataModules.psCashOnDelivery.name}`, async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'searchModule', baseContext);

const isModuleVisible = await boModuleManagerPage.searchModule(page, dataModules.psCashOnDelivery);
expect(isModuleVisible).toEqual(true);
});

test('should display the reset modal and cancel it', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'resetModuleAndCancel', baseContext);

const textResult = await boModuleManagerPage.setActionInModule(page, dataModules.psCashOnDelivery, 'reset', true);
expect(textResult).toEqual('');

const isModuleVisible = await boModuleManagerPage.isModuleVisible(page, dataModules.psCashOnDelivery);
expect(isModuleVisible).toEqual(true);

const isModalVisible = await boModuleManagerPage.isModalActionVisible(page, dataModules.psCashOnDelivery, 'reset');
expect(isModalVisible).toEqual(false);
});

test('should reset the module', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'resetModule', baseContext);

const successMessage = await boModuleManagerPage.setActionInModule(page, dataModules.psCashOnDelivery, 'reset');
expect(successMessage).toEqual(boModuleManagerPage.resetModuleSuccessMessage(dataModules.psCashOnDelivery.tag));
});

test('should go to Front Office', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'goToFo', baseContext);

page = await boModuleManagerPage.viewMyShop(page);
await foClassicHomePage.changeLanguage(page, 'en');

const isHomePage = await foClassicHomePage.isHomePage(page);
expect(isHomePage).toEqual(true);
});

test('should go to login page', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'goToLoginPageFO', baseContext);

await foClassicHomePage.goToLoginPage(page);

const pageTitle = await foClassicLoginPage.getPageTitle(page);
expect(pageTitle).toContain(foClassicLoginPage.pageTitle);
});

test('should sign in with default customer', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'sighInFO', baseContext);

await foClassicLoginPage.customerLogin(page, dataCustomers.johnDoe);

const isCustomerConnected = await foClassicLoginPage.isCustomerConnected(page);
expect(isCustomerConnected).toEqual(true);
});

test('should add the first product to the cart', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'addProductToCart', baseContext);

await foClassicLoginPage.goToHomePage(page);

// Add first product to cart by quick view
await foClassicHomePage.addProductToCartByQuickView(page, 1);
await foClassicHomePage.proceedToCheckout(page);

const pageTitle = await foClassicCartPage.getPageTitle(page);
expect(pageTitle).toEqual(foClassicCartPage.pageTitle);
});

test('should proceed to checkout and check Step Address', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'checkAddressStep', baseContext);

await foClassicCartPage.clickOnProceedToCheckout(page);

const isCheckoutPage = await foClassicCheckoutPage.isCheckoutPage(page);
expect(isCheckoutPage).toEqual(true);

const isStepPersonalInformationComplete = await foClassicCheckoutPage.isStepCompleted(
page,
foClassicCheckoutPage.personalInformationStepForm,
);
expect(isStepPersonalInformationComplete).toEqual(true);
});

test('should validate Step Address and go to Delivery Step', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'checkDeliveryStep', baseContext);

const isStepAddressComplete = await foClassicCheckoutPage.goToDeliveryStep(page);
expect(isStepAddressComplete).toEqual(true);
});

test('should go to payment step', async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'goToPaymentStep', baseContext);

const isStepDeliveryComplete = await foClassicCheckoutPage.goToPaymentStep(page);
expect(isStepDeliveryComplete, 'Step Address is not complete').toEqual(true);
});

test(`should check the '${dataModules.psCashOnDelivery.name}' payment module`, async () => {
await testContext.addContextItem(test.info(), 'testIdentifier', 'checkPaymentModule', baseContext);

// Payment step - Choose payment step
const isVisible = await foClassicCheckoutPage.isPaymentMethodExist(page, dataModules.psCashOnDelivery.tag);
expect(isVisible).toEqual(true);
});
});
Loading
Loading