-
Notifications
You must be signed in to change notification settings - Fork 171
/
Upload.java
41 lines (34 loc) · 1.19 KB
/
Upload.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package src.test.java;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import java.io.File;
public class Upload {
WebDriver driver;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
// If uploading to a Grid node or Sauce Labs, check out driver.setFileDetector()
// https://saucelabs.com/resources/articles/selenium-file-upload
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void uploadFile() throws Exception {
String filename = "some-file.txt";
File file = new File(filename);
String path = file.getAbsolutePath();
driver.get("http://the-internet.herokuapp.com/upload");
driver.findElement(By.id("file-upload")).sendKeys(path);
driver.findElement(By.id("file-submit")).click();
String text = driver.findElement(By.id("uploaded-files")).getText();
assertThat(text, is(equalTo(filename)));
}
}