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

fix(docs): clarify repeating calls to setHTTPCredentials #2212

Merged
merged 1 commit into from
May 13, 2020
Merged
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
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});

Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).

To disable authentication, pass `null`.
> **NOTE** Browsers may cache credentials that resulted in successfull auth. That means passing different credentials after successfull authentication or passing `null` to disable authentication is unreliable. Instead, create a separate browser context that will not have previous credentials cached.

#### browserContext.setOffline(offline)
- `offline` <[boolean]> Whether to emulate network being offline for the browser context.
Expand Down
26 changes: 26 additions & 0 deletions test/browsercontext.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,32 @@ describe('BrowserContext.setHTTPCredentials', function() {
expect(response.status()).toBe(401);
await context.close();
});
it.fail(true)('should update', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'user', password: 'pass' }
});
const page = await context.newPage();
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await context.setHTTPCredentials({ username: 'user', password: 'letmein' });
response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await context.close();
});
it.fail(true)('should update to null', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'user', password: 'pass' }
});
const page = await context.newPage();
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await context.setHTTPCredentials(null);
response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await context.close();
});
it('should return resource body', async({browser, server}) => {
server.setAuth('/playground.html', 'user', 'pass');
const context = await browser.newContext({
Expand Down