Skip to content

Commit

Permalink
Merge e4feddc into 44d7840
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus authored Jun 12, 2024
2 parents 44d7840 + e4feddc commit 814e655
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 18 deletions.
39 changes: 36 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';
%s
export default function() {
browser.isConnected();
browser.isConnected()
};
`, tt.options)

Expand All @@ -2319,6 +2319,39 @@ func TestBrowserPermissions(t *testing.T) {
}
}

func TestBrowserExperimentalImport(t *testing.T) {
t.Parallel()

const script = `
import { browser } from 'k6/experimental/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}
export default function() {
browser.isConnected()
};
`

const wantExitCode = 108
ts := getSingleFileTestState(t, script, []string{}, wantExitCode)
ts.Env["K6_BROWSER_EXECUTABLE_PATH"] = "k6-browser-fake-cmd"
cmd.ExecuteWithGlobalState(ts.GlobalState)
loglines := ts.LoggerHook.Drain()

assert.Contains(t, loglines[0].Message, "use k6/browser instead of k6/experimental/browser")
}

func TestSetupTimeout(t *testing.T) {
t.Parallel()
ts := NewGlobalTestState(t)
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();
}
}
19 changes: 12 additions & 7 deletions js/jsmodules.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ 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(),
"Please update your imports to use k6/browser instead of k6/experimental/browser,"+
" which will be removed after September 23rd, 2024. Ensure your scripts are migrated by then."+
" For more information, see the migration guide at the link:"+
" https://grafana.com/docs/k6/latest/using-k6-browser/migrating-to-k6-v0-52/"),
"k6/browser": browser.New(),
"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

0 comments on commit 814e655

Please sign in to comment.