|
20 | 20 | const assert = require('node:assert')
|
21 | 21 | const { Browser } = require('selenium-webdriver')
|
22 | 22 | const { Pages, suite, ignore } = require('../../lib/test')
|
23 |
| -const Network = require('selenium-webdriver/bidi/network') |
| 23 | +const { Network, CacheBehavior } = require('selenium-webdriver/bidi/network') |
| 24 | +const BrowsingContext = require('selenium-webdriver/bidi/browsingContext') |
24 | 25 | const until = require('selenium-webdriver/lib/until')
|
25 | 26 |
|
26 | 27 | suite(
|
@@ -212,6 +213,52 @@ suite(
|
212 | 213 | assert(onResponseCompleted[0].response.mimeType.includes('text/plain'))
|
213 | 214 | })
|
214 | 215 | })
|
| 216 | + |
| 217 | + describe('setCacheBehavior', function () { |
| 218 | + it('can set cache behavior to bypass for a context', async function () { |
| 219 | + await driver.get(Pages.emptyPage) |
| 220 | + const browsingContext = await BrowsingContext(driver, { |
| 221 | + type: 'tab', |
| 222 | + }) |
| 223 | + const contextId = browsingContext.id |
| 224 | + await network.setCacheBehavior(CacheBehavior.BYPASS, [contextId]) |
| 225 | + }) |
| 226 | + |
| 227 | + it('can set cache behavior to default for a context', async function () { |
| 228 | + await driver.get(Pages.emptyPage) |
| 229 | + const browsingContext = await BrowsingContext(driver, { |
| 230 | + type: 'tab', |
| 231 | + }) |
| 232 | + const contextId = browsingContext.id |
| 233 | + await network.setCacheBehavior(CacheBehavior.DEFAULT, [contextId]) |
| 234 | + }) |
| 235 | + |
| 236 | + it('can set cache behavior to default/bypass with no context id', async function () { |
| 237 | + await driver.get(Pages.emptyPage) |
| 238 | + await network.setCacheBehavior(CacheBehavior.DEFAULT) |
| 239 | + await network.setCacheBehavior(CacheBehavior.BYPASS) |
| 240 | + }) |
| 241 | + |
| 242 | + it('throws error for invalid cache behavior', async function () { |
| 243 | + await driver.get(Pages.emptyPage) |
| 244 | + await assert.rejects( |
| 245 | + async () => await network.setCacheBehavior('invalid'), |
| 246 | + /Cache behavior must be either "default" or "bypass"/, |
| 247 | + ) |
| 248 | + }) |
| 249 | + |
| 250 | + it('throws error for invalid context id types', async function () { |
| 251 | + await driver.get(Pages.emptyPage) |
| 252 | + await assert.rejects( |
| 253 | + async () => await network.setCacheBehavior(CacheBehavior.BYPASS, ''), |
| 254 | + /Contexts must be an array of non-empty strings/, |
| 255 | + ) |
| 256 | + await assert.rejects( |
| 257 | + async () => await network.setCacheBehavior(CacheBehavior.BYPASS, ['', ' ']), |
| 258 | + /Contexts must be an array of non-empty strings/, |
| 259 | + ) |
| 260 | + }) |
| 261 | + }) |
215 | 262 | },
|
216 | 263 | { browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },
|
217 | 264 | )
|
0 commit comments