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

feat(Page): add `setCacheEnabled(enabled)` to Page object #1609

Merged
merged 2 commits into from Feb 8, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -86,6 +86,7 @@
* [page.reload(options)](#pagereloadoptions)
* [page.screenshot([options])](#pagescreenshotoptions)
* [page.select(selector, ...values)](#pageselectselector-values)
* [page.setCacheEnabled(enabled)](#pagesetcacheenabledenabled)
* [page.setContent(html)](#pagesetcontenthtml)
* [page.setCookie(...cookies)](#pagesetcookiecookies)
* [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout)
@@ -1150,6 +1151,12 @@ page.select('select#colors', 'red', 'green', 'blue'); // multiple selections

Shortcut for [page.mainFrame().select()](#frameselectselector-values)

#### page.setCacheEnabled(enabled)
- `enabled` <[boolean]> sets the `enabled` state of the cache.
- returns: <[Promise]>

Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled.

#### page.setContent(html)
- `html` <[string]> HTML markup to assign to the page.
- returns: <[Promise]>
@@ -650,6 +650,14 @@ class Page extends EventEmitter {
await this._client.send('Page.addScriptToEvaluateOnNewDocument', { source });
}

/**
* @param {Boolean} enabled
* @returns {!Promise}
*/
async setCacheEnabled(enabled = true) {
await this._client.send('Network.setCacheDisabled', {cacheDisabled: !enabled});
}

/**
* @param {!Object=} options
* @return {!Promise<!Buffer>}
@@ -3050,6 +3050,21 @@ describe('Page', function() {
});
});

describe('Page.setCacheEnabled', function() {
it('should enable or disable the cache based on the state passed', async({page, server}) => {
const responses = new Map();
page.on('response', r => responses.set(r.url().split('/').pop(), r));

await page.goto(server.PREFIX + '/cached/one-style.html', {waitUntil: 'networkidle2'});
await page.reload({waitUntil: 'networkidle2'});
expect(responses.get('one-style.css').fromCache()).toBe(true);

await page.setCacheEnabled(false);
await page.reload({waitUntil: 'networkidle2'});
expect(responses.get('one-style.css').fromCache()).toBe(false);
});
});

// Printing to pdf is currently only supported in headless
(headless ? describe : xdescribe)('Page.pdf', function() {
it('should be able to save file', async({page, server}) => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.