Skip to content

Commit

Permalink
Implemented fakerJS
Browse files Browse the repository at this point in the history
  • Loading branch information
shayfaber committed Jan 27, 2025
1 parent 8a41fbc commit d4397be
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 34 deletions.
36 changes: 22 additions & 14 deletions tests/base/checkout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test.describe('Checkout (login required)', () => {

const loginPage = new LoginPage(page);
await loginPage.login(emailInputValue, passwordInputValue);
await page.goto(slugs.checkoutSlug);
});

/**
Expand All @@ -72,28 +73,35 @@ test.describe('Checkout (login required)', () => {
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);
await accountPage.addNewAddress();
} 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}) => {
const checkoutPage = new CheckoutPage(page);
await checkoutPage.placeOrder();
});
// expect to see radio button to select existing address
let shippingRadioButton = page.locator(selectors.checkout.shippingAddressRadioLocator).first();
await expect(shippingRadioButton, 'Radio button to select address should be visible').toBeVisible();

});


/**
* @feature Place order for simple product
* @scenario User places an order for a simple product
* @given I have a product in my cart
* @and I am on any page
* @when I navigate to the checkout
* @and I fill in the required fields
* @and I click the button to place my order
* @then I should see a confirmation that my order has been placed
* @and a order number should be created and show to me
*/
test('Place order for simple product',{ tag: '@simple-product-order',}, async ({page}, testInfo) => {
const checkoutPage = new CheckoutPage(page);
let orderNumber = await checkoutPage.placeOrder();
testInfo.annotations.push({ type: 'Order number', description: `${orderNumber}` });
});
});

test.describe('Checkout (guest)', () => {
Expand Down
4 changes: 3 additions & 1 deletion tests/base/config/expected/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"couponAppliedNotification": "Your coupon was successfully applied",
"couponRemovedNotification": "Your coupon was successfully removed",
"checkoutPriceReducedSymbol": "-$",
"incorrectDiscountNotification": "The coupon code isn't valid. Verify the code and try again."
"incorrectDiscountNotification": "The coupon code isn't valid. Verify the code and try again.",
"orderPlacedNotification": "Thank you for your purchase!",
"orderPlacedNumberText": "Your order number is:"
},
"contactPage": {
"messageSentConfirmationText": "Thanks for contacting us with"
Expand Down
3 changes: 2 additions & 1 deletion tests/base/config/selectors/selectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"openCartButtonLabel": "Cart",
"openCartButtonLabelCont": "item",
"openCartButtonLabelContMultiple": "items",
"cartDetailsLocator": "#checkout-cart-details div"
"cartDetailsLocator": "#checkout-cart-details div",
"shippingAddressRadioLocator": "#shipping-details input[type='radio']"
},
"miniCart": {
"checkOutButtonLabel": "Checkout",
Expand Down
10 changes: 1 addition & 9 deletions tests/base/contact.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {test, expect} from '@playwright/test';
import { ContactPage } from './fixtures/contact.page';

import slugs from './config/slugs.json';
import inputvalues from './config/input-values/input-values.json';

/**
* @feature Magento 2 Contact Form
* @scenario User fills in the contact form and sends a message
Expand All @@ -16,10 +13,5 @@ import inputvalues from './config/input-values/input-values.json';
*/
test('I can send a message through the contact form',{ tag: '@contact-form',}, async ({page}) => {
const contactPage = new ContactPage(page);
let formName = inputvalues.accountCreation.firstNameValue;
let formEmail = inputvalues.contact.contactFormEmailValue;
let message = inputvalues.contact.contactFormMessage;

await page.goto(slugs.contact);
await contactPage.fillOutForm(formName,formEmail,message);
await contactPage.fillOutForm();
});
6 changes: 3 additions & 3 deletions tests/base/fixtures/checkout.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CheckoutPage {
}

async placeOrder(){
let orderPlacedNotification = "Thank you for your purchase!";
let orderPlacedNotification = verify.checkout.orderPlacedNotification;
await this.page.goto(slugs.checkoutSlug);

await this.shippingMethodOptionFixed.check();
Expand All @@ -50,12 +50,12 @@ export class CheckoutPage {
});

await expect(this.page.getByText(orderPlacedNotification)).toBeVisible();
let orderNumber = await this.page.locator('p').filter({ hasText: 'Your order number is:' }).getByRole('link').innerText();
let orderNumber = await this.page.locator('p').filter({ hasText: verify.checkout.orderPlacedNumberText }).getByRole('link').innerText();
console.log(`Your ordernumer is: ${orderNumber}`);

// This await only exists to report order number to the HTML reporter.
// TODO: replace this with a proper way to write something to the HTML reporter.
await expect(this.continueShoppingButton, `Your order number is: ${orderNumber}`).toBeVisible();
await expect(this.continueShoppingButton, `${verify.checkout.orderPlacedNumberText} ${orderNumber}`).toBeVisible();
return orderNumber;
}

Expand Down
12 changes: 8 additions & 4 deletions tests/base/fixtures/contact.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {expect, type Locator, type Page} from '@playwright/test';
import {faker} from '@faker-js/faker';

import selectors from '../config/selectors/selectors.json';
import verify from '../config/expected/expected.json';
import slugs from '../config/slugs.json';

export class ContactPage {
readonly page: Page;
Expand All @@ -17,11 +20,12 @@ export class ContactPage {
this.sendFormButton = this.page.getByRole('button', { name: selectors.general.genericSubmitButtonLabel });
}

async fillOutForm(name: string, email: string, message: string){
async fillOutForm(){
await this.page.goto(slugs.contact);
let messageSentConfirmationText = verify.contactPage.messageSentConfirmationText;
await this.nameField.fill(name);
await this.emailField.fill(email);
await this.messageField.fill(message);
await this.nameField.fill(faker.person.firstName());
await this.emailField.fill(faker.internet.email());
await this.messageField.fill(faker.lorem.paragraph());
await this.sendFormButton.click();

await expect(this.page.getByText(messageSentConfirmationText)).toBeVisible();
Expand Down
2 changes: 0 additions & 2 deletions tests/base/register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ test('User can register an account', { tag: '@setup', }, async ({page, browserNa
}
// end of browserNameEmailSection


// password is retrieved from .env file in createNewAccount() function
await registerPage.createNewAccount(firstName, lastName, accountEmail, existingAccountPassword);
});

Expand Down

0 comments on commit d4397be

Please sign in to comment.