Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor luma account tests #111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 77 additions & 49 deletions cypress/integration/luma/user/account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,50 @@ import {isMobile} from "../../../support/utils";
describe('Account test creation', () => {
it('Can create an account', () => {
cy.visit(account.routes.accountCreate)
Account.createNewCustomer(account.customer.customer.firstname, account.customer.customer.lastname, Date.now() + account.customer.customer.email, account.customer.password)
Account.createNewCustomer(
account.customer.customer.firstname,
account.customer.customer.lastname,
Date.now() + account.customer.customer.email, account.customer.password
)
cy.contains('Thank you for registering with Main Website Store.').should('exist')
cy.wait(2000)
Account.logout()
})
})

describe('Account login/logout', () => {
before(() => {
Magento2RestApi.createCustomerAccount(account.customer)
Account.login(account.customer.customer.email, account.customer.password)
})

// TODO: Create login test without using Account.login ( clicking the "Sign In" in the Header and then doing login.)

it('Can log out', () => {
cy.get('.base').should('contain.text', 'My Account')
cy.get(selectorsLuma.accountIcon).click({force: true})
cy.get(selectorsLuma.accountMenuItems).contains('Sign Out').click({force: true})
cy.get(selectorsLuma.signedOutHeader).should('contain.text', 'You are signed out')
cy.wait(2000)
})
})

describe('Account activities', () => {
beforeEach(() => {
Account.login(account.customer.customer.email, account.customer.password)
cy.wait(2500)
})

before(() => {
cy.wait(2500)
Magento2RestApi.createCustomerAccount(account.customer)
Account.login(account.customer.customer.email, account.customer.password)
Account.createAddress(account.customerInfo)
// We need to logout or the beforeEach will fail

if(isMobile()) {
cy.wait(2000)
}
cy.wait(2500)
})

after(() => {
// Remove the added address
cy.wait(4000)
Account.login(account.customer.customer.email, account.customer.password)
cy.visit('/customer/address')
cy.wait(4000)
cy.get('.additional-addresses a.delete').eq(0).click({force: true})
cy.wait(1000)
cy.get('.modal-content').contains('Are you sure you want to delete this address?')
cy.get('.action-primary').click()
cy.wait(2500)
})

it('Can check your profile', () => {
cy.visit(account.routes.accountEdit)
Account.checkAllProfileSpecs()
Expand All @@ -62,9 +69,11 @@ describe('Account activities', () => {
Account.login(account.customer.customer.email, account.tempCustomerInfo.password)
cy.visit(account.routes.accountEdit)
// Change password back to normal
cy.get('#change-password').check({force: true})
Account.changePassword(account.tempCustomerInfo.password, account.customer.password)
cy.contains('You saved the account information.').should('exist')
Magento2RestApi.replacePassword(
account.customer.customer.email,
account.tempCustomerInfo.password,
account.customer.password
)
})

it('Can change the profile values', () => {
Expand Down Expand Up @@ -103,23 +112,67 @@ describe('Account activities', () => {
})
})

it('Can add an address', () => {
cy.visit(account.routes.accountAddAddress)
Account.createAddress(account.customerInfo)
it('Can change the newsletter subscription', () => {
Account.login(account.customer.customer.email, account.customer.password)
cy.visit(account.routes.manageNewsletter)
cy.contains('General Subscription')
cy.get('#subscription').should('be.checked')
})

it('Can add a product the a wishlist', () => {
cy.visit(product.simpleProductUrl)
cy.wait(2000)
cy.get(selectorsLuma.addToWishlistButton).eq(0).click({force: true})
cy.get(selectorsLuma.wishlistTitle).should('contain.text', 'My Wish List').should('exist')
cy.visit(account.routes.wishlist).then(() => {
cy.get('.toolbar-number').should('exist')
cy.contains(product.simpleProductName).should('exist')
})
})


})

describe('Account Address Activities', () => {
beforeEach(() => {
Account.login(account.customer.customer.email, account.customer.password)
cy.wait(1500)
})

before(() => {
Magento2RestApi.createCustomerAccount(account.customer)
if(isMobile()) {
cy.wait(2000)
}
cy.wait(2500)
})

after(() => {
cy.wait(4000)
Account.login(account.customer.customer.email, account.customer.password)
Account.deleteAddress()
})

it('Can add an address', () => {
cy.contains(selectorsLuma.addNewAddressButton, 'Add New Address').click()
cy.get(selectorsLuma.newAddressStreetInput).type(account.customerInfo.streetAddress)
cy.get(selectorsLuma.newAddressCityInput).type(account.customerInfo.city)
cy.get(selectorsLuma.newAddressTelInput).type(account.customerInfo.phone)
cy.get(selectorsLuma.newAddressZipcodeInput).type(account.customerInfo.zip)
cy.get(selectorsLuma.newAddressCountryInput).select(account.customerInfo.country)
cy.contains('Save Address').click()

cy.get('.messages')
.should('contain.text', 'You saved the address')
})

it('Can change an address', () => {
const timeStamp = Date.now().toString()
// TODO: Don't go directly to Addresses page, go to /customer/account/index and click on "Manage Addresses"

cy.visit(account.routes.accountAddresses)
cy.get(selectorsLuma.editAddress).first().click()

const timeStamp = Date.now().toString()
cy.get(selectorsLuma.addressEditStreetInput).eq(0).type(timeStamp)
cy.get(selectorsLuma.saveAddressButton).contains('Save Address').click()
cy.contains('You saved the address.').should('exist')
Expand Down Expand Up @@ -150,31 +203,6 @@ describe('Account activities', () => {
cy.get('.action-primary').click()
cy.contains('You deleted the address.').should('exist')
})

it('Can change the newsletter subscription', () => {
Account.login(account.customer.customer.email, account.customer.password)
cy.visit(account.routes.manageNewsletter)
cy.contains('General Subscription')
cy.get('#subscription').should('be.checked')
})

it('Can add a product the a wishlist', () => {
cy.visit(product.simpleProductUrl)
cy.wait(2000)
cy.get(selectorsLuma.addToWishlistButton).eq(0).click({force: true})
cy.get(selectorsLuma.wishlistTitle).should('contain.text', 'My Wish List').should('exist')
cy.visit(account.routes.wishlist).then(() => {
cy.get('.toolbar-number').should('exist')
cy.contains(product.simpleProductName).should('exist')
})
})

it('Can log out', () => {
cy.get(selectorsLuma.accountIcon).click({force: true})
cy.get(selectorsLuma.accountMenuItems).contains('Sign Out').click({force: true})
cy.get(selectorsLuma.signedOutHeader).should('contain.text', 'You are signed out')
cy.wait(2000)
})
})

describe('Guest user test', () => {
Expand Down
28 changes: 27 additions & 1 deletion cypress/page-objects/luma/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class Account {
static isLoggedIn() {
cy.contains(selectors.myAccountHeaderSelector, 'My Account')
}

static logout() {
cy.visit(account.routes.accountIndex);
cy.get('.base').then(($text) => {
Expand Down Expand Up @@ -85,6 +85,32 @@ export class Account {
})
}

static deleteAddress() {
cy.visit(account.routes.accountAddresses)
cy.wait(2000)

cy.get('.block-addresses-list').then($block => {
cy.log($block.find('.empty').length)
if ($block.find('.empty').length === 1) {
cy.log('No more addresses to remove');
} else {
// TODO: Replace this with REST API call at some point?
cy.get('.additional-addresses a.delete').then(($links) => {
if ($links.length > 0) {
cy.wrap($links.first()).click({force: true});
cy.wait(2000)
cy.get('.modal-content').then(($modal) => {
if ($modal.text().indexOf('Are you sure you want to delete this address?') >= 0) {
cy.get('.action-primary').click()
}
this.deleteAddress(); // calling as long as we have addresses to remove!
})
}
})
}
})
}

static addItemToWishlist(itemUrl = '') {
cy.visit(itemUrl)
cy.get('button[aria-label="Add to Wish List"]').click()
Expand Down
24 changes: 24 additions & 0 deletions cypress/support/magento2-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ export class Magento2RestApi {
});
}

static replacePassword(username, oldPassword, newPassword) {
cy.request({
method: 'POST',
url: '/rest/all/V1/integration/customer/token',
body: {
"username": username,
"password": oldPassword
},
}).then((response) => {
let token = response.body
cy.request({
method: 'PUT',
url: '/rest/default/V1/customers/me/password',
headers: {
Authorization: "Bearer " + token
},
body: {
"currentPassword": oldPassword,
"newPassword": newPassword
}
})
})
}

static logCustomerIn(customer) {
cy.request({
method: 'POST',
Expand Down