-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Thank you for your contribution. Before making a PR, please read our contributing guidelines at https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution We recommend creating a *draft* PR, so that you can mark it as 'ready for review' when you are done. --> ## Purpose Add tests for the [corresponding PR in HH](DevExpress/testcafe-hammerhead#2890) ## Approach _Describe how your changes address the issue or implement the desired functionality in as much detail as possible._ ## References DevExpress/testcafe-hammerhead#2890 ## Pre-Merge TODO - [ ] Write tests for your proposed changes - [ ] Make sure that existing tests do not fail
- Loading branch information
Showing
5 changed files
with
119 additions
and
1 deletion.
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
75 changes: 75 additions & 0 deletions
75
test/functional/fixtures/request-pipeline/xhr/pages/index.html
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,75 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>XMLHttpRequest</title> | ||
</head> | ||
<body> | ||
<form action="submit.html"> | ||
<input type="button" id="test-header" value="test-header"/> | ||
<input type="button" id="auth-header" value="auth-header"/> | ||
<input type="button" id="delay" value="delay"/> | ||
</form> | ||
|
||
<script> | ||
document.querySelector('#test-header').addEventListener('click', () => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('POST', '/xhr/test-header'); | ||
xhr.setRequestHeader('test', 'test-string'); | ||
xhr.withCredentials = true; | ||
xhr.send(); | ||
|
||
xhr.onload = function() { | ||
if (xhr.status = 200) { | ||
const xhrResultDiv = document.createElement('div'); | ||
|
||
xhrResultDiv.id = 'xhr-result'; | ||
xhrResultDiv.textContent = xhr.responseText; | ||
|
||
document.body.appendChild(xhrResultDiv); | ||
} | ||
}; | ||
}) | ||
|
||
document.querySelector('#auth-header').addEventListener('click', () => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('POST', '/xhr/auth-header'); | ||
xhr.setRequestHeader('authorization', 'authorization-string'); | ||
xhr.send(); | ||
|
||
xhr.onload = function() { | ||
if (xhr.status = 200) { | ||
const xhrResultDiv = document.createElement('div'); | ||
|
||
xhrResultDiv.id = 'xhr-result'; | ||
xhrResultDiv.textContent = xhr.getResponseHeader('authorization'); | ||
|
||
document.body.appendChild(xhrResultDiv); | ||
} | ||
}; | ||
}) | ||
|
||
document.querySelector('#delay').addEventListener('click', () => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('POST', '/xhr/1000', true); | ||
xhr.send(); | ||
|
||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState != 4) return; | ||
|
||
if (xhr.status === 200) { | ||
const xhrResultDiv = document.createElement('div'); | ||
|
||
xhrResultDiv.id = 'xhr-result'; | ||
xhrResultDiv.textContent = xhr.responseText; | ||
|
||
xhrResultDiv.addEventListener('click', function () { | ||
throw new Error('Xhr requests are finished'); | ||
}); | ||
|
||
document.body.appendChild(xhrResultDiv); | ||
} | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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,18 @@ | ||
const { errorInEachBrowserContains } = require('../../../assertion-helper.js'); | ||
|
||
describe('XHR', () => { | ||
it('Should keep header if request was reopened', () => { | ||
return runTests('./testcafe-fixtures/index.js', 'Click test header button'); | ||
}); | ||
|
||
it('Should not return authorization prefix for the authorization header', () => { | ||
return runTests('./testcafe-fixtures/index.js', 'Click auth header button'); | ||
}); | ||
|
||
it('Should wait for xhr-requests after an action', () => { | ||
return runTests('./testcafe-fixtures/index.js', 'Click delay button', { shouldFail: true }) | ||
.catch(errs => { | ||
errorInEachBrowserContains(errs, 'Xhr requests are finished', 0); | ||
}); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
test/functional/fixtures/request-pipeline/xhr/testcafe-fixtures/index.js
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,16 @@ | ||
import { Selector } from 'testcafe'; | ||
|
||
fixture('My fixture') | ||
.page('http://localhost:3000/fixtures/request-pipeline/xhr/pages/index.html'); | ||
test('Click test header button', async t => { | ||
await t.click('#test-header'); | ||
await t.expect(Selector('#xhr-result').textContent).eql('test-string'); | ||
}); | ||
test('Click auth header button', async t => { | ||
await t.click('#auth-header'); | ||
await t.expect(Selector('#xhr-result').textContent).eql('authorization-string'); | ||
}); | ||
test('Click delay button', async t => { | ||
await t.click('#delay'); | ||
await t.click('#xhr-result'); | ||
}); |
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