Skip to content

Commit 11818a3

Browse files
authored
fix: add catch blocks to script examples (#1154)
1 parent 1d4a88f commit 11818a3

File tree

9 files changed

+38
-11
lines changed

9 files changed

+38
-11
lines changed

‎src/components/BrowserExamplesMenu/snippets/colorscheme.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export default async function() {
3939
await check(colorScheme, {
4040
'isDarkColorScheme': cs => cs.isDarkColorScheme
4141
});
42+
} catch (e) {
43+
console.log('Error during execution:', e);
44+
throw e;
4245
} finally {
4346
await page.close();
4447
}

‎src/components/BrowserExamplesMenu/snippets/dispatch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export default async function () {
3030
await check(page.locator('h3'), {
3131
header: async (locator) => (await locator.textContent()) === 'Contact us',
3232
});
33+
} catch (e) {
34+
console.log('Error during execution:', e);
35+
throw e;
3336
} finally {
3437
await page.close();
3538
}

‎src/components/BrowserExamplesMenu/snippets/evaluate.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export default async function () {
4242
await check(result, {
4343
'result should be 25': (result) => result == 25,
4444
});
45+
} catch (e) {
46+
console.log('Error during execution:', e);
47+
throw e;
4548
} finally {
4649
await page.close();
4750
}

‎src/components/BrowserExamplesMenu/snippets/fillform.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export default async function () {
4848
return cookies.find((c) => c.name == 'sid') !== undefined;
4949
},
5050
});
51+
} catch (e) {
52+
console.log('Error during execution:', e);
53+
throw e;
5154
} finally {
5255
await page.close();
5356
}

‎src/components/BrowserExamplesMenu/snippets/getattribute.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export default async function () {
2929
await check(page.locator('#dark-mode-toggle-3'), {
3030
"GetAttribute('mode')": async (locator) => (await locator.getAttribute('mode')) === 'light',
3131
});
32+
} catch (e) {
33+
console.log('Error during execution:', e);
34+
throw e;
3235
} finally {
3336
await page.close();
3437
}

‎src/components/BrowserExamplesMenu/snippets/querying.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export default async function () {
3333
await check(page.locator(`//header//h1[@class="title"]`), {
3434
'Title with XPath selector': async (locator) => (await locator.textContent()) === title,
3535
});
36+
} catch (e) {
37+
console.log('Error during execution:', e);
38+
throw e;
3639
} finally {
3740
await page.close();
3841
}

‎src/components/BrowserExamplesMenu/snippets/waitForFunction.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export default async function () {
3535
timeout: 2000,
3636
});
3737
await check(ok, { 'waitForFunction successfully resolved': ok.innerHTML() == 'Hello' });
38+
} catch (e) {
39+
console.log('Error during execution:', e);
40+
throw e;
3841
} finally {
3942
await page.close();
4043
}
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { browser } from 'k6/experimental/browser'
2-
import { check } from 'k6'
1+
import { browser } from 'k6/experimental/browser';
2+
import { check } from 'k6';
33

44
export const options = {
55
scenarios: {
@@ -17,25 +17,28 @@ export const options = {
1717
thresholds: {
1818
checks: ['rate==1.0'],
1919
},
20-
}
20+
};
2121

2222
export default async function () {
23-
const page = browser.newPage()
23+
const page = browser.newPage();
2424

2525
try {
26-
await page.goto('https://test.k6.io/my_messages.php')
26+
await page.goto('https://test.k6.io/my_messages.php');
2727

28-
page.locator('input[name="login"]').type('admin')
29-
page.locator('input[name="password"]').type('123')
28+
page.locator('input[name="login"]').type('admin');
29+
page.locator('input[name="password"]').type('123');
3030

31-
const submitButton = page.locator('input[type="submit"]')
31+
const submitButton = page.locator('input[type="submit"]');
3232

33-
await Promise.all([page.waitForNavigation(), submitButton.click()])
33+
await Promise.all([page.waitForNavigation(), submitButton.click()]);
3434

3535
check(page, {
3636
header: (p) => p.locator('h2').textContent() === 'Welcome, admin!',
37-
})
37+
});
38+
} catch (e) {
39+
console.log('Error during execution:', e);
40+
throw e;
3841
} finally {
39-
page.close()
42+
page.close();
4043
}
4144
}

‎src/components/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ export default async function () {
206206
await check(page.locator("h2"), {
207207
header: async (locator) => (await locator.textContent()) == "Welcome, admin!",
208208
});
209+
} catch (e) {
210+
console.log('Error during execution:', e);
211+
throw e;
209212
} finally {
210213
await page.close();
211214
}

0 commit comments

Comments
 (0)