Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/firefox/addon_test.js
2884 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 { Browser } = require('selenium-webdriver/index')
22
const { Pages, suite } = require('../../lib/test')
23
const { locate } = require('../../lib/test/resources')
24
const { until, By } = require('selenium-webdriver/index')
25
26
const EXT_XPI = locate('common/extensions/webextensions-selenium-example.xpi')
27
const EXT_UNSIGNED_ZIP = locate('common/extensions/webextensions-selenium-example-unsigned.zip')
28
const EXT_SIGNED_ZIP = locate('common/extensions/webextensions-selenium-example.zip')
29
const EXT_UNSIGNED_DIR = locate('common/extensions/webextensions-selenium-example')
30
const EXT_SIGNED_DIR = locate('common/extensions/webextensions-selenium-example')
31
32
suite(
33
function (env) {
34
describe('firefox', function () {
35
let driver
36
37
beforeEach(function () {
38
driver = null
39
})
40
41
afterEach(function () {
42
return driver && driver.quit()
43
})
44
45
describe('installAddon', function () {
46
beforeEach(function () {
47
driver = env.builder().build()
48
})
49
50
it('installs and uninstalls by xpi file', async function () {
51
await driver.get(Pages.blankPage)
52
await verifyWebExtensionNotInstalled()
53
54
let id = await driver.installAddon(EXT_XPI)
55
56
await driver.navigate().refresh()
57
await verifyWebExtensionWasInstalled()
58
59
await driver.uninstallAddon(id)
60
await driver.navigate().refresh()
61
await verifyWebExtensionNotInstalled()
62
})
63
64
it('installs and uninstalls by unsigned zip file', async function () {
65
await driver.get(Pages.blankPage)
66
await verifyWebExtensionNotInstalled()
67
68
let id = await driver.installAddon(EXT_UNSIGNED_ZIP, true)
69
70
await driver.navigate().refresh()
71
await verifyWebExtensionWasInstalled()
72
73
await driver.uninstallAddon(id)
74
await driver.navigate().refresh()
75
await verifyWebExtensionNotInstalled()
76
})
77
78
it('installs and uninstalls by signed zip file', async function () {
79
await driver.get(Pages.blankPage)
80
await verifyWebExtensionNotInstalled()
81
82
let id = await driver.installAddon(EXT_SIGNED_ZIP)
83
84
await driver.navigate().refresh()
85
await verifyWebExtensionWasInstalled()
86
87
await driver.uninstallAddon(id)
88
await driver.navigate().refresh()
89
await verifyWebExtensionNotInstalled()
90
})
91
92
it('installs and uninstalls by unsigned directory', async function () {
93
await driver.get(Pages.blankPage)
94
await verifyWebExtensionNotInstalled()
95
96
let id = await driver.installAddon(EXT_UNSIGNED_DIR, true)
97
98
await driver.navigate().refresh()
99
await verifyWebExtensionWasInstalled()
100
101
await driver.uninstallAddon(id)
102
await driver.navigate().refresh()
103
await verifyWebExtensionNotInstalled()
104
})
105
106
it('installs and uninstalls by signed directory', async function () {
107
await driver.get(Pages.blankPage)
108
await verifyWebExtensionNotInstalled()
109
110
let id = await driver.installAddon(EXT_SIGNED_DIR, true)
111
112
await driver.navigate().refresh()
113
await verifyWebExtensionWasInstalled()
114
115
await driver.uninstallAddon(id)
116
await driver.navigate().refresh()
117
await verifyWebExtensionNotInstalled()
118
})
119
})
120
121
async function verifyWebExtensionNotInstalled() {
122
let found = await driver.findElements({
123
id: 'webextensions-selenium-example',
124
})
125
assert.strictEqual(found.length, 0)
126
}
127
128
async function verifyWebExtensionWasInstalled() {
129
let footer = await driver.wait(until.elementLocated(By.id('webextensions-selenium-example')), 5000)
130
131
let text = await footer.getText()
132
assert.strictEqual(text, 'Content injected by webextensions-selenium-example')
133
}
134
})
135
},
136
{ browsers: [Browser.FIREFOX] },
137
)
138
139