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

add options example #108

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@ console.log(result);
await browser.close();
```

Run basic test scenarios with path and other options.

```js
/* basic working example for a UI test with macOS specific path
* deno test -A ./page-content-test.js
* see also https://docs.deno.com/runtime/fundamentals/testing/
* */
import { launch } from "jsr:@astral/astral";
import { assert } from "jsr:@std/assert";

const browser = await launch({
// macOS specific path option
path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
args: ['--remote-debugging-port=9222', '--headless=new', '--no-first-run', '--password-store=basic', '--use-mock-keychain', '--hide-scrollbars', '--no-sandbox']
});

const page = await browser.newPage("https://deno.com");

// Run code in the context of the browser
const text = await page.evaluate(() => {
return document.body.querySelector('main h1')?.textContent ?? '';
});

assert(text.includes('JavaScript'), 'has JavaScript');

await browser.close();

```

You can navigate to a page and interact with it.

```ts
Expand Down
23 changes: 23 additions & 0 deletions examples/page-content-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* basic working example for a UI test with macOS specific path
* deno test -A ./page-content-test.js
* see also https://docs.deno.com/runtime/fundamentals/testing/
* */
import { launch } from "jsr:@astral/astral";
import { assert } from "jsr:@std/assert";

const browser = await launch({
// macOS specific path option
path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
args: ['--remote-debugging-port=9222', '--headless=new', '--no-first-run', '--password-store=basic', '--use-mock-keychain', '--hide-scrollbars', '--no-sandbox']
});

const page = await browser.newPage("https://deno.com");

// Run code in the context of the browser
const text = await page.evaluate(() => {
return document.body.querySelector('main h1')?.textContent ?? '';
});

assert(text.includes('JavaScript'), 'has JavaScript');

await browser.close();
Loading