File tree Expand file tree Collapse file tree 4 files changed +53
-6
lines changed Expand file tree Collapse file tree 4 files changed +53
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { Then , When } from "@badeball/cypress-cucumber-preprocessor" ;
2
+ import { uploadAndDownloadPage } from "cypress/pages/04.download/UploadAndDownloadPage" ;
3
+ import { homePage } from "cypress/pages/0A.home/HomePage" ;
4
+ import { navBarPage } from "cypress/pages/0B.navbar/NavBarPage" ;
2
5
3
- //TODO: Refactor to POM
4
6
When ( 'I navigate to the "Elements" section' , ( ) => {
5
- cy . contains ( "Elements" ) . click ( ) ;
7
+ homePage . navigateToElementsSection ( ) ;
6
8
} ) ;
7
9
8
10
When ( 'I click on the "Upload and Download" section' , ( ) => {
9
- cy . contains ( "Upload and Download" ) . click ( ) ;
10
-
11
+ navBarPage . navigateToUploadAndDownloadSection ( ) ;
11
12
} ) ;
12
13
13
14
When ( 'I click on the "Download" button' , ( ) => {
14
- cy . get ( "#downloadButton" ) . click ( ) ;
15
+ uploadAndDownloadPage . pageRedirectValidation ( ) ;
16
+ uploadAndDownloadPage . clickDownloadButton ( ) ;
15
17
} ) ;
16
18
17
19
Then ( 'The file should be downloaded successfully' , ( ) => {
18
- cy . readFile ( "cypress/downloads/sampleFile.jpeg" ) . should ( "exist" ) ;
20
+ uploadAndDownloadPage . downloadFileValidation ( ) ;
19
21
} ) ;
Original file line number Diff line number Diff line change
1
+ import BasePage from "../BasePage" ;
2
+ import { IPage } from "../IPage" ;
3
+
4
+ class UploadAndDownloadPage extends BasePage implements IPage {
5
+ readonly title : string = 'DEMOQA' ;
6
+ readonly url : string = `${ Cypress . config ( ) . baseUrl } /upload-download` ;
7
+ readonly h1 : string = 'Upload and Download' ;
8
+
9
+ private readonly downloadButtonSelector = '#downloadButton' ;
10
+ private readonly uploadButtonSelector = '#uploadFile' ;
11
+ private readonly uploadFilePath = 'cypress/downloads/sampleFile.jpeg' ;
12
+
13
+ pageRedirectValidation ( ) {
14
+ this . validateTitle ( this . title ) ;
15
+ this . validateUrl ( this . url ) ;
16
+ this . validateH1 ( this . h1 ) ;
17
+ }
18
+
19
+ clickDownloadButton ( ) {
20
+ this . clickElementByText ( UploadAndDownloadPage . DOWNLOAD_BUTTON_TEXT , this . downloadButtonSelector ) ;
21
+ }
22
+
23
+ clickUploadButton ( ) {
24
+ this . clickElementByText ( UploadAndDownloadPage . UPLOAD_BUTTON_TEXT , this . uploadButtonSelector ) ;
25
+ }
26
+
27
+ downloadFileValidation ( ) {
28
+ cy . readFile ( this . uploadFilePath ) . should ( "exist" ) ;
29
+ }
30
+
31
+ static readonly DOWNLOAD_BUTTON_TEXT : string = 'Download' ;
32
+ static readonly UPLOAD_BUTTON_TEXT : string = 'Upload' ;
33
+ }
34
+
35
+ export const uploadAndDownloadPage = new UploadAndDownloadPage ( ) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ class HomePage extends BasePage implements IPage {
25
25
this . clickElementByText ( HomePage . BOOK_STORE_TEXT , this . cardSectionSelector ) ;
26
26
}
27
27
28
+ navigateToElementsSection ( ) {
29
+ this . clickElementByText ( HomePage . ELEMENTS_TEXT , this . cardSectionSelector ) ;
30
+ }
31
+
32
+ static readonly ELEMENTS_TEXT : string = 'Elements' ;
28
33
static readonly FORM_CARD_TEXT : string = 'Forms' ;
29
34
static readonly ALERTS_FRAMES_WINDOWS_CARD_TEXT : string = 'Alerts, Frame & Windows' ;
30
35
static readonly BOOK_STORE_TEXT : string = 'Book Store Application' ;
Original file line number Diff line number Diff line change @@ -15,9 +15,14 @@ class NavBarPage extends BasePage {
15
15
this . clickElementByText ( NavBarPage . LOGIN_TEXT , this . elementListSelector ) ;
16
16
}
17
17
18
+ navigateToUploadAndDownloadSection ( ) {
19
+ this . clickElementByText ( NavBarPage . UPLOAD_AND_DOWNLOAD_TEXT , this . elementListSelector ) ;
20
+ }
21
+
18
22
static readonly PRACTICE_FORM_TEXT : string = 'Practice Form' ;
19
23
static readonly FRAME_TEXT : string = 'Frames' ;
20
24
static readonly LOGIN_TEXT : string = 'Login' ;
25
+ static readonly UPLOAD_AND_DOWNLOAD_TEXT : string = 'Upload and Download' ;
21
26
}
22
27
23
28
export const navBarPage = new NavBarPage ( ) ;
You can’t perform that action at this time.
0 commit comments