Skip to content

Commit

Permalink
Merge pull request #43 from webvisum/cypress-tests-24
Browse files Browse the repository at this point in the history
Cypress tests 24
  • Loading branch information
peterjaap authored Mar 22, 2022
2 parents 6ebc1b9 + 201de3a commit ed17fac
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 9 deletions.
5 changes: 5 additions & 0 deletions cypress/fixtures/hyva/cms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"wrongPageUrl": "/abc",
"cmsTitles": ["Customer Login", "Orders and Returns", "Contact Us"],
"errorPageTitle": "Whoops, our bad..."
}
4 changes: 3 additions & 1 deletion cypress/fixtures/hyva/selectors/cart.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"messageToast": "div.message",
"productPrice": ".price"
},
"productRowInCart": "div.table-row-item",
"productNameInCart": "a[x-html='item.product.name']",
"product1Price": ":nth-child(3) > .sm\\:order-2 > .flex > :nth-child(2) > .block",
"product1Subtotal": ":nth-child(3) > .md\\:justify-end > .sm\\:items-center > .flex > .block > span",
"product2Subtotal": ":nth-child(4) > .md\\:justify-end > .sm\\:items-center > .flex > .block > span",
Expand All @@ -23,4 +25,4 @@
"product1Url": "/didi-sport-watch.html",
"product2Url": "/affirm-water-bottle.html"
}
}
}
7 changes: 7 additions & 0 deletions cypress/fixtures/hyva/selectors/cms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"infocenter": ".bg-white > .wrapper > .order-3",
"cmsListItem": "nav > ul > li",
"cmsItemLink": "li > a",
"pageTitle": "h1.page-title",
"cmsDefaultPages": [":nth-child(1) > ul.mt-4 > :nth-child(2) > .text-base", "ul.mt-4 > :nth-child(3) > .text-base", "ul.mt-4 > :nth-child(4) > .text-base"]
}
1 change: 1 addition & 0 deletions cypress/fixtures/hyva/selectors/homepage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"headerNavCategory": "div.lg\\:block > nav > div:nth-child(2) > span > a[title=\"Women\"]",
"headerNavSubCategory": "div.lg\\:block > nav > div:nth-child(2) > div > a:nth-child(1)",
"mainHeading": "h1.title-font",
"addToCartButton": "button.btn-primary:visible",
"newsletterSubscribeButton": "#newsletter-validate-detail button",
"productCard": "#maincontent div > div div.card.card-interactive",
"subscribeToNewsletterField": "#newsletter-subscribe",
Expand Down
3 changes: 3 additions & 0 deletions cypress/fixtures/hyva/selectors/minicart.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
"addToCartButton": "#product-addtocart-button",
"firstProductAmount": ":nth-child(2) > .w-3\\/4 > :nth-child(1) > .text-xl > [x-html=\"item.qty\"]",
"miniCartButton": "#menu-cart-icon > .w-8",
"miniCartSlider": ".fixed > .w-screen > .flex-col",
"miniCartCheckoutButton": ":nth-child(3) > :nth-child(2) > .inline-flex",
"miniCartEditProductButton": ".pt-4 > .mr-2",
"miniCartFirstProductPrice": ":nth-child(2) > .w-3\\/4 > :nth-child(3) > [x-html=\"item.product_price\"]",
"miniCartProductName": "[x-html=\"item.product_name\"]",
"miniCartSecondProductPrice": ":nth-child(3) > .w-3\\/4 > :nth-child(3) > [x-html=\"item.product_price\"]",
"miniCartSubtotal": "[x-html=\"cart.subtotal\"] > .price",
"miniCartViewCartLink": ".underline",
"productQty": "[x-html='item.qty']",
"PDPProductName": ".order-2 > .text-xl",
"productPrice": ".final-price",
"removeProductButton": ".pt-4 > button.inline-flex > .w-5",
"qtyInputField": "input[name='qty']",
"secondProductAmount": ":nth-child(3) > .w-3\\/4 > :nth-child(1) > .text-xl > [x-html=\"item.qty\"]",
"pageTitle": ".base"
}
7 changes: 6 additions & 1 deletion cypress/integration/hyva/cart/cart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ describe("Cart tests", () => {
});

it("merges an already existing cart when a customer logs in", () => {
//test goes here
cy.get(cart.productNameInCart).invoke('text').then(productName => {
Account.login(account.customerLogin.username, account.customerLogin.password);
cy.visit(cart.url.cartUrl);
cy.get(cart.productNameInCart).should('have.text', productName)
})
Account.logout();
});
});
17 changes: 17 additions & 0 deletions cypress/integration/hyva/cart/minicart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ describe('Mini cart tests', () => {
cy.get(selectors.miniCartCheckoutButton).click()
cy.get(selectors.pageTitle).should('contains.text', 'Checkout').should('be.visible')
})

it('can open minicart slider', () => {
cy.get(selectors.miniCartSlider).should('be.visible')
})

it('can change amount in the minicart', () => {
cy.get(selectors.miniCartSlider).within(() => {
cy.get(selectors.miniCartEditProductButton).click()
})
cy.get(selectors.qtyInputField)
.type("{backspace}2{enter}")
.should("have.value", "2");
cy.get(selectors.addToCartButton).click()
cy.get(selectors.miniCartButton).click()
cy.get(selectors.productQty)
.should('have.text', '2')
})
})

describe('Test without added product',() => {
Expand Down
16 changes: 16 additions & 0 deletions cypress/integration/hyva/cms/cms-pages.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import selectors from "../../../../fixtures/hyva/selectors/cms.json";
import cms from "../../../../fixtures/hyva/cms.json";

describe('CMS tests', () => {
it('Can display the default 404 page', () => {
cy.visit(cms.wrongPageUrl, {failOnStatusCode: false});
cy.get(selectors.pageTitle).should('contain.text', cms.errorPageTitle)
})

it('Can open default CMS pages', () => {
cy.get(selectors.cmsDefaultPages).each((cmsPage, i) => {
cy.get(cmsPage).click()
cy.get(selectors.pageTitle).should('contain.text', cms.cmsTitles[i])
})
})
})
21 changes: 14 additions & 7 deletions cypress/integration/hyva/homepage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import selectors from '../../fixtures/hyva/selectors/homepage.json';
import searchSelectors from '../../fixtures/hyva/selectors/search.json';
import product from '../../fixtures/hyva/product.json';
import account from '../../fixtures/account.json';
import cart from "../../../fixtures/hyva/selectors/cart.json";

describe('Home page tests', () => {
beforeEach(() => {
Expand All @@ -11,17 +12,17 @@ describe('Home page tests', () => {

it('Can visit the homepage and it contains products', () => {
cy.get(selectors.mainHeading).should(
'contain.text',
homepage.titleText
'contain.text',
homepage.titleText
);
cy.get(selectors.productCard).should('have.length.gte', 4);
});

it('Can perform search from homepage', () => {
cy.get(searchSelectors.headerSearchIcon).click();
cy.get(searchSelectors.headerSearchField)
.should('be.visible')
.type(`${product.simpleProductName}{enter}`);
.should('be.visible')
.type(`${product.simpleProductName}{enter}`);
cy.get(selectors.mainHeading).should(
'contain.text',
product.simpleProductName
Expand All @@ -30,10 +31,10 @@ describe('Home page tests', () => {

it('Can open category', () => {
// Force because hover is not (yet?) possible in cypress
cy.get(selectors.headerNavSubCategory).click({ force: true });
cy.get(selectors.headerNavSubCategory).click();
cy.get(selectors.mainHeading).should(
'contain.text',
homepage.subCategoryName
'contain.text',
homepage.subCategoryName
);
});

Expand All @@ -57,4 +58,10 @@ describe('Home page tests', () => {
}
});
});
it('Can add product to the cart when add to cart button is visible', () => {
cy.get(selectors.addToCartButton).first().click();
cy.get(cart.product.messageToast)
.should("include.text", "to your shopping cart")
.should("be.visible");
});
});

0 comments on commit ed17fac

Please sign in to comment.