-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update browser tests in
k6/foundations
- Loading branch information
Showing
2 changed files
with
51 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import { browser } from 'k6/experimental/browser'; | ||
import { browser } from 'k6/browser'; | ||
import { check } from "k6"; | ||
|
||
export async function LoadAndCheck(url, headless) { | ||
const page = browser.newPage(); | ||
let checkData; | ||
const page = await browser.newPage(); | ||
|
||
try { | ||
await page.goto(url) | ||
checkData = await page.locator("h1").textContent(); | ||
check(page, { | ||
'header': page.locator('h1').textContent() == 'Looking to break out of your pizza routine?', | ||
header: checkData == "Looking to break out of your pizza routine?", | ||
}); | ||
|
||
await page.locator('//button[. = "Pizza, Please!"]').click(); | ||
page.waitForTimeout(500); | ||
page.screenshot({ path: `screenshots/${__ITER}.png` }); | ||
await page.waitForTimeout(500); | ||
await page.screenshot({ path: `screenshots/${__ITER}.png` }); | ||
checkData = await page.locator("div#recommendations").textContent(); | ||
check(page, { | ||
'recommendation': page.locator('div#recommendations').textContent() != '', | ||
recommendation: checkData != "", | ||
}); | ||
} finally { | ||
page.close(); | ||
await page.close(); | ||
} | ||
} |