Skip to content

Commit 1df5daf

Browse files
committed
Adding a new test for file upload using a hidden file input. Also disabling file input visibility check in legacy Firefox driver. Fixes #706
1 parent 9cb14e8 commit 1df5daf

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Upload Form</title>
5+
<script>
6+
var intervalId;
7+
function onTick() {
8+
var label = document.getElementById('upload_label');
9+
label.innerHTML += '.';
10+
}
11+
12+
function onUploadSubmit() {
13+
document.getElementById('upload_target').contentWindow.document.body.
14+
innerHTML = '';
15+
var label = document.getElementById('upload_label');
16+
label.innerHTML = 'Uploading "' + document.forms[0].upload.value + '"';
17+
label.style.display = '';
18+
intervalId = window.setInterval(onTick, 500);
19+
return true;
20+
}
21+
22+
function onUploadDone() {
23+
var label = document.getElementById('upload_label');
24+
label.style.display = 'none';
25+
window.clearInterval(intervalId);
26+
return true;
27+
}
28+
</script>
29+
</head>
30+
<body>
31+
<form action="/common/upload" method="post" name="upload_form"
32+
target="upload_target" enctype="multipart/form-data"
33+
onsubmit="onUploadSubmit();">
34+
<div style='height: 0; width: 0; overflow: hidden;'>
35+
<div><input id="upload" name="upload" type="file"/></div>
36+
</div>
37+
<label id="visible_label" for="upload">Upload</label>
38+
<div><input id="go" type="submit" value="Go!"/></div>
39+
<div id="upload_label" style="display:none"></div>
40+
<iframe src="" id="upload_target" name="upload_target"
41+
style="width:300px;height:200px">
42+
</iframe>
43+
</form>
44+
</body>
45+
</html>

java/client/test/org/openqa/selenium/UploadTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ public void testClickFileInput() throws Exception {
106106
assertThat(ex, instanceOf(InvalidArgumentException.class));
107107
}
108108

109+
@Test
110+
public void testUploadingWithHiddenFileInput() throws Exception {
111+
driver.get(appServer.whereIs("upload_invisible.html"));
112+
driver.findElement(By.id("upload")).sendKeys(testFile.getAbsolutePath());
113+
driver.findElement(By.id("go")).click();
114+
115+
// Uploading files across a network may take a while, even if they're really small
116+
WebElement label = driver.findElement(By.id("upload_label"));
117+
wait.until(not(visibilityOf(label)));
118+
119+
driver.switchTo().frame("upload_target");
120+
121+
WebElement body = driver.findElement(By.xpath("//body"));
122+
wait.until(elementTextToEqual(body, LOREM_IPSUM_TEXT));
123+
124+
}
125+
109126
private File createTmpFile(String content) throws IOException {
110127
File f = File.createTempFile("webdriver", "tmp");
111128
f.deleteOnExit();

javascript/firefox-driver/js/preconditions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ goog.require('bot.dom');
3535
fxdriver.preconditions.visible = function(doc, parameters) {
3636
var element = Utils.getElementAt(parameters.id, doc);
3737

38+
if (bot.dom.isElement(element, goog.dom.TagName.INPUT)) {
39+
var inputtype = element.getAttribute('type');
40+
if (inputtype && inputtype.toLowerCase() == 'file') {
41+
return;
42+
}
43+
}
44+
3845
if (!bot.dom.isShown(element, /*ignoreOpacity=*/true)) {
3946
return new WebDriverError(bot.ErrorCode.ELEMENT_NOT_VISIBLE,
4047
'Element is not currently visible and so may not be interacted with');

0 commit comments

Comments
 (0)