Skip to content

Commit 4f16360

Browse files
Merge pull request #31 from aldimhernandez/14-pom---download
refactor: 🎨 implements page object model for download suite case
2 parents c5b2ec4 + 925d06e commit 4f16360

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
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";
25

3-
//TODO: Refactor to POM
46
When('I navigate to the "Elements" section', () => {
5-
cy.contains("Elements").click();
7+
homePage.navigateToElementsSection();
68
});
79

810
When('I click on the "Upload and Download" section', () => {
9-
cy.contains("Upload and Download").click();
10-
11+
navBarPage.navigateToUploadAndDownloadSection();
1112
});
1213

1314
When('I click on the "Download" button', () => {
14-
cy.get("#downloadButton").click();
15+
uploadAndDownloadPage.pageRedirectValidation();
16+
uploadAndDownloadPage.clickDownloadButton();
1517
});
1618

1719
Then('The file should be downloaded successfully', () => {
18-
cy.readFile("cypress/downloads/sampleFile.jpeg").should("exist");
20+
uploadAndDownloadPage.downloadFileValidation();
1921
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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();

cypress/pages/0A.home/HomePage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class HomePage extends BasePage implements IPage {
2525
this.clickElementByText(HomePage.BOOK_STORE_TEXT, this.cardSectionSelector);
2626
}
2727

28+
navigateToElementsSection() {
29+
this.clickElementByText(HomePage.ELEMENTS_TEXT, this.cardSectionSelector);
30+
}
31+
32+
static readonly ELEMENTS_TEXT: string = 'Elements';
2833
static readonly FORM_CARD_TEXT: string = 'Forms';
2934
static readonly ALERTS_FRAMES_WINDOWS_CARD_TEXT: string = 'Alerts, Frame & Windows';
3035
static readonly BOOK_STORE_TEXT: string = 'Book Store Application';

cypress/pages/0B.navbar/NavBarPage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ class NavBarPage extends BasePage {
1515
this.clickElementByText(NavBarPage.LOGIN_TEXT, this.elementListSelector);
1616
}
1717

18+
navigateToUploadAndDownloadSection() {
19+
this.clickElementByText(NavBarPage.UPLOAD_AND_DOWNLOAD_TEXT, this.elementListSelector);
20+
}
21+
1822
static readonly PRACTICE_FORM_TEXT: string = 'Practice Form';
1923
static readonly FRAME_TEXT: string = 'Frames';
2024
static readonly LOGIN_TEXT: string = 'Login';
25+
static readonly UPLOAD_AND_DOWNLOAD_TEXT: string = 'Upload and Download';
2126
}
2227

2328
export const navBarPage = new NavBarPage();

0 commit comments

Comments
 (0)