Skip to content

Commit 4e77ee1

Browse files
committed
[Java] Move code sample to github
1 parent 470e0c9 commit 4e77ee1

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11
package dev.selenium.elements;
22

3-
import dev.selenium.BaseTest;
3+
import org.junit.jupiter.api.Test;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.WebElement;
7+
import org.openqa.selenium.chrome.ChromeDriver;
8+
import java.time.Duration;
49

5-
public class FileUploadTest extends BaseTest {
10+
import java.io.File;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
13+
import java.time.Duration;
614

7-
}
15+
public class FileUploadTest {
16+
17+
@Test
18+
public void fileUploadTest() {
19+
WebDriver driver = new ChromeDriver();
20+
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(1000));
21+
driver.get("https://the-internet.herokuapp.com/upload");
22+
Path path = Paths.get("src/test/resources/selenium-snapshot.png");
23+
File imagePath = new File(path.toUri());
24+
25+
//we want to import selenium-snapshot file.
26+
driver.findElement(By.id("file-upload")).sendKeys(imagePath.toString());
27+
driver.findElement(By.id("file-submit")).submit();
28+
if(driver.getPageSource().contains("File Uploaded!")) {
29+
System.out.println("file uploaded");
30+
}
31+
else{
32+
System.out.println("file not uploaded");
33+
}
34+
driver.quit();
35+
}
36+
}
Loading

0 commit comments

Comments
 (0)