Skip to content

Commit c0e91b9

Browse files
committed
webdriven: attachFile should throw an exception if the file is not found or can't be accessed
1 parent 437725c commit c0e91b9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private File downloadFile(String name) {
6262
fos = new FileOutputStream(outputTo);
6363
Resources.copy(url, fos);
6464
} catch (IOException e) {
65-
65+
throw new SeleniumException("Can't access file to upload: " + url, e);
6666
}
6767

6868
return outputTo;

java/client/test/com/thoughtworks/selenium/corebased/TestAttachFile.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import com.google.common.io.Files;
2323

2424
import com.thoughtworks.selenium.InternalSelenseTestBase;
25+
import com.thoughtworks.selenium.SeleniumException;
2526

2627
import org.junit.Before;
2728
import org.junit.Test;
2829

2930
import java.io.File;
31+
import java.io.FileNotFoundException;
3032
import java.io.IOException;
3133

3234
public class TestAttachFile extends InternalSelenseTestBase {
@@ -57,4 +59,16 @@ public void testAttachFile() throws Exception {
5759
selenium.selectFrame("upload_target");
5860
assertEquals(selenium.getText("//body"), LOREM_IPSUM_TEXT);
5961
}
62+
63+
@Test
64+
public void testAttachNonExistingFile() throws Exception {
65+
selenium.open("/common/upload.html");
66+
try {
67+
selenium.attachFile("upload", testFile.toURI().toURL().toString() + "-missing");
68+
} catch (SeleniumException expected) {
69+
assertTrue(expected.getCause() instanceof IOException);
70+
return;
71+
}
72+
fail("Exception expected");
73+
}
6074
}

0 commit comments

Comments
 (0)