Skip to content

Commit

Permalink
Add click to the browser code
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
  • Loading branch information
dgzlopes committed Apr 17, 2023
1 parent 75e729a commit d56151e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
13 changes: 11 additions & 2 deletions k6/09.composability.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,23 @@ export function getPizza() {

export async function checkFrontend() {
const browser = chromium.launch({ headless: true });
const page = browser.newPage();
const context = browser.newContext(
{ viewport: { width: 1920, height: 1080 } },
);
const page = context.newPage();

try {
await page.goto(BASE_URL, { waitUntil: 'networkidle' })
page.screenshot({ path: `screenshots/${__ITER}.png` });
check(page, {
'header': page.locator('h1').textContent() == 'Looking to break out of your pizza routine?',
});

await page.click('button', { text: 'Pizza, Please!' });
await page.waitForTimeout(500);
page.screenshot({ path: `screenshots/${__ITER}.png` });
check(page, {
'recommendation': page.locator('div#recommendations').textContent() != '',
});
} finally {
page.close();
browser.close();
Expand Down
15 changes: 12 additions & 3 deletions k6/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ import { check } from 'k6';
const BASE_URL = __ENV.BASE_URL || 'http://localhost:3333';

export default async function () {
const browser = chromium.launch({ headless: false });
const page = browser.newPage();
const browser = chromium.launch({ headless: true });
const context = browser.newContext(
{ viewport: { width: 1920, height: 1080 } },
);
const page = context.newPage();

try {
await page.goto(BASE_URL, { waitUntil: 'networkidle' })
page.screenshot({ path: 'screenshot.png' });
check(page, {
'header': page.locator('h1').textContent() == 'Looking to break out of your pizza routine?',
});

await page.click('button', { text: 'Pizza, Please!' });
await page.waitForTimeout(500);
page.screenshot({ path: 'screenshot.png' });
check(page, {
'recommendation': page.locator('div#recommendations').textContent() != '',
});
} finally {
page.close();
browser.close();
Expand Down
15 changes: 12 additions & 3 deletions k6/shared/frontend/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import { check, sleep } from "k6";

export async function LoadAndCheck(url, headless) {
const browser = chromium.launch({ headless: headless });
const page = browser.newPage();

const context = browser.newContext(
{ viewport: { width: 1920, height: 1080 } },
);
const page = context.newPage();

try {
await page.goto(url, { waitUntil: 'networkidle' })
page.screenshot({ path: `screenshots/${__ITER}.png` });
check(page, {
'header': page.locator('h1').textContent() == 'Looking to break out of your pizza routine?',
});

await page.click('button', { text: 'Pizza, Please!' });
await page.waitForTimeout(500);
page.screenshot({ path: `screenshots/${__ITER}.png` });
check(page, {
'recommendation': page.locator('div#recommendations').textContent() != '',
});
} finally {
page.close();
browser.close();
Expand Down
2 changes: 1 addition & 1 deletion pkg/web/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
{/if}
<p>
{#if pizza['pizza']}
<div class="flex justify-center">
<div class="flex justify-center" id="recommendations">
<div class="w-[300px] sm:w-[500px] mt-6 bg-gray-50 border border-gray-200 rounded-lg">
<div class="text-left p-4">
<h2 class="font-medium">Our recommendation:</h2>
Expand Down

0 comments on commit d56151e

Please sign in to comment.