diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2c54539..b50bce0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,7 +7,7 @@ on: jobs: build-and-selftest: - runs-on: windows-latest + runs-on: ubuntu-latest env: BASE_URL: https://hyva-demo.elgentos.io/ diff --git a/tests/base/account.spec.ts b/tests/base/account.spec.ts index ea5d14d..317ca24 100644 --- a/tests/base/account.spec.ts +++ b/tests/base/account.spec.ts @@ -1,5 +1,7 @@ import {test, expect} from '@playwright/test'; +import {MainMenuPage} from './fixtures/mainmenu.page'; import {LoginPage} from './fixtures/login.page'; +import {RegisterPage} from './fixtures/register.page'; import {AccountPage} from './fixtures/account.page'; import {NewsletterSubscriptionPage} from './fixtures/newsletter.page'; @@ -41,22 +43,47 @@ test.describe('Account information actions', {annotation: {type: 'Account Dashbo * @then I should see a notification that my password has been updated * @and I should be able to login with my new credentials. */ - test.skip('I can change my password',{ tag: '@account-credentials', }, async ({page}) => { + test('I can change my password',{ tag: '@account-credentials', }, async ({page, browserName}) => { + + // Create instances and set variables + const mainMenu = new MainMenuPage(page); + const registerPage = new RegisterPage(page); const accountPage = new AccountPage(page); - let changedPasswordValue = process.env.MAGENTO_EXISTING_ACCOUNT_CHANGED_PASSWORD; + const loginPage = new LoginPage(page); + + const browserEngine = browserName?.toUpperCase() || "UNKNOWN"; + let randomNumberforEmail = Math.floor(Math.random() * 101); + let emailPasswordUpdatevalue = `passwordupdate-${randomNumberforEmail}-${browserEngine}@example.com`; let passwordInputValue = process.env.MAGENTO_EXISTING_ACCOUNT_PASSWORD; + let changedPasswordValue = process.env.MAGENTO_EXISTING_ACCOUNT_CHANGED_PASSWORD; + // Log out of current account + if(await page.getByRole('link', { name: selectors.mainMenu.myAccountLogoutItem }).isVisible()){ + await mainMenu.logout(); + } + + // Create account if(!changedPasswordValue || !passwordInputValue) { throw new Error("Changed password or original password in your .env file is not defined or could not be read."); } - // Navigate to Account Information, confirm by checking heading above sidebar - const sidebarAccountInfoLink = page.getByRole('link', { name: 'Account Information' }); - sidebarAccountInfoLink.click(); - await expect(page.getByRole('heading', { name: 'Account Information' }).locator('span')).toBeVisible(); + await registerPage.createNewAccount(inputvalues.accountCreation.firstNameValue, inputvalues.accountCreation.lastNameValue, emailPasswordUpdatevalue, passwordInputValue); + // Update password + await page.goto(slugs.account.changePasswordSlug); + await page.waitForLoadState(); await accountPage.updatePassword(passwordInputValue, changedPasswordValue); + // If login with changePasswordValue is possible, then password change was succesful. + await loginPage.login(emailPasswordUpdatevalue, changedPasswordValue); + + // Logout again, login with original account + await mainMenu.logout(); + let emailInputValue = process.env[`MAGENTO_EXISTING_ACCOUNT_EMAIL_${browserEngine}`]; + if(!emailInputValue) { + throw new Error("MAGENTO_EXISTING_ACCOUNT_EMAIL_${browserEngine} and/or MAGENTO_EXISTING_ACCOUNT_PASSWORD have not defined in the .env file, or the account hasn't been created yet."); + } + await loginPage.login(emailInputValue, passwordInputValue); }); }); diff --git a/tests/base/checkout.spec.ts b/tests/base/checkout.spec.ts index f53d661..0819eae 100644 --- a/tests/base/checkout.spec.ts +++ b/tests/base/checkout.spec.ts @@ -1,13 +1,13 @@ import {test, expect} from '@playwright/test'; import {LoginPage} from './fixtures/login.page'; -import {MainMenuPage} from './fixtures/mainmenu.page'; import {ProductPage} from './fixtures/product.page'; +import {AccountPage} from './fixtures/account.page'; +import { CheckoutPage } from './fixtures/checkout.page'; import slugs from './config/slugs.json'; import inputvalues from './config/input-values/input-values.json'; import selectors from './config/selectors/selectors.json'; -import verify from './config/expected/expected.json'; -import { CheckoutPage } from './fixtures/checkout.page'; + /** * @feature BeforeEach runs before each test in this group. @@ -43,6 +43,44 @@ test.describe('Checkout (login required)', () => { const loginPage = new LoginPage(page); await loginPage.login(emailInputValue, passwordInputValue); }); + + /** + * @feature Automatically fill in certain data in checkout (if user is logged in) + * @scenario When the user navigates to the checkout (with a product), their name and address should be filled in. + * @given I am logged in + * @and I have a product in my cart + * @and I have navigated to the checkout page + * @then My name and address should already be filled in + */ + test('My address should be already filled in at the checkout',{ tag: '@checkout',}, async ({page}) => { + let signInLink = page.getByRole('link', { name: selectors.credentials.loginButtonLabel }); + let addressField = page.getByLabel(selectors.newAddress.streetAddressLabel); + let addressAlreadyAdded = false; + + if(await signInLink.isVisible()) { + throw new Error(`Sign in link found, user is not logged in. Please check the test setup.`); + } + + // name field should NOT be on the page + await expect(page.getByLabel(selectors.personalInformation.firstNameLabel)).toBeHidden(); + + if(await addressField.isVisible()) { + if(!addressAlreadyAdded){ + // Address field is visible and addressalreadyAdded is not true, so we need to add an address to the account. + const accountPage = new AccountPage(page); + + let phoneNumberValue = inputvalues.firstAddress.firstPhoneNumberValue; + let addressValue = inputvalues.firstAddress.firstStreetAddressValue; + let zipCodeValue = inputvalues.firstAddress.firstZipCodeValue; + let cityNameValue = inputvalues.firstAddress.firstCityValue; + let stateValue = inputvalues.firstAddress.firstProvinceValue; + + await accountPage.addNewAddress(phoneNumberValue, addressValue, zipCodeValue, cityNameValue, stateValue); + } else { + throw new Error(`Address field is visible even though an address has been added to the account.`); + } + } + }); /** diff --git a/tests/base/config/slugs.json b/tests/base/config/slugs.json index 20673df..d6293a5 100644 --- a/tests/base/config/slugs.json +++ b/tests/base/config/slugs.json @@ -5,7 +5,8 @@ "createAccountSlug": "/customer/account/create", "addressBookSlug": "/customer/address", "addressIndexSlug": "/customer/address/index", - "addressNewSlug": "customer/address/new" + "addressNewSlug": "customer/address/new", + "changePasswordSlug": "/customer/account/edit/changepass/1/" }, "productpage": { "simpleProductSlug": "/push-it-messenger-bag.html",