Skip to content

Commit 0e39157

Browse files
committed
webdriven: Fixing attachFile command and adding a test for this command (it is not included in the suite because it should be run in local env only and can't be run on CI server at the moment)
1 parent 3a7e29e commit 0e39157

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

java/client/src/com/thoughtworks/selenium/webdriven/commands/AttachFile.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ private File downloadFile(String name) {
5555
URL url = getUrl(name);
5656

5757
File dir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("attachFile", "dir");
58-
File outputTo = new File(dir, url.getFile());
59-
if (!outputTo.getParentFile().mkdirs()) {
60-
throw new SeleniumException("Cannot create file for upload: " + outputTo);
61-
}
58+
File outputTo = new File(dir, new File(url.getFile()).getName());
6259

6360
FileOutputStream fos = null;
6461
try {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
19+
package com.thoughtworks.selenium.corebased;
20+
21+
import com.google.common.base.Charsets;
22+
import com.google.common.io.Files;
23+
24+
import com.thoughtworks.selenium.InternalSelenseTestBase;
25+
26+
import org.junit.Before;
27+
import org.junit.Test;
28+
29+
import java.io.File;
30+
import java.io.IOException;
31+
32+
public class TestAttachFile extends InternalSelenseTestBase {
33+
34+
private static final String LOREM_IPSUM_TEXT = "lorem ipsum dolor sit amet";
35+
private static final String FILE_HTML = "<div>" + LOREM_IPSUM_TEXT + "</div>";
36+
37+
private File testFile;
38+
39+
@Before
40+
public void setUp() throws Exception {
41+
testFile = createTmpFile(FILE_HTML);
42+
}
43+
44+
private File createTmpFile(String content) throws IOException {
45+
File f = File.createTempFile("webdriver", "tmp");
46+
f.deleteOnExit();
47+
Files.write(content, f, Charsets.UTF_8);
48+
return f;
49+
}
50+
51+
@Test
52+
public void testAttachFile() throws Exception {
53+
selenium.open("/common/upload.html");
54+
selenium.attachFile("upload", testFile.toURI().toURL().toString());
55+
selenium.click("go");
56+
selenium.waitForPageToLoad("30000");
57+
selenium.selectFrame("upload_target");
58+
assertEquals(selenium.getText("//body"), LOREM_IPSUM_TEXT);
59+
}
60+
}

0 commit comments

Comments
 (0)