Path: blob/trunk/javascript/selenium-webdriver/test/bidi/setFiles_command_test.js
2885 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const assert = require('node:assert')20require('../../lib/test/fileserver')21const { Pages, suite } = require('../../lib/test')22const { Browser, By } = require('selenium-webdriver')23const Input = require('selenium-webdriver/bidi/input')24const io = require('selenium-webdriver/io')25const { ReferenceValue, RemoteReferenceType } = require('selenium-webdriver/bidi/protocolValue')26const fs = require('node:fs')27const { ignore } = require('selenium-webdriver/testing')2829suite(30function (env) {31describe('Input Set Files', function () {32const FILE_HTML = '<!DOCTYPE html><div>' + 'Hello' + '</div>'33let driver3435let _fp36before(function () {37return (_fp = io.tmpFile().then(function (fp) {38fs.writeFileSync(fp, FILE_HTML)39return fp40}))41})4243beforeEach(async function () {44driver = await env.builder().build()45})4647afterEach(function () {48return driver.quit()49})5051ignore(env.browsers(Browser.FIREFOX)).it('can set files', async function () {52const browsingContextId = await driver.getWindowHandle()53const input = await Input(driver)54await driver.get(Pages.formPage)5556const filePath = await io.tmpFile().then(function (fp) {57fs.writeFileSync(fp, FILE_HTML)58return fp59})6061const webElement = await driver.findElement(By.id('upload'))6263assert.strictEqual(await webElement.getAttribute('value'), '')6465const webElementId = await webElement.getId()6667await input.setFiles(browsingContextId, new ReferenceValue(RemoteReferenceType.SHARED_ID, webElementId), [68filePath,69])7071assert.notEqual(await webElement.getAttribute('value'), '')72})7374ignore(env.browsers(Browser.FIREFOX)).it('can set files with element id', async function () {75const browsingContextId = await driver.getWindowHandle()76const input = await Input(driver)77await driver.get(Pages.formPage)7879const filePath = await io.tmpFile().then(function (fp) {80fs.writeFileSync(fp, FILE_HTML)81return fp82})8384const webElement = await driver.findElement(By.id('upload'))8586assert.strictEqual(await webElement.getAttribute('value'), '')8788const webElementId = await webElement.getId()8990await input.setFiles(browsingContextId, webElementId, filePath)9192assert.notEqual(await webElement.getAttribute('value'), '')93})94})95},96{ browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },97)9899100