Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/bidi/setFiles_command_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
require('../../lib/test/fileserver')
22
const { Pages, suite } = require('../../lib/test')
23
const { Browser, By } = require('selenium-webdriver')
24
const Input = require('selenium-webdriver/bidi/input')
25
const io = require('selenium-webdriver/io')
26
const { ReferenceValue, RemoteReferenceType } = require('selenium-webdriver/bidi/protocolValue')
27
const fs = require('node:fs')
28
const { ignore } = require('selenium-webdriver/testing')
29
30
suite(
31
function (env) {
32
describe('Input Set Files', function () {
33
const FILE_HTML = '<!DOCTYPE html><div>' + 'Hello' + '</div>'
34
let driver
35
36
let _fp
37
before(function () {
38
return (_fp = io.tmpFile().then(function (fp) {
39
fs.writeFileSync(fp, FILE_HTML)
40
return fp
41
}))
42
})
43
44
beforeEach(async function () {
45
driver = await env.builder().build()
46
})
47
48
afterEach(function () {
49
return driver.quit()
50
})
51
52
ignore(env.browsers(Browser.FIREFOX)).it('can set files', async function () {
53
const browsingContextId = await driver.getWindowHandle()
54
const input = await Input(driver)
55
await driver.get(Pages.formPage)
56
57
const filePath = await io.tmpFile().then(function (fp) {
58
fs.writeFileSync(fp, FILE_HTML)
59
return fp
60
})
61
62
const webElement = await driver.findElement(By.id('upload'))
63
64
assert.strictEqual(await webElement.getAttribute('value'), '')
65
66
const webElementId = await webElement.getId()
67
68
await input.setFiles(browsingContextId, new ReferenceValue(RemoteReferenceType.SHARED_ID, webElementId), [
69
filePath,
70
])
71
72
assert.notEqual(await webElement.getAttribute('value'), '')
73
})
74
75
ignore(env.browsers(Browser.FIREFOX)).it('can set files with element id', async function () {
76
const browsingContextId = await driver.getWindowHandle()
77
const input = await Input(driver)
78
await driver.get(Pages.formPage)
79
80
const filePath = await io.tmpFile().then(function (fp) {
81
fs.writeFileSync(fp, FILE_HTML)
82
return fp
83
})
84
85
const webElement = await driver.findElement(By.id('upload'))
86
87
assert.strictEqual(await webElement.getAttribute('value'), '')
88
89
const webElementId = await webElement.getId()
90
91
await input.setFiles(browsingContextId, webElementId, filePath)
92
93
assert.notEqual(await webElement.getAttribute('value'), '')
94
})
95
})
96
},
97
{ browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },
98
)
99
100