-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from shopcanal/dgattey/fixes
feat: rewrite all tests to work without flakiness + add sharding
- Loading branch information
Showing
27 changed files
with
2,630 additions
and
2,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
#!/bin/sh -l | ||
|
||
BROWSER="$1" | ||
SHARD="$2" | ||
|
||
echo "Installing packages..." | ||
yarn | ||
|
||
echo "Running tests on $BROWSER..." | ||
HOME=/root yarn test --browser=$BROWSER | ||
echo "Running tests on $BROWSER (shard $SHARD)..." | ||
HOME=/root DEBUG=pw:api,pw:browser yarn test --project=$BROWSER --shard=$SHARD | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Page } from '@playwright/test'; | ||
|
||
/** | ||
* Intercepts requests on the page to disable requesting fonts, or any third | ||
* party resource. We do this to better control the flakiness of the tests and | ||
* avoid some third party request from affecting things. EVERY test should call | ||
* this function via a before each. | ||
*/ | ||
export const intercept = async (page: Page): Promise<void> => { | ||
await page.route( | ||
/.*(?:clarity.ms)|(?:crisp.chat)|(?:cdn.shopify)|(?:shopify.com)|(?:heapanalytics)|(?:facebook)|(?:googletagmanager)|(?:google-analytics)|(?:bing.com)|(?:stripe)|(?:sentry).*/, | ||
// eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
(route) => route.abort(), | ||
); | ||
await page.route( | ||
'**.{woff2}', | ||
// eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
(route) => route.abort(), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
import type { | ||
BrowserContext, | ||
Page, | ||
PlaywrightTestArgs, | ||
PlaywrightTestOptions, | ||
PlaywrightWorkerArgs, | ||
PlaywrightWorkerOptions, | ||
TestType, | ||
} from '@playwright/test'; | ||
import type { BrowserContext, Page } from '@playwright/test'; | ||
import { expect } from '@playwright/test'; | ||
import { LOGIN_PAGE, SHOPKEEP_ROUTES } from './routes'; | ||
import { SHOPKEEP_ROUTES, SUPPLIER_ROUTES } from './routes'; | ||
|
||
/** | ||
* Selectors used for logging in | ||
|
@@ -19,44 +11,59 @@ export const LOGIN_BUTTON_SELECTOR = 'button#login'; | |
|
||
const E2E_ACCOUNT_LOGIN = '[email protected]'; | ||
|
||
export const logInSuccessfully = async ( | ||
/** | ||
* Use this to log a user in and make sure they land on a given page. | ||
*/ | ||
const logIn = async ( | ||
page: Page, | ||
context: BrowserContext, | ||
test?: TestType< | ||
PlaywrightTestArgs & PlaywrightTestOptions, | ||
PlaywrightWorkerArgs & PlaywrightWorkerOptions | ||
>, | ||
loginUrl: string, | ||
firstLoggedInPageUrl: string, | ||
): Promise<void> => { | ||
const loginButton = page.locator(LOGIN_BUTTON_SELECTOR); | ||
const profileDropdown = page.locator('button:has-text("e2e_tester")'); | ||
|
||
if (process.env.APP_TEST_PASSWORD) { | ||
// Make sure browser is logged out before attempting to go through login flow | ||
await logout(context); | ||
await logout(page, context); | ||
|
||
// Navigate to login page and wait for login button to load | ||
await page.goto(LOGIN_PAGE); | ||
await page.waitForSelector(LOGIN_BUTTON_SELECTOR); | ||
await page.goto(loginUrl); | ||
await loginButton.waitFor(); | ||
|
||
// Fill out email and password | ||
await page.fill(LOGIN_EMAIL_INPUT_SELECTOR, E2E_ACCOUNT_LOGIN); | ||
await page.fill(LOGIN_PASSWORD_INPUT_SELECTOR, process.env.APP_TEST_PASSWORD || ''); | ||
|
||
// Then click the login button | ||
await page.click(LOGIN_BUTTON_SELECTOR); | ||
// Then click the login button and make sure we navigate | ||
await loginButton.click(); | ||
|
||
// Wait 10 seconds to give time for the next page to load | ||
await page.waitForTimeout(10000); | ||
// Make sure the profile dropdown shows, as this appears on both sides once logged in | ||
await profileDropdown.waitFor(); | ||
|
||
// See if the nav has loaded - if it hasn't, then skip the test since login was flaky | ||
const overviewButton = await page.$('a#navOverview'); | ||
if (test) test.skip(!overviewButton, 'Login was not successful - skipping test'); | ||
|
||
// Ensure that the URL is now the URL of the Shopkeep Inventory page | ||
expect(page.url().includes(SHOPKEEP_ROUTES.INVENTORY)).toBeTruthy(); | ||
// Make sure this is the page we want | ||
expect(page.url().includes(firstLoggedInPageUrl)).toBeTruthy(); | ||
} else { | ||
console.warn('Could not log in because no APP_TEST_PASSWORD was provided. Failing test.'); | ||
expect(true).toBe(false); | ||
} | ||
}; | ||
|
||
export const logout = async (context: BrowserContext): Promise<void> => { | ||
/** | ||
* Logs a user into the shopkeep landing page | ||
*/ | ||
export const logIntoShopkeep = async (page: Page, context: BrowserContext): Promise<void> => | ||
logIn(page, context, SHOPKEEP_ROUTES.LOGIN, SHOPKEEP_ROUTES.INVENTORY); | ||
|
||
/** | ||
* Logs a user into the supplier landing page | ||
*/ | ||
export const logIntoSupplier = async (page: Page, context: BrowserContext): Promise<void> => | ||
logIn(page, context, SUPPLIER_ROUTES.LOGIN, SUPPLIER_ROUTES.OVERVIEW); | ||
|
||
/** | ||
* Simulates a log out by clearing cookies. On next page nav, we'll refresh. | ||
*/ | ||
export const logout = async (page: Page, context: BrowserContext): Promise<void> => { | ||
await context.clearCookies(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.