-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Index HTML</title> | ||
</head> | ||
<body> | ||
|
||
<div id="test"> | ||
<button id="http">Make HTTP request</button> | ||
<a href="test.html" id="navigate">Navigate to another page</a> | ||
</div> | ||
|
||
</body> | ||
</html> | ||
|
||
<script> | ||
document.getElementById('http').addEventListener('click', async () => { | ||
fetch("https://get.geojs.io/v1/ip/country.json?ip=8.8.8.8") | ||
}) | ||
</script> |
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,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Test HTML</title> | ||
</head> | ||
<body> | ||
|
||
<div id="test"> | ||
<button id="http">Make HTTP request</button> | ||
</div> | ||
</body> | ||
</html> | ||
|
||
<script> | ||
document.getElementById('http').addEventListener('click', () => { | ||
fetch('https://www.google.com').then(console.log) | ||
}) | ||
</script> |
33 changes: 33 additions & 0 deletions
33
tests/vanilla/page/requests/testRequestInterception.test.mjs
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,33 @@ | ||
import {StageTest, correct, wrong} from "../../../../dist/hstest/index.js" | ||
import path from 'path' | ||
|
||
global.browserOptions = { | ||
args: ['--start-maximized', '--disable-infobar', '--disable-site-isolation-trials'] | ||
} | ||
|
||
const pagePath = path.join(import.meta.url, '../index.html') | ||
|
||
class TestRequestInterceptionTest extends StageTest { | ||
|
||
page = this.getPage(pagePath) | ||
|
||
tests = [ | ||
this.node.execute(async () => { | ||
const button = await this.page.findById('http'); | ||
await button.click() | ||
await new Promise(r => setTimeout(r, 2000)); | ||
if (this.page.requests.length !== 1) { | ||
return wrong('Expected only one request!') | ||
} | ||
await button.click() | ||
if (this.page.requests.length !== 2) { | ||
return wrong('Expected 2 requests!') | ||
} | ||
return correct() | ||
}) | ||
]; | ||
} | ||
|
||
it('Test request interception', async () => { | ||
await new TestRequestInterceptionTest().runTests() | ||
}).timeout(15000); |
34 changes: 34 additions & 0 deletions
34
tests/vanilla/page/requests/testRequestInterceptionAfterNavigation.test.mjs
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,34 @@ | ||
import {StageTest, correct, wrong} from "../../../../dist/hstest/index.js" | ||
import path from 'path' | ||
|
||
const pagePath = path.join(import.meta.url, '../index.html') | ||
|
||
class TestRequestInterceptionTest extends StageTest { | ||
|
||
page = this.getPage(pagePath) | ||
|
||
tests = [ | ||
this.node.execute(async () => { | ||
const button = await this.page.findById('http'); | ||
await button.click(); | ||
if (this.page.requests.length !== 1) { | ||
return wrong('Expected only one request'); | ||
} | ||
const navigateButton = await this.page.findById('navigate'); | ||
await navigateButton.clickForNavigation(); | ||
const anotherButton = await this.page.findById('http'); | ||
await anotherButton.click(); | ||
if (this.page.requests.length === 1) { | ||
return wrong('Expected more than 1 request'); | ||
} | ||
if (this.page.requests[0].url() !== 'https://get.geojs.io/v1/ip/country.json?ip=8.8.8.8') { | ||
return wrong('Wrong url') | ||
} | ||
return correct() | ||
}) | ||
]; | ||
} | ||
|
||
it('Test request interception', async () => { | ||
await new TestRequestInterceptionTest().runTests() | ||
}); |