Skip to content

Commit

Permalink
Merge branch 'main' into todo-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dheesen authored Jan 22, 2025
2 parents f42a725 + 3aa2374 commit cfbaa80
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
39 changes: 33 additions & 6 deletions tests/base/account.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
});
});

Expand Down
44 changes: 41 additions & 3 deletions tests/base/checkout.spec.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.`);
}
}
});


/**
Expand Down
3 changes: 2 additions & 1 deletion tests/base/config/slugs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cfbaa80

Please sign in to comment.