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 () => {
await this.continueToCheckoutButton.waitFor()
await this.continueToCheckoutButton.click()
await this.page.waitForURL(/\/login/, {timeout: 3000})

View File

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

View File

@ -1,5 +1,6 @@
import { expect } from "@playwright/test"
import { Navigation } from "./Navigation.js"
import { isDesktopViewPort } from "../Utils/isDesktopViewport.js"
export class ProductsPage {
@ -22,14 +23,23 @@ export class ProductsPage {
await expect(specificAddButton).toHaveText("Add to Basket")
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 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 () => {

View File

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