Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graduate to k6/browser from an experimental module #3793

Merged
merged 7 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ func TestBrowserPermissions(t *testing.T) {
name: "browser option not set",
options: "",
expectedExitCode: 0,
expectedError: "GoError: browser not found in registry. make sure to set browser type option in scenario definition in order to use the browser module",
expectedError: "browser not found in registry. make sure to set browser type option in scenario definition in order to use the browser module",
},
// When we do supply the correct browser options,
// we expect that the browser module will start
Expand Down Expand Up @@ -2300,12 +2300,12 @@ func TestBrowserPermissions(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
script := fmt.Sprintf(`
import { browser } from 'k6/experimental/browser';
import { browser } from 'k6/browser';
ankur22 marked this conversation as resolved.
Show resolved Hide resolved

%s

export default function() {
browser.isConnected();
browser.isConnected()
};
`, tt.options)

Expand Down
17 changes: 9 additions & 8 deletions examples/experimental/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { check } from 'k6';
import { browser } from 'k6/experimental/browser';
import { browser } from 'k6/browser';

export const options = {
scenarios: {
Expand All @@ -18,8 +18,8 @@ export const options = {
}

export default async function() {
const context = browser.newContext();
const page = context.newPage();
const context = await browser.newContext();
const page = await context.newPage();

try {
// Goto front page, find login link and click it
Expand All @@ -29,19 +29,20 @@ export default async function() {
page.locator('a[href="/my_messages.php"]').click(),
]);
// Enter login credentials and login
page.locator('input[name="login"]').type('admin');
page.locator('input[name="password"]').type('123');
await page.locator('input[name="login"]').type("admin");
await page.locator('input[name="password"]').type("123");
// We expect the form submission to trigger a navigation, so to prevent a
// race condition, setup a waiter concurrently while waiting for the click
// to resolve.
await Promise.all([
page.waitForNavigation(),
page.locator('input[type="submit"]').click(),
]);
check(page, {
'header': p => p.locator('h2').textContent() == 'Welcome, admin!',
const content = await page.locator("h2").textContent();
check(content, {
'header': content => content == 'Welcome, admin!',
});
} finally {
page.close();
await page.close();
}
}
17 changes: 10 additions & 7 deletions js/jsmodules.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ func getInternalJSModules() map[string]interface{} {
"k6/experimental/timers is now part of the k6 core, please change your imports to use k6/timers instead."+
" The k6/experimental/timers will be removed in k6 v0.52.0"),
"k6/experimental/tracing": tracing.New(),
"k6/experimental/browser": browser.NewSync(),
"k6/experimental/fs": fs.New(),
"k6/net/grpc": grpc.New(),
"k6/html": html.New(),
"k6/http": http.New(),
"k6/metrics": metrics.New(),
"k6/ws": ws.New(),
"k6/experimental/browser": newWarnExperimentalModule(browser.NewSync(),
"k6/experimental/browser is now part of the k6 core, please change your imports to use k6/browser instead."+
" The k6/experimental/browser will be removed in k6 v0.54.0"),
ankur22 marked this conversation as resolved.
Show resolved Hide resolved
"k6/browser": browser.New(),
ankur22 marked this conversation as resolved.
Show resolved Hide resolved
"k6/experimental/fs": fs.New(),
"k6/net/grpc": grpc.New(),
"k6/html": html.New(),
"k6/http": http.New(),
"k6/metrics": metrics.New(),
"k6/ws": ws.New(),
"k6/experimental/grpc": newRemovedModule(
"k6/experimental/grpc has been graduated, please use k6/net/grpc instead." +
" See https://grafana.com/docs/k6/latest/javascript-api/k6-net-grpc/ for more information.",
Expand Down