Enabling func to be compliant with mobile viewport

This commit is contained in:
Kira 2023-09-15 16:01:04 -07:00
parent d6c643a39b
commit 4219b60e31
5 changed files with 49 additions and 23 deletions

View File

@ -0,0 +1,5 @@
export const isDesktopViewPort = (page) => {
const size = page.viewportSize()
return size.width >= 600
}

View File

@ -34,6 +34,7 @@ export class CheckoutPage {
} }
continueToCheckout = async () => { continueToCheckout = async () => {
await this.continueToCheckoutButton.waitFor() await this.continueToCheckoutButton.waitFor()
await this.continueToCheckoutButton.click() await this.continueToCheckoutButton.click()
await this.page.waitForURL(/\/login/, {timeout: 3000}) await this.page.waitForURL(/\/login/, {timeout: 3000})

View File

@ -1,9 +1,13 @@
import { isDesktopViewPort } from "../Utils/isDesktopViewport.js"
export class Navigation { export class Navigation {
constructor(page){ constructor(page){
this.page = page this.page = page
this.basketCounter = page.locator('[data-qa="header-basket-count"]') this.basketCounter = page.locator('[data-qa="header-basket-count"]')
this.checkoutLink = page.getByRole('link', { name: 'Checkout' }) this.checkoutLink = page.getByRole('link', { name: 'Checkout' })
this.mobileBurgerButton = page.locator('[data-qa="burger-button"]')
} }
getBasketCount = async () => { getBasketCount = async () => {
@ -13,10 +17,16 @@ export class Navigation {
} }
goToCheckout = async () => { goToCheckout = async () => {
this.checkoutLink.waitFor()
if(!isDesktopViewPort(this.page)) {
await this.mobileBurgerButton.waitFor()
await this.mobileBurgerButton.click()
}
this.checkoutLink.waitFor()
await this.checkoutLink.click() await this.checkoutLink.click()
await this.page.waitForURL("/basket") await this.page.waitForURL("/basket")
} }
} }

View File

@ -1,5 +1,6 @@
import { expect } from "@playwright/test" import { expect } from "@playwright/test"
import { Navigation } from "./Navigation.js" import { Navigation } from "./Navigation.js"
import { isDesktopViewPort } from "../Utils/isDesktopViewport.js"
export class ProductsPage { export class ProductsPage {
@ -22,14 +23,23 @@ export class ProductsPage {
await expect(specificAddButton).toHaveText("Add to Basket") await expect(specificAddButton).toHaveText("Add to Basket")
const navigation = new Navigation(this.page) const navigation = new Navigation(this.page)
const basketCountBefore = await navigation.getBasketCount()
// only desktop viewport
let basketCountBefore
if (isDesktopViewPort(this.page)) {
basketCountBefore = await navigation.getBasketCount()
}
await specificAddButton.click() await specificAddButton.click()
await expect(specificAddButton).toHaveText("Remove from Basket") await expect(specificAddButton).toHaveText("Remove from Basket")
const basketCountAfter = await navigation.getBasketCount()
expect(basketCountAfter).toBeGreaterThan(basketCountBefore) // only desktop viewport
if(isDesktopViewPort(this.page)) {
const basketCountAfter = await navigation.getBasketCount()
expect(basketCountAfter).toBeGreaterThan(basketCountBefore)
}
} }
sortByCheapest = async () => { sortByCheapest = async () => {

View File

@ -46,12 +46,12 @@ const config = {
/* Configure projects for major browsers */ /* Configure projects for major browsers */
projects: [ projects: [
{ // {
name: 'chromium', // name: 'chromium',
use: { // use: {
...devices['Desktop Chrome'], // ...devices['Desktop Chrome'],
}, // },
}, // },
// { // {
// name: 'firefox', // name: 'firefox',
@ -68,18 +68,18 @@ const config = {
// }, // },
/* Test against mobile viewports. */ /* Test against mobile viewports. */
// { {
// name: 'Mobile Chrome', name: 'Mobile Chrome',
// use: { use: {
// ...devices['Pixel 5'], ...devices['Pixel 5'],
// }, },
// }, },
// { // {
// name: 'Mobile Safari', // name: 'Mobile Safari',
// use: { // use: {
// ...devices['iPhone 12'], // ...devices['iPhone 12'],
// }, // },
// }, // },
/* Test against branded browsers. */ /* Test against branded browsers. */
// { // {