diff --git a/tests/base/checkout.spec.ts b/tests/base/checkout.spec.ts index 32ae81c..ae67678 100644 --- a/tests/base/checkout.spec.ts +++ b/tests/base/checkout.spec.ts @@ -46,6 +46,7 @@ test.describe('Checkout (login required)', () => { const loginPage = new LoginPage(page); await loginPage.login(emailInputValue, passwordInputValue); + await page.goto(slugs.checkoutSlug); }); /** @@ -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)', () => { diff --git a/tests/base/config/expected/expected.json b/tests/base/config/expected/expected.json index 7dc1301..970321c 100644 --- a/tests/base/config/expected/expected.json +++ b/tests/base/config/expected/expected.json @@ -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" diff --git a/tests/base/config/selectors/selectors.json b/tests/base/config/selectors/selectors.json index 04b3a8a..d9ab7ba 100644 --- a/tests/base/config/selectors/selectors.json +++ b/tests/base/config/selectors/selectors.json @@ -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", diff --git a/tests/base/contact.spec.ts b/tests/base/contact.spec.ts index 224ad6c..cc77ea5 100644 --- a/tests/base/contact.spec.ts +++ b/tests/base/contact.spec.ts @@ -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 @@ -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(); }); \ No newline at end of file diff --git a/tests/base/fixtures/checkout.page.ts b/tests/base/fixtures/checkout.page.ts index ce1cab1..c5a83f6 100644 --- a/tests/base/fixtures/checkout.page.ts +++ b/tests/base/fixtures/checkout.page.ts @@ -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(); @@ -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; } diff --git a/tests/base/fixtures/contact.page.ts b/tests/base/fixtures/contact.page.ts index 01cd963..7ab8b07 100644 --- a/tests/base/fixtures/contact.page.ts +++ b/tests/base/fixtures/contact.page.ts @@ -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; @@ -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(); diff --git a/tests/base/register.spec.ts b/tests/base/register.spec.ts index 23e1021..7e7bd97 100644 --- a/tests/base/register.spec.ts +++ b/tests/base/register.spec.ts @@ -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); });