-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from lowlighter/feat-page-set-content
feat: add `page.setContent`
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { assertStrictEquals } from "https://deno.land/[email protected]/assert/assert_strict_equals.ts"; | ||
import { launch } from "../mod.ts"; | ||
|
||
Deno.test("Set content", async () => { | ||
// Launch browser | ||
const browser = await launch(); | ||
const content = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Astral</title> | ||
</head> | ||
<body> | ||
<span>Hello world</span> | ||
</body> | ||
</html>`; | ||
|
||
// Open the webpage and set content | ||
const page = await browser.newPage(); | ||
await page.setContent(content); | ||
|
||
// Wait for selector | ||
assertStrictEquals( | ||
content.replace(/\s/g, ""), | ||
`${await page.content()}`.replace(/\s/g, ""), | ||
); | ||
const selected = await page.waitForSelector("span"); | ||
assertStrictEquals(await selected.innerText(), "Hello world"); | ||
|
||
// Close browser | ||
await browser.close(); | ||
}); |