File tree 3 files changed +55
-0
lines changed
3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ public AlertsPage clickJavaScriptAlerts(){
36
36
return new AlertsPage (driver );
37
37
}
38
38
39
+ public FileUploadPage clickFileUpload (){
40
+ clickLink ("File Upload" );
41
+ return new FileUploadPage (driver );
42
+ }
43
+
39
44
private void clickLink (String linkText ){
40
45
driver .findElement (By .linkText (linkText )).click ();
41
46
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments