-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bidi][java][js] Add setFiles command of the Input Module (#13711)
- Loading branch information
Showing
5 changed files
with
301 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
java/test/org/openqa/selenium/bidi/input/SetFilesCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.bidi.input; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.openqa.selenium.testing.drivers.Browser.EDGE; | ||
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX; | ||
import static org.openqa.selenium.testing.drivers.Browser.IE; | ||
import static org.openqa.selenium.testing.drivers.Browser.SAFARI; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.bidi.module.Input; | ||
import org.openqa.selenium.bidi.script.RemoteReference; | ||
import org.openqa.selenium.environment.webserver.AppServer; | ||
import org.openqa.selenium.environment.webserver.NettyAppServer; | ||
import org.openqa.selenium.remote.RemoteWebElement; | ||
import org.openqa.selenium.testing.JupiterTestBase; | ||
import org.openqa.selenium.testing.NotYetImplemented; | ||
|
||
public class SetFilesCommandTest extends JupiterTestBase { | ||
private Input input; | ||
|
||
private String windowHandle; | ||
|
||
private AppServer server; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
windowHandle = driver.getWindowHandle(); | ||
input = new Input(driver); | ||
server = new NettyAppServer(); | ||
server.start(); | ||
} | ||
|
||
@Test | ||
@NotYetImplemented(SAFARI) | ||
@NotYetImplemented(IE) | ||
@NotYetImplemented(EDGE) | ||
@NotYetImplemented(FIREFOX) | ||
void canSetFiles() throws IOException { | ||
driver.get(pages.formPage); | ||
WebElement uploadElement = driver.findElement(By.id("upload")); | ||
assertThat(uploadElement.getAttribute("value")).isEmpty(); | ||
|
||
File file = File.createTempFile("test", "txt"); | ||
file.deleteOnExit(); | ||
|
||
List<String> paths = new ArrayList<>(); | ||
paths.add(file.getAbsolutePath()); | ||
|
||
input.setFiles( | ||
windowHandle, | ||
new RemoteReference( | ||
RemoteReference.Type.SHARED_ID, ((RemoteWebElement) uploadElement).getId()), | ||
paths); | ||
|
||
assertThat(uploadElement.getAttribute("value")).endsWith(file.getName()); | ||
} | ||
|
||
@Test | ||
@NotYetImplemented(SAFARI) | ||
@NotYetImplemented(IE) | ||
@NotYetImplemented(EDGE) | ||
@NotYetImplemented(FIREFOX) | ||
public void canSetFilesWithElementId() throws IOException { | ||
driver.get(pages.formPage); | ||
WebElement uploadElement = driver.findElement(By.id("upload")); | ||
assertThat(uploadElement.getAttribute("value")).isEmpty(); | ||
|
||
File file = File.createTempFile("test", "txt"); | ||
file.deleteOnExit(); | ||
|
||
List<String> paths = new ArrayList<>(); | ||
paths.add(file.getAbsolutePath()); | ||
|
||
input.setFiles(windowHandle, ((RemoteWebElement) uploadElement).getId(), paths); | ||
|
||
assertThat(uploadElement.getAttribute("value")).endsWith(file.getName()); | ||
} | ||
|
||
@Test | ||
@NotYetImplemented(SAFARI) | ||
@NotYetImplemented(IE) | ||
@NotYetImplemented(EDGE) | ||
@NotYetImplemented(FIREFOX) | ||
void canSetFile() throws IOException { | ||
driver.get(pages.formPage); | ||
WebElement uploadElement = driver.findElement(By.id("upload")); | ||
assertThat(uploadElement.getAttribute("value")).isEmpty(); | ||
|
||
File file = File.createTempFile("test", "txt"); | ||
file.deleteOnExit(); | ||
|
||
input.setFiles( | ||
windowHandle, | ||
new RemoteReference( | ||
RemoteReference.Type.SHARED_ID, ((RemoteWebElement) uploadElement).getId()), | ||
file.getAbsolutePath()); | ||
|
||
assertThat(uploadElement.getAttribute("value")).endsWith(file.getName()); | ||
} | ||
|
||
@Test | ||
@NotYetImplemented(SAFARI) | ||
@NotYetImplemented(IE) | ||
@NotYetImplemented(EDGE) | ||
@NotYetImplemented(FIREFOX) | ||
void canSetFileWithElementId() throws IOException { | ||
driver.get(pages.formPage); | ||
WebElement uploadElement = driver.findElement(By.id("upload")); | ||
assertThat(uploadElement.getAttribute("value")).isEmpty(); | ||
|
||
File file = File.createTempFile("test", "txt"); | ||
file.deleteOnExit(); | ||
|
||
input.setFiles( | ||
windowHandle, ((RemoteWebElement) uploadElement).getId(), file.getAbsolutePath()); | ||
|
||
assertThat(uploadElement.getAttribute("value")).endsWith(file.getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
javascript/node/selenium-webdriver/test/bidi/setFiles_command_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
'use strict' | ||
|
||
const assert = require('assert') | ||
require('../../lib/test/fileserver') | ||
const firefox = require('../../firefox') | ||
const { Pages, suite } = require('../../lib/test') | ||
const { Browser, By } = require('../..') | ||
const Input = require('../../bidi/input') | ||
const io = require('../../io') | ||
const fs = require('node:fs') | ||
const { ReferenceValue, RemoteReferenceType } = require('../../bidi/protocolValue') | ||
|
||
suite( | ||
function (env) { | ||
describe('Input Set Files', function () { | ||
const FILE_HTML = '<!DOCTYPE html><div>' + 'Hello' + '</div>' | ||
let driver | ||
|
||
let _fp | ||
before(function () { | ||
return (_fp = io.tmpFile().then(function (fp) { | ||
fs.writeFileSync(fp, FILE_HTML) | ||
return fp | ||
})) | ||
}) | ||
|
||
beforeEach(async function () { | ||
driver = await env.builder().setFirefoxOptions(new firefox.Options().enableBidi()).build() | ||
}) | ||
|
||
afterEach(function () { | ||
return driver.quit() | ||
}) | ||
|
||
xit('can set files', async function () { | ||
const browsingContextId = await driver.getWindowHandle() | ||
const input = await Input(driver) | ||
await driver.get(Pages.formPage) | ||
|
||
const filePath = await io.tmpFile().then(function(fp) { | ||
fs.writeFileSync(fp, FILE_HTML) | ||
return fp | ||
}) | ||
|
||
const webElement = await driver.findElement(By.id('upload')) | ||
|
||
assert.strictEqual(await webElement.getAttribute('value'), '') | ||
|
||
const webElementId = await webElement.getId() | ||
|
||
await input.setFiles(browsingContextId, new ReferenceValue(RemoteReferenceType.SHARED_ID, webElementId), [filePath]) | ||
|
||
assert.notEqual(await webElement.getAttribute('value'), '') | ||
}) | ||
|
||
xit('can set files with element id', async function () { | ||
const browsingContextId = await driver.getWindowHandle() | ||
const input = await Input(driver) | ||
await driver.get(Pages.formPage) | ||
|
||
const filePath = await io.tmpFile().then(function(fp) { | ||
fs.writeFileSync(fp, FILE_HTML) | ||
return fp | ||
}) | ||
|
||
const webElement = await driver.findElement(By.id('upload')) | ||
|
||
assert.strictEqual(await webElement.getAttribute('value'), '') | ||
|
||
const webElementId = await webElement.getId() | ||
|
||
await input.setFiles(browsingContextId, webElementId, filePath) | ||
|
||
assert.notEqual(await webElement.getAttribute('value'), '') | ||
}) | ||
}) | ||
}, | ||
{ browsers: [Browser.FIREFOX] }, | ||
) |