Skip to content

Commit 18a2092

Browse files
committed
Adding support for testing of transparent file upload elements
1 parent 51fd82e commit 18a2092

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

Diff for: common/src/web/transparentUpload.html

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Upload Form</title>
5+
<style>
6+
.fileUpload {
7+
position: relative;
8+
overflow: hidden;
9+
margin: 10px;
10+
background-color: #FFFFFF;
11+
width: 50px;
12+
text-align: center;
13+
}
14+
.fileUpload input.upload {
15+
position: absolute;
16+
top: 0;
17+
right: 0;
18+
margin: 0;
19+
padding: 0;
20+
font-size: 20px;
21+
cursor: pointer;
22+
opacity: 0;
23+
filter: alpha(opacity=0);
24+
height: 100%;
25+
text-align: center;
26+
}
27+
</style>
28+
<script>
29+
var intervalId;
30+
function onTick() {
31+
var label = document.getElementById('upload_label');
32+
label.innerHTML += '.';
33+
}
34+
35+
function onUploadSubmit() {
36+
document.getElementById('upload_target').contentWindow.document.body.
37+
innerHTML = '';
38+
var label = document.getElementById('upload_label');
39+
label.innerHTML = 'Uploading "' + document.forms[0].upload.value + '"';
40+
label.style.display = '';
41+
intervalId = window.setInterval(onTick, 500);
42+
return true;
43+
}
44+
45+
function onUploadDone() {
46+
var label = document.getElementById('upload_label');
47+
label.style.display = 'none';
48+
window.clearInterval(intervalId);
49+
return true;
50+
}
51+
</script>
52+
</head>
53+
<body>
54+
<form action="/common/upload" method="post" name="upload_form"
55+
target="upload_target" enctype="multipart/form-data"
56+
onsubmit="onUploadSubmit();">
57+
<div>
58+
<div class="fileUpload">
59+
<span>Upload</span>
60+
<input id="upload" name="upload" type="file" class="upload" />
61+
</div>
62+
<div><input id="go" type="submit" value="Go!"/></div>
63+
</div>
64+
<div id="upload_label" style="display:none"></div>
65+
<iframe src="" id="upload_target" name="upload_target"
66+
style="width:300px;height:200px">
67+
</iframe>
68+
</form>
69+
</body>
70+
</html>

Diff for: dotnet/test/common/DriverTestFixture.cs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public abstract class DriverTestFixture
4444
public string rectanglesPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("rectangles.html");
4545
public string javascriptEnhancedForm = EnvironmentManager.Instance.UrlBuilder.WhereIs("javascriptEnhancedForm.html");
4646
public string uploadPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("upload.html");
47+
public string transparentUploadPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("transparentUpload.html");
4748
public string childPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("child/childPage.html");
4849
public string grandchildPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("child/grandchild/grandchildPage.html");
4950
public string documentWrite = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("document_write_in_onload.html");

Diff for: dotnet/test/common/UploadTest.cs

+20-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public class UploadTest : DriverTestFixture
1212
private const string FileHtml = "<div>" + LoremIpsumText + "</div>";
1313
private System.IO.FileInfo testFile;
1414

15-
[SetUp]
15+
[TestFixtureSetUp]
1616
public void Setup()
1717
{
1818
CreateTempFile(FileHtml);
1919
}
2020

21-
[TearDown]
21+
[TestFixtureTearDown]
2222
public void Teardown()
2323
{
2424
if (testFile != null && testFile.Exists)
@@ -40,6 +40,24 @@ public void ShouldAllowFileUploading()
4040

4141
IWebElement body = driver.FindElement(By.XPath("//body"));
4242
Assert.IsTrue(LoremIpsumText == body.Text, "Page source is: " + driver.PageSource);
43+
driver.Url = "about:blank";
44+
}
45+
46+
[Test]
47+
[Category("Javascript")]
48+
[IgnoreBrowser(Browser.WindowsPhone, "Does not yet support file uploads")]
49+
[IgnoreBrowser(Browser.IE, "Transparent file upload element not yet handled")]
50+
public void ShouldAllowFileUploadingUsingTransparentUploadElement()
51+
{
52+
driver.Url = transparentUploadPage;
53+
driver.FindElement(By.Id("upload")).SendKeys(testFile.FullName);
54+
driver.FindElement(By.Id("go")).Submit();
55+
56+
driver.SwitchTo().Frame("upload_target");
57+
58+
IWebElement body = driver.FindElement(By.XPath("//body"));
59+
Assert.IsTrue(LoremIpsumText == body.Text, "Page source is: " + driver.PageSource);
60+
driver.Url = "about:blank";
4361
}
4462

4563
private void CreateTempFile(string content)

0 commit comments

Comments
 (0)