From bb4eb7f04984047237fba2f268be6b2b0970405f Mon Sep 17 00:00:00 2001 From: Oleh Babenko Date: Tue, 6 Feb 2024 22:23:38 +0200 Subject: [PATCH] Reworking the framework from .js to .ts --- cypress.config.js => cypress.config.ts | 12 ++--- cypress/e2e/logIn.cy.js | 27 ----------- cypress/e2e/logIn.cy.ts | 27 +++++++++++ cypress/e2e/navigation.cy.js | 32 ------------- cypress/e2e/navigation.cy.ts | 32 +++++++++++++ cypress/e2e/products.cy.js | 16 ------- cypress/e2e/products.cy.ts | 16 +++++++ cypress/src/base/BasePage.js | 12 ----- cypress/src/base/BasePage.ts | 12 +++++ cypress/src/components/AlreadyRegistered.js | 37 -------------- cypress/src/components/AlreadyRegistered.ts | 41 ++++++++++++++++ cypress/src/components/Footer.js | 27 ----------- cypress/src/components/Footer.ts | 25 ++++++++++ .../src/components/{Header.js => Header.ts} | 20 ++++---- cypress/src/components/ProductList.js | 34 ------------- cypress/src/components/ProductList.ts | 33 +++++++++++++ cypress/src/modals/QuickView.js | 46 ------------------ cypress/src/modals/QuickView.ts | 48 +++++++++++++++++++ cypress/src/pages/{Account.js => Account.ts} | 10 ++-- cypress/src/pages/ContactUs.js | 7 --- cypress/src/pages/ContactUs.ts | 7 +++ cypress/src/pages/{Home.js => Home.ts} | 21 ++++---- cypress/src/pages/SignIn.js | 10 ---- cypress/src/pages/SignIn.ts | 10 ++++ cypress/support/commands.js | 22 --------- cypress/support/commands.ts | 19 ++++++++ cypress/support/{e2e.js => e2e.ts} | 0 package.json | 6 ++- tsconfig.json | 16 +++++++ 29 files changed, 323 insertions(+), 302 deletions(-) rename cypress.config.js => cypress.config.ts (62%) delete mode 100644 cypress/e2e/logIn.cy.js create mode 100644 cypress/e2e/logIn.cy.ts delete mode 100644 cypress/e2e/navigation.cy.js create mode 100644 cypress/e2e/navigation.cy.ts delete mode 100644 cypress/e2e/products.cy.js create mode 100644 cypress/e2e/products.cy.ts delete mode 100644 cypress/src/base/BasePage.js create mode 100644 cypress/src/base/BasePage.ts delete mode 100644 cypress/src/components/AlreadyRegistered.js create mode 100644 cypress/src/components/AlreadyRegistered.ts delete mode 100644 cypress/src/components/Footer.js create mode 100644 cypress/src/components/Footer.ts rename cypress/src/components/{Header.js => Header.ts} (55%) delete mode 100644 cypress/src/components/ProductList.js create mode 100644 cypress/src/components/ProductList.ts delete mode 100644 cypress/src/modals/QuickView.js create mode 100644 cypress/src/modals/QuickView.ts rename cypress/src/pages/{Account.js => Account.ts} (60%) delete mode 100644 cypress/src/pages/ContactUs.js create mode 100644 cypress/src/pages/ContactUs.ts rename cypress/src/pages/{Home.js => Home.ts} (50%) delete mode 100644 cypress/src/pages/SignIn.js create mode 100644 cypress/src/pages/SignIn.ts delete mode 100644 cypress/support/commands.js create mode 100644 cypress/support/commands.ts rename cypress/support/{e2e.js => e2e.ts} (100%) create mode 100644 tsconfig.json diff --git a/cypress.config.js b/cypress.config.ts similarity index 62% rename from cypress.config.js rename to cypress.config.ts index 28b639f..12b3653 100644 --- a/cypress.config.js +++ b/cypress.config.ts @@ -15,12 +15,12 @@ module.exports = defineConfig({ viewportHeight: 1080, video: false, baseUrl: 'http://www.automationpractice.pl/', - loginAPIUrl: 'http://www.automationpractice.pl/index.php?controller=authentication', - account: { - userEmail: 'automationpractice@ukr.net', - password: 'simple_automation_com_2021', - userName: 'John Wick' - }, + env:{ + userEmail: 'automationpractice@ukr.net', + password: 'simple_automation_com_2021', + userName: 'John Wick', + loginAPIUrl: 'http://www.automationpractice.pl/index.php?controller=authentication', + } }, }); diff --git a/cypress/e2e/logIn.cy.js b/cypress/e2e/logIn.cy.js deleted file mode 100644 index e963f11..0000000 --- a/cypress/e2e/logIn.cy.js +++ /dev/null @@ -1,27 +0,0 @@ -import Home from '../src/pages/Home'; - -const homePage = new Home(); - -describe('User Login tests', () => { - it('Sign in page (Valid data)', () => { - homePage - .visit() - .checkPageUrl() - .header.clickOnSignInButton() - .alreadyRegisteredComponent - .enterUserEmail(Cypress.config('account')['userEmail']) - .enterPassword(Cypress.config('account')['password']) - .clickOnLoginButton() - .checkPageUrl() - .checkTextIsPresent('Welcome to your account. Here you can manage all of your personal information and orders.') - .header.checkUserNameIsPresent(Cypress.config('account')['userName']); - }); - - it('Log In via API (Valid data)', () => { - cy.logInApi(Cypress.config('account')['userEmail'],Cypress.config('account')['password']); - homePage - .visit() - .checkPageUrl() - .header.checkUserNameIsPresent(Cypress.config('account')['userName']); - }); -}); \ No newline at end of file diff --git a/cypress/e2e/logIn.cy.ts b/cypress/e2e/logIn.cy.ts new file mode 100644 index 0000000..338d8d8 --- /dev/null +++ b/cypress/e2e/logIn.cy.ts @@ -0,0 +1,27 @@ +import Home from '../src/pages/Home'; + +const homePage = new Home(); + +describe('User Login tests', () => { + it('Sign in page (Valid data)', () => { + homePage + .visit() + .checkPageUrl() + .header.clickOnSignInButton() + .alreadyRegisteredComponent + .enterUserEmail(Cypress.env('userEmail')) + .enterPassword(Cypress.env('password')) + .clickOnLoginButton() + .checkPageUrl() + .checkTextIsPresent('Welcome to your account. Here you can manage all of your personal information and orders.') + .header.checkUserNameIsPresent(Cypress.env('userName')); + }); + + it('Log In via API (Valid data)', () => { + cy.logInApi(Cypress.env('userEmail'), Cypress.env('password')) + homePage + .visit() + .checkPageUrl() + .header.checkUserNameIsPresent(Cypress.env('userName')); + }); +}); \ No newline at end of file diff --git a/cypress/e2e/navigation.cy.js b/cypress/e2e/navigation.cy.js deleted file mode 100644 index 56b5887..0000000 --- a/cypress/e2e/navigation.cy.js +++ /dev/null @@ -1,32 +0,0 @@ -import Home from '../src/pages/Home'; - -const homePage = new Home(); - -describe('Navigation tests', () => { - it('Navigate to the Home page, and verify url', () => { - homePage.visit().checkPageUrl(); - }); - - it('Navigate to the Contact Us page via header, and verify url', () => { - homePage - .visit() - .checkPageUrl() - .header.clickOnContactUsButton() - .checkPageUrl(); - }); - - it('Navigate to the Sign In page via header, and verify url', () => { - homePage - .visit() - .checkPageUrl() - .header.clickOnSignInButton() - .checkPageUrl(); - }); - - it('Check links on Follow us section in footer', () => { - homePage - .visit() - .checkPageUrl() - .footer.checkFollowUsSectionLinks(); - }); -}); \ No newline at end of file diff --git a/cypress/e2e/navigation.cy.ts b/cypress/e2e/navigation.cy.ts new file mode 100644 index 0000000..96cc7b6 --- /dev/null +++ b/cypress/e2e/navigation.cy.ts @@ -0,0 +1,32 @@ +import Home from '../src/pages/Home'; + +const homePage = new Home(); + +describe('Navigation tests', () => { + it('Navigate to the Home page, and verify url', () => { + homePage.visit().checkPageUrl(); + }); + + it('Navigate to the Contact Us page via header, and verify url', () => { + homePage + .visit() + .checkPageUrl() + .header.clickOnContactUsButton() + .checkPageUrl(); + }); + + it('Navigate to the Sign In page via header, and verify url', () => { + homePage + .visit() + .checkPageUrl() + .header.clickOnSignInButton() + .checkPageUrl(); + }); + + it('Check links on Follow us section in footer', () => { + homePage + .visit() + .checkPageUrl() + .footer.checkFollowUsSectionLinks(); + }); +}); \ No newline at end of file diff --git a/cypress/e2e/products.cy.js b/cypress/e2e/products.cy.js deleted file mode 100644 index 38e1640..0000000 --- a/cypress/e2e/products.cy.js +++ /dev/null @@ -1,16 +0,0 @@ -import Home from '../src/pages/Home'; - -const homePage = new Home(); - -describe('Check product on site', () => { - it('Check item discount', () => { - homePage - .visit() - .checkPageUrl() - .productList - .clickOnBestSellersBtn() - .openQuickViewModalForFirstProductWithPriceDiscount() - .waitForLoad() - .checkSumWithDiscountCalculatedCorrectly(); - }); -}); \ No newline at end of file diff --git a/cypress/e2e/products.cy.ts b/cypress/e2e/products.cy.ts new file mode 100644 index 0000000..1305874 --- /dev/null +++ b/cypress/e2e/products.cy.ts @@ -0,0 +1,16 @@ +import Home from '../src/pages/Home'; + +const homePage = new Home(); + +describe('Check product on site', () => { + it('Check item discount', () => { + homePage + .visit() + .checkPageUrl() + .productList + .clickOnBestSellersBtn() + .openQuickViewModalForFirstProductWithPriceDiscount() + .waitForLoad() + .checkSumWithDiscountCalculatedCorrectly(); + }); +}); \ No newline at end of file diff --git a/cypress/src/base/BasePage.js b/cypress/src/base/BasePage.js deleted file mode 100644 index 4d844e0..0000000 --- a/cypress/src/base/BasePage.js +++ /dev/null @@ -1,12 +0,0 @@ -export default class BasePage { - url; - - constructor(url) { - this.url = url; - } - - checkPageUrl() { - cy.url().should('eq', `${Cypress.config('baseUrl')}${this.url}`); - return this; - } -} \ No newline at end of file diff --git a/cypress/src/base/BasePage.ts b/cypress/src/base/BasePage.ts new file mode 100644 index 0000000..862ef6a --- /dev/null +++ b/cypress/src/base/BasePage.ts @@ -0,0 +1,12 @@ +export default class BasePage { + private url: string; + + constructor(url: string) { + this.url = url; + } + + public checkPageUrl(): this { + cy.url().should('eq', `${Cypress.config('baseUrl')}${this.url}`); + return this; + } +} diff --git a/cypress/src/components/AlreadyRegistered.js b/cypress/src/components/AlreadyRegistered.js deleted file mode 100644 index f2065ec..0000000 --- a/cypress/src/components/AlreadyRegistered.js +++ /dev/null @@ -1,37 +0,0 @@ -import Account from '../pages/Account'; - -export default class AlreadyRegistered { - alreadyRegisteredContainerLocator = '#login_form'; - loginFieldLocator = '#email'; - passwordFieldLocator = '#passwd'; - loginButtonLocator = '#SubmitLogin'; - - get inputEmailField() { - return cy - .get(this.alreadyRegisteredContainerLocator) - .find(this.loginFieldLocator); - } - get inputPasswordField() { - return cy - .get(this.alreadyRegisteredContainerLocator) - .find(this.passwordFieldLocator); - } - get loginButton() { - return cy - .get(this.alreadyRegisteredContainerLocator) - .find(this.loginButtonLocator); - } - - enterUserEmail(userEmail) { - this.inputEmailField.type(userEmail); - return this; - } - enterPassword(password) { - this.inputPasswordField.type(password); - return this; - } - clickOnLoginButton() { - this.loginButton.click(); - return new Account(); - } -} \ No newline at end of file diff --git a/cypress/src/components/AlreadyRegistered.ts b/cypress/src/components/AlreadyRegistered.ts new file mode 100644 index 0000000..4149cd6 --- /dev/null +++ b/cypress/src/components/AlreadyRegistered.ts @@ -0,0 +1,41 @@ +import Account from '../pages/Account'; + +export default class AlreadyRegistered { + private alreadyRegisteredContainerLocator: string = '#login_form'; + private loginFieldLocator: string = '#email'; + private passwordFieldLocator: string = '#passwd'; + private loginButtonLocator: string = '#SubmitLogin'; + + private get inputEmailField(): Cypress.Chainable { + return cy + .get(this.alreadyRegisteredContainerLocator) + .find(this.loginFieldLocator); + } + + private get inputPasswordField(): Cypress.Chainable { + return cy + .get(this.alreadyRegisteredContainerLocator) + .find(this.passwordFieldLocator); + } + + private get loginButton(): Cypress.Chainable { + return cy + .get(this.alreadyRegisteredContainerLocator) + .find(this.loginButtonLocator); + } + + public enterUserEmail(userEmail: any): this { + this.inputEmailField.type(userEmail); + return this; + } + + public enterPassword(password: string): this { + this.inputPasswordField.type(password); + return this; + } + + public clickOnLoginButton(): Account { + this.loginButton.click(); + return new Account(); + } +} \ No newline at end of file diff --git a/cypress/src/components/Footer.js b/cypress/src/components/Footer.js deleted file mode 100644 index c725346..0000000 --- a/cypress/src/components/Footer.js +++ /dev/null @@ -1,27 +0,0 @@ -export default class Footer { - footerContainerLocator = '#footer'; - - get followUsSectionLinksList() { - return cy.get(this.footerContainerLocator) - .find('#social_block a'); - } - - checkFollowUsSectionLinks() { - this.followUsSectionLinksList.each((element) => { - cy.request({ - method: 'GET', - url: element.attr('href'), - failOnStatusCode: false - }).then((response) => { - if (response.status === 200) { - expect(response.status).eq(200); - } else if (response.status === 404) { - expect(response.status).eq(404); - } - else { - console.log(`${element.attr('href')}${response.status}`); - } - }); - }); - } -} \ No newline at end of file diff --git a/cypress/src/components/Footer.ts b/cypress/src/components/Footer.ts new file mode 100644 index 0000000..8b01325 --- /dev/null +++ b/cypress/src/components/Footer.ts @@ -0,0 +1,25 @@ +export default class Footer { + private footerContainerLocator: string = '#footer'; + + private get followUsSectionLinksList(): Cypress.Chainable { + return cy.get(this.footerContainerLocator).find('#social_block a'); + } + + public checkFollowUsSectionLinks(): void { + this.followUsSectionLinksList.each((element) => { + cy.request({ + method: 'GET', + url: element.attr('href'), + failOnStatusCode: false, + }).then((response) => { + if (response.status === 200) { + expect(response.status).eq(200); + } else if (response.status === 404) { + expect(response.status).eq(404); + } else { + console.log(`${element.attr('href')}${response.status}`); + } + }); + }); + } +} \ No newline at end of file diff --git a/cypress/src/components/Header.js b/cypress/src/components/Header.ts similarity index 55% rename from cypress/src/components/Header.js rename to cypress/src/components/Header.ts index c2c1c37..e738b43 100644 --- a/cypress/src/components/Header.js +++ b/cypress/src/components/Header.ts @@ -2,28 +2,32 @@ import ContactUs from '../pages/ContactUs'; import SignIn from '../pages/SignIn'; export default class Header { - headerContainerLocator = '#header'; - nameAccountLocator = '.account'; + private headerContainerLocator: string = '#header'; + private nameAccountLocator: string = '.account'; - get contactUsButton() { + private get contactUsButton(): Cypress.Chainable { return cy.get(this.headerContainerLocator).contains('a', 'Contact us'); } - get signInButton() { + + private get signInButton(): Cypress.Chainable { return cy.get(this.headerContainerLocator).contains('a', 'Sign in'); } - get nameAccount() { + + private get nameAccount(): Cypress.Chainable { return cy.get(this.nameAccountLocator); } - clickOnContactUsButton() { + public clickOnContactUsButton(): ContactUs { this.contactUsButton.click(); return new ContactUs(); } - clickOnSignInButton() { + + public clickOnSignInButton(): SignIn { this.signInButton.click(); return new SignIn(); } - checkUserNameIsPresent(userName) { + + public checkUserNameIsPresent(userName: string): this { this.nameAccount.contains(userName); return this; } diff --git a/cypress/src/components/ProductList.js b/cypress/src/components/ProductList.js deleted file mode 100644 index af4db57..0000000 --- a/cypress/src/components/ProductList.js +++ /dev/null @@ -1,34 +0,0 @@ -import QuickView from '../modals/QuickView'; - -export default class ProductList { - homeTabsContainerLocator = '#home-page-tabs'; - bestSellersBtnLocator = '.blockbestsellers'; - productsContainerLocator = '.tab-content'; - productContainerLocator = '.product-container'; - productDiscountLocator = '#blockbestsellers .right-block .price-percent-reduction'; - quickViewButtonLocator = '.quick-view'; - - get bestSellersButton() { - return cy.get(this.bestSellersBtnLocator).contains('a', 'Best Sellers'); - } - - get firstProductWithPriceDiscount() { - return cy.get(this.productsContainerLocator) - .find(this.productDiscountLocator).eq(0) - .parents(this.productContainerLocator); - } - - get firstProductWithPriceDiscountQuickModalButton() { - return this.firstProductWithPriceDiscount.find(this.quickViewButtonLocator); - } - - clickOnBestSellersBtn() { - this.bestSellersButton.click(); - return this; - } - - openQuickViewModalForFirstProductWithPriceDiscount() { - this.firstProductWithPriceDiscountQuickModalButton.click({ force: true }); - return new QuickView(); - } -} \ No newline at end of file diff --git a/cypress/src/components/ProductList.ts b/cypress/src/components/ProductList.ts new file mode 100644 index 0000000..e5fc979 --- /dev/null +++ b/cypress/src/components/ProductList.ts @@ -0,0 +1,33 @@ +import QuickView from '../modals/QuickView'; + +export default class ProductList { + private bestSellersBtnLocator: string = '.blockbestsellers'; + private productsContainerLocator: string = '.tab-content'; + private productContainerLocator: string = '.product-container'; + private productDiscountLocator: string = '#blockbestsellers .right-block .price-percent-reduction'; + private quickViewButtonLocator: string = '.quick-view'; + + private get bestSellersButton(): Cypress.Chainable { + return cy.get(this.bestSellersBtnLocator).contains('a', 'Best Sellers'); + } + + private get firstProductWithPriceDiscount(): Cypress.Chainable { + return cy.get(this.productsContainerLocator) + .find(this.productDiscountLocator).eq(0) + .parents(this.productContainerLocator); + } + + private get firstProductWithPriceDiscountQuickModalButton(): Cypress.Chainable { + return this.firstProductWithPriceDiscount.find(this.quickViewButtonLocator); + } + + public clickOnBestSellersBtn(): this { + this.bestSellersButton.click(); + return this; + } + + public openQuickViewModalForFirstProductWithPriceDiscount(): QuickView { + this.firstProductWithPriceDiscountQuickModalButton.click({ force: true }); + return new QuickView(); + } +} \ No newline at end of file diff --git a/cypress/src/modals/QuickView.js b/cypress/src/modals/QuickView.js deleted file mode 100644 index 42847f6..0000000 --- a/cypress/src/modals/QuickView.js +++ /dev/null @@ -1,46 +0,0 @@ -export default class QuickView { - priceWithoutDiscountLocator = '#old_price_display'; - priceWithDiscountLocator = ' #our_price_display'; - discountPercentageLocator = ' #reduction_percent_display'; - loadingSpinnerLocator = '#fancybox-loading'; - - get loadingSpinner() { - return cy.get(this.loadingSpinnerLocator, {timeout: 20000}); - } - - waitForLoad() { - this.loadingSpinner.should('not.exist'); - return this; - } - - get modalWindow() { - return cy.iframe('[class="fancybox-overlay fancybox-overlay-fixed"] iframe'); - } - - get priceWithoutDiscount() { - return this.modalWindow.find(this.priceWithoutDiscountLocator).invoke('text'); - } - - get priceWithDiscount() { - return this.modalWindow.find(this.priceWithDiscountLocator).invoke('text'); - } - - get discountPercentage() { - return this.modalWindow.find(this.discountPercentageLocator).invoke('text'); - } - - checkSumWithDiscountCalculatedCorrectly() { - this.priceWithoutDiscount.then(priceWithoutDiscount => { - this.priceWithDiscount.then(priceWithDiscount => { - this.discountPercentage.then(discountPercentage => { - const priceWithoutDiscountFormatted = Number(priceWithoutDiscount.replace(/[^\d.]/g, '')); - const priceWithDiscountFormatted = Number(priceWithDiscount.replace(/[^\d.]/g, '')); - const discountPercentageFormatted = Number(discountPercentage.replace(/[^\d.]/g, '')); - const calculatedSumWithDiscount = Math.floor(priceWithoutDiscountFormatted - (priceWithoutDiscountFormatted / 100 * discountPercentageFormatted)); - expect(priceWithDiscountFormatted).eq(calculatedSumWithDiscount); - }); - }); - }); - return this; - } -} \ No newline at end of file diff --git a/cypress/src/modals/QuickView.ts b/cypress/src/modals/QuickView.ts new file mode 100644 index 0000000..5139385 --- /dev/null +++ b/cypress/src/modals/QuickView.ts @@ -0,0 +1,48 @@ +export default class QuickView { + private priceWithoutDiscountLocator: string = '#old_price_display'; + private priceWithDiscountLocator: string = ' #our_price_display'; + private discountPercentageLocator: string = ' #reduction_percent_display'; + private loadingSpinnerLocator: string = '#fancybox-loading'; + + private get loadingSpinner(): Cypress.Chainable { + return cy.get(this.loadingSpinnerLocator, { timeout: 20000 }); + } + + + private get modalWindow(): Cypress.Chainable { + return cy.iframe('[class="fancybox-overlay fancybox-overlay-fixed"] iframe'); + } + + private get priceWithoutDiscount(): Cypress.Chainable { + return this.modalWindow.find(this.priceWithoutDiscountLocator).invoke('text'); + } + + private get priceWithDiscount(): Cypress.Chainable { + return this.modalWindow.find(this.priceWithDiscountLocator).invoke('text'); + } + + private get discountPercentage(): Cypress.Chainable { + return this.modalWindow.find(this.discountPercentageLocator).invoke('text'); + } + public waitForLoad(): this { + this.loadingSpinner.should('not.exist'); + return this; + } + + public checkSumWithDiscountCalculatedCorrectly(): this { + this.priceWithoutDiscount.then((priceWithoutDiscount) => { + this.priceWithDiscount.then((priceWithDiscount) => { + this.discountPercentage.then((discountPercentage) => { + const priceWithoutDiscountFormatted = Number(priceWithoutDiscount.replace(/[^\d.]/g, '')); + const priceWithDiscountFormatted = Number(priceWithDiscount.replace(/[^\d.]/g, '')); + const discountPercentageFormatted = Number(discountPercentage.replace(/[^\d.]/g, '')); + const calculatedSumWithDiscount = Math.floor( + priceWithoutDiscountFormatted - (priceWithoutDiscountFormatted / 100) * discountPercentageFormatted + ); + expect(priceWithDiscountFormatted).eq(calculatedSumWithDiscount); + }); + }); + }); + return this; + } +} \ No newline at end of file diff --git a/cypress/src/pages/Account.js b/cypress/src/pages/Account.ts similarity index 60% rename from cypress/src/pages/Account.js rename to cypress/src/pages/Account.ts index da61152..9d02dbd 100644 --- a/cypress/src/pages/Account.js +++ b/cypress/src/pages/Account.ts @@ -2,19 +2,19 @@ import Header from '../components/Header'; import BasePage from '../base/BasePage'; export default class Account extends BasePage { - header = new Header(); - accountInfoContainerLocator = '#center_column'; + header: Header = new Header(); + private accountInfoContainerLocator: string = '#center_column'; constructor() { super('index.php?controller=my-account'); } - get accountInfo() { + private get accountInfo(): Cypress.Chainable { return cy.get(this.accountInfoContainerLocator); } - checkTextIsPresent(expectedText) { + public checkTextIsPresent(expectedText: string): this { this.accountInfo.contains(expectedText); return this; } -} +} \ No newline at end of file diff --git a/cypress/src/pages/ContactUs.js b/cypress/src/pages/ContactUs.js deleted file mode 100644 index 3427fe9..0000000 --- a/cypress/src/pages/ContactUs.js +++ /dev/null @@ -1,7 +0,0 @@ -import BasePage from '../base/BasePage'; - -export default class ContactUs extends BasePage{ - constructor() { - super('index.php?controller=contact'); - } -} \ No newline at end of file diff --git a/cypress/src/pages/ContactUs.ts b/cypress/src/pages/ContactUs.ts new file mode 100644 index 0000000..b0abe49 --- /dev/null +++ b/cypress/src/pages/ContactUs.ts @@ -0,0 +1,7 @@ +import BasePage from '../base/BasePage'; + +export default class ContactUs extends BasePage { + constructor() { + super('index.php?controller=contact'); + } +} \ No newline at end of file diff --git a/cypress/src/pages/Home.js b/cypress/src/pages/Home.ts similarity index 50% rename from cypress/src/pages/Home.js rename to cypress/src/pages/Home.ts index 0171f54..2aea780 100644 --- a/cypress/src/pages/Home.js +++ b/cypress/src/pages/Home.ts @@ -4,17 +4,16 @@ import Footer from '../components/Footer'; import ProductList from '../components/ProductList'; export default class Home extends BasePage { - header = new Header(); - footer = new Footer(); - productList = new ProductList(); + header: Header = new Header(); + footer: Footer = new Footer(); + productList: ProductList = new ProductList(); + constructor() { + super('index.php'); + } - constructor() { - super('index.php'); - } - - visit() { - cy.visit('/'); - return this; - } + public visit(): this { + cy.visit('/'); + return this; + } } \ No newline at end of file diff --git a/cypress/src/pages/SignIn.js b/cypress/src/pages/SignIn.js deleted file mode 100644 index 7a4cfa3..0000000 --- a/cypress/src/pages/SignIn.js +++ /dev/null @@ -1,10 +0,0 @@ -import BasePage from '../base/BasePage'; -import AlreadyRegistered from '../components/AlreadyRegistered'; - -export default class SignIn extends BasePage { - alreadyRegisteredComponent = new AlreadyRegistered(); - - constructor() { - super('index.php?controller=authentication&back=my-account'); - } -} \ No newline at end of file diff --git a/cypress/src/pages/SignIn.ts b/cypress/src/pages/SignIn.ts new file mode 100644 index 0000000..93dbc6a --- /dev/null +++ b/cypress/src/pages/SignIn.ts @@ -0,0 +1,10 @@ +import BasePage from '../base/BasePage'; +import AlreadyRegistered from '../components/AlreadyRegistered'; + +export default class SignIn extends BasePage { + alreadyRegisteredComponent: AlreadyRegistered = new AlreadyRegistered(); + + constructor() { + super('index.php?controller=authentication&back=my-account'); + } +} \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js deleted file mode 100644 index 514bfd3..0000000 --- a/cypress/support/commands.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * user login using the request api. - * @memberOf cy - * @method logInApi - * @param {string} email - The user email. - * @param {string} password - The user password. - * @returns set cookies - * @example cy.logInApi('userName', 'userPassword); - */ -Cypress.Commands.add('logInApi', (email, password) => { - cy.request({ - method: 'POST', - url: Cypress.config('loginAPIUrl'), - form: true, - body: { - email: email, - passwd: password, - back: 'my-account', - SubmitLogin: '' - } - }); -}); \ No newline at end of file diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts new file mode 100644 index 0000000..e3cc453 --- /dev/null +++ b/cypress/support/commands.ts @@ -0,0 +1,19 @@ +declare namespace Cypress { + interface Chainable { + logInApi(email: string, password: string): void; + } +} + +Cypress.Commands.add('logInApi', (email: string, password: string) => { + cy.request({ + method: 'POST', + url: Cypress.env('loginAPIUrl'), + form: true, + body: { + email: email, + passwd: password, + back: 'my-account', + SubmitLogin: '' + } + }); +}); \ No newline at end of file diff --git a/cypress/support/e2e.js b/cypress/support/e2e.ts similarity index 100% rename from cypress/support/e2e.js rename to cypress/support/e2e.ts diff --git a/package.json b/package.json index 7460302..d031920 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,12 @@ }, "homepage": "https://github.com/VadimNastoyashchy/cypressautomationpracticecom#readme", "devDependencies": { - "cypress": "10.2.0", + "@types/node": "^20.11.16", + "cypress": "^10.2.0", "cypress-iframe": "1.0.1", "eslint": "^8.56.0", "eslint-plugin-cypress": "^2.12.1", - "mochawesome": "7.1.3" + "mochawesome": "7.1.3", + "typescript": "^5.3.3" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..969a160 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "es5", + "dom" + ], + "types": [ + "cypress", + "node" + ] + }, + "include": [ + "**/*.ts" + ] +} \ No newline at end of file