Skip to content

Commit e846b8e

Browse files
committed
File upload
1 parent 499f21f commit e846b8e

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package pages;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
6+
public class FileUploadPage {
7+
8+
private WebDriver driver;
9+
private By inputField = By.id("file-upload");
10+
private By uploadButton = By.id("file-submit");
11+
private By uploadedFiles = By.id("uploaded-files");
12+
13+
public FileUploadPage(WebDriver driver){
14+
this.driver = driver;
15+
}
16+
17+
public void clickUploadButton(){
18+
driver.findElement(uploadButton).click();
19+
}
20+
21+
/**
22+
* Provides path of file to the form then clicks Upload button
23+
* @param absolutePathOfFile The complete path of the file to upload
24+
*/
25+
public void uploadFile(String absolutePathOfFile){
26+
driver.findElement(inputField).sendKeys(absolutePathOfFile);
27+
clickUploadButton();
28+
}
29+
30+
public String getUploadedFiles(){
31+
return driver.findElement(uploadedFiles).getText();
32+
}
33+
34+
}

webdriver_java/src/main/java/pages/HomePage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public AlertsPage clickJavaScriptAlerts(){
3636
return new AlertsPage(driver);
3737
}
3838

39+
public FileUploadPage clickFileUpload(){
40+
clickLink("File Upload");
41+
return new FileUploadPage(driver);
42+
}
43+
3944
private void clickLink(String linkText){
4045
driver.findElement(By.linkText(linkText)).click();
4146
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package alerts;
2+
3+
import base.BaseTests;
4+
import org.testng.annotations.Test;
5+
6+
import static org.testng.Assert.assertEquals;
7+
8+
public class FileUploadTests extends BaseTests {
9+
10+
@Test
11+
public void testFileUpload(){
12+
var uploadPage = homePage.clickFileUpload();
13+
uploadPage.uploadFile("/Users/angie/workspace/testautomationu/webdriver_java/resources/chromedriver");
14+
assertEquals(uploadPage.getUploadedFiles(), "chromedriver", "Uploaded files incorrect");
15+
}
16+
}

0 commit comments

Comments
 (0)