Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/chrome/permission_test.js
2885 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
'use strict'
19
20
const assert = require('node:assert')
21
const chrome = require('selenium-webdriver/chrome')
22
const test = require('../../lib/test')
23
const { ignore } = require('../../lib/test')
24
const { Browser } = require('selenium-webdriver/index')
25
26
test.suite(
27
function (env) {
28
// Chrome unable to set "prompt" due to: https://bugs.chromium.org/p/chromedriver/issues/detail?id=4350
29
describe('setPermission', () => {
30
ignore(env.browsers(Browser.CHROME)).it('can set permission', async function () {
31
const driver = await env.builder().build()
32
33
await driver.get(test.Pages.clicksPage)
34
35
await driver.setPermission('clipboard-read', 'prompt')
36
assert.strictEqual(await checkPermission(driver, 'clipboard-read'), 'prompt')
37
38
await driver.setPermission('clipboard-read', 'granted')
39
assert.strictEqual(await checkPermission(driver, 'clipboard-read'), 'granted')
40
41
await driver.quit()
42
})
43
44
ignore(env.browsers(Browser.CHROME)).it('can set permission in headless mode', async function () {
45
const driver = await env.builder().setChromeOptions(new chrome.Options().addArguments('-headless')).build()
46
47
await driver.get(test.Pages.clicksPage)
48
49
await driver.setPermission('clipboard-read', 'prompt')
50
assert.strictEqual(await checkPermission(driver, 'clipboard-read'), 'prompt')
51
52
await driver.setPermission('clipboard-read', 'granted')
53
assert.strictEqual(await checkPermission(driver, 'clipboard-read'), 'granted')
54
55
await driver.quit()
56
})
57
})
58
},
59
{ browsers: ['chrome'] },
60
)
61
62
const checkPermission = (driver, permission) => {
63
return driver.executeAsyncScript((permission, callback) => {
64
// eslint-disable-next-line
65
navigator.permissions.query({ name: permission }).then((result) => callback(result.state))
66
}, permission)
67
}
68
69