Skip to content

Commit

Permalink
Merge pull request #49 from elgentos/gl-17
Browse files Browse the repository at this point in the history
[GL-17] Added test to check address and name are filled in at checkout for user
  • Loading branch information
dheesen authored Jan 21, 2025
2 parents 23af139 + 979a3cf commit 52bef10
Showing 1 changed file with 41 additions and 3 deletions.
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';


// no resetting storageState, mainmenu has more functionalities when logged in.

Expand Down Expand Up @@ -47,6 +47,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.`);
}
}
});

//TODO: Add Gherkin feature description
test('Place order for simple product',{ tag: '@simple-product-order',}, async ({page}) => {
Expand Down

0 comments on commit 52bef10

Please sign in to comment.