Skip to content

Commit

Permalink
Cypress End to End Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanzade-hasan authored and gadimbaylisahil committed Sep 20, 2023
1 parent 05d72cf commit e600030
Show file tree
Hide file tree
Showing 20 changed files with 8,536 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/tests/Cypress/node_modules/
/tests/Cypress/cypress/screenshots
/tests/Cypress/cypress/videos
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "better-payment/bp-plugin-shopware6-api2",
"description": "Better Payment plugin to implement payment methods using API2",
"version": "2.1.0",
"type": "shopware-platform-plugin",
"type": "shopware-platform-plugin",
"license": "proprietary",
"authors": [
{
Expand Down
7 changes: 7 additions & 0 deletions tests/Cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
experimentalStudio: true,
},
});
13 changes: 13 additions & 0 deletions tests/Cypress/cypress/commands/administration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Cypress.Commands.add('loginAsAdmin', () => {
cy.visit('admin#/login');
cy.get('#sw-field--username').type('admin');
cy.get('#sw-field--password').type('shopware');
cy.get('.sw-button').click();

cy.url().should('include', 'dashboard');
});

Cypress.Commands.add('goToSettings', () => {
cy.get('[data-testid="sw-icon__regular-cog"]').click({force: true});
cy.contains('Settings');
});
52 changes: 52 additions & 0 deletions tests/Cypress/cypress/commands/storefront.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Cypress.Commands.add('register', (data) => {
cy.url().should('include', 'checkout/register')

if (data.asCommercial) {
cy.get('#accountType').select('Commercial');
}

cy.get('#personalSalutation').select('Mr.');
cy.get('#personalFirstName').type('Cypress');
cy.get('#personalLastName').type('Test');
if (data.withBirthday) {
cy.get('#personalBirthday').select('1');
cy.get(':nth-child(5) > :nth-child(2) > .custom-select').select('1');
cy.get(':nth-child(3) > .custom-select').select('2000');
}

if (data.withGender) {
cy.get('#better_payment_customer_gender').select('m');
}

// cy.get('.register-personal > .custom-control > .custom-control-label').click();
// cy.get('#personalGuest').check();
cy.get('#personalMail').type('[email protected]');
cy.get('#billingAddressAddressStreet').type('Main street');
cy.get('#billingAddressAddressZipcode').type('1234567');
cy.get('#billingAddressAddressCity').type('White city');
cy.get('#billingAddressAddressCountry').select('Germany');
cy.get('#billingAddressAddressCountryState').select('Hamburg');
cy.get('#billingAddressAddressPhoneNumber').type('1234567');
cy.get('.register-submit > .btn').click();
});

Cypress.Commands.add('buyProduct', () => {
// TODO: improve url and path access, consider below lines
// cy.visit('/');
// cy.get('.main-navigation-link-text > span').first().click();

cy.visit('Clothing/');
cy.contains('Add to shopping cart').first().click();
cy.contains('Go to checkout').click();
})

Cypress.Commands.add('selectPaymentMethod', (name) => {
cy.url().should('include', 'checkout/confirm');

// show more button in case payment method name is not shown
if (cy.get('.confirm-checkout-collapse-trigger-label')) {
cy.get('.confirm-checkout-collapse-trigger-label').click();
}

cy.contains(name).click();
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('Custom fields are installed', () => {
it('successfully installed customer gender custom field', () => {
cy.loginAsAdmin().goToSettings();

// Go to Custom Fields
cy.get('.sw-settings__tab-system').click();
cy.get('[data-testid="sw-icon__regular-bars-square"]').click();

// Check custom field is defined correctly
cy.contains('Better Payment Customer').click();
cy.contains('Gender').click();
cy.get('#sw-field--currentCustomField-name').should('have.value', 'better_payment_customer_gender');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe('Payment Methods are installed', () => {
it('successfully installed Payment Methods', () => {
cy.loginAsAdmin().goToSettings();

// Go to Payment Methods
cy.get('[data-testid="sw-icon__regular-credit-card"]').click();

const paymentMethods = [
'Invoice',
'Invoice B2B',
'SEPA Direct Debit',
'SEPA Direct Debit B2B',
'Credit Card',
'PayPal',
'Paydirekt',
'Sofort'
];

paymentMethods.forEach(paymentMethod => {
cy.contains(paymentMethod + ' | Better Payment');
// TODO: find a way to check if they are active (active toggle turned on)
});
});
});
41 changes: 41 additions & 0 deletions tests/Cypress/cypress/e2e/administration/installers/rule.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
describe('Rules are installed', () => {
it('successfully installed private customer rule', () => {
cy.loginAsAdmin().goToSettings();

// Go to Rule Builder
cy.get('[data-testid="sw-icon__regular-rule"]').click();

// Search for Private Customer Role
cy.get('.sw-search-bar__input').type('Private Customer');
cy.contains('Private Customer').click({force: true});

// Check rule defined correctly
cy.get('.sw-single-select__selection-text').first().contains('Commercial customer');
cy.get('.sw-single-select__selection-text').last().contains('No');

// Check rule assigned to Payment Methods correctly
cy.get('.sw-settings-rule-detail__tab-item-assignments').click();
cy.get('.sw-settings-rule-detail-assignments__card-payment_method').scrollIntoView().contains('Invoice');
cy.get('.sw-settings-rule-detail-assignments__card-payment_method').scrollIntoView().contains('SEPA Direct Debit');
});

it('successfully installed commercial customer rule', () => {
cy.loginAsAdmin().goToSettings();

// Go to Rule Builder settings
cy.get('[data-testid="sw-icon__regular-rule"]').click();

// Search for Commercial Customer Role
cy.get('.sw-search-bar__input').type('Commercial Customer');
cy.contains('Commercial Customer').click({force: true});

// Check rule defined correctly
cy.get('.sw-single-select__selection-text').first().contains('Commercial customer');
cy.get('.sw-single-select__selection-text').last().contains('Yes');

// Check rule assigned to Payment Methods correctly
cy.get('.sw-settings-rule-detail__tab-item-assignments').click();
cy.get('.sw-settings-rule-detail-assignments__card-payment_method').scrollIntoView().contains('Invoice B2B');
cy.get('.sw-settings-rule-detail-assignments__card-payment_method').scrollIntoView().contains('SEPA Direct Debit B2B');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
describe('Log-in & sign-up flags are set', () => {
it('successfully set login & signup flags', () => {
cy.loginAsAdmin().goToSettings();

// Go to Log-in & Sign-up
cy.get('[data-testid="sw-icon__regular-sign-in"]').click();

cy.get('[name="core.loginRegistration.showPhoneNumberField"]').siblings().first().should('have.css', 'background', 'rgb(24, 158, 255)');
cy.get('[name="core.loginRegistration.showAccountTypeSelection"]').siblings().first().should('have.css', 'background', 'rgb(24, 158, 255)');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe('Credit Card test', () => {
it('valid payment', () => {
cy.buyProduct();
cy.register({
asCommercial: false,
withBirthday: false,
withGender: false,
});
cy.selectPaymentMethod('Credit Card');

cy.get('#tos').check();
cy.get('#confirmFormSubmit').click();

cy.origin('https://testapi.betterpayment.de', () => {
cy.url().should('include', 'payment');
cy.contains('Pay Now');
cy.contains('Cancel');
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('Paydirekt test', () => {
it('valid payment', () => {
cy.buyProduct();
cy.register({
asCommercial: false,
withBirthday: false,
withGender: false,
});
cy.selectPaymentMethod('Paydirekt');

cy.get('#tos').check();
cy.get('#confirmFormSubmit').click();

cy.origin('https://sandbox.paydirekt.de', () => {
cy.url().should('include', 'checkout');
cy.contains('Better Payment Germany');
})
})
})
18 changes: 18 additions & 0 deletions tests/Cypress/cypress/e2e/storefront/payment-methods/paypal.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe('PayPal test', () => {
it('valid payment', () => {
cy.buyProduct();
cy.register({
asCommercial: false,
withBirthday: false,
withGender: false,
});
cy.selectPaymentMethod('PayPal');

cy.get('#tos').check();
cy.get('#confirmFormSubmit').click();

cy.origin('https://www.sandbox.paypal.com', () => {
cy.url().should('include', 'paypal');
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
describe('Paydirekt test', () => {
it('valid private customer payment', () => {
cy.buyProduct();
cy.register({
asCommercial: false,
withBirthday: false,
withGender: false,
});

cy.selectPaymentMethod('SEPA Direct Debit');

// SEPA direct debit specific fields
cy.get('#betterpayment_iban').type('IBAN 1234567');
cy.get('#betterpayment_bic').type('BIC 1234567');
cy.get('#agreement').check();

cy.get('#tos').check();
cy.get('#confirmFormSubmit').click();

})
})
18 changes: 18 additions & 0 deletions tests/Cypress/cypress/e2e/storefront/payment-methods/sofort.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe('Sofort test', () => {
it('valid payment', () => {
cy.buyProduct();
cy.register({
asCommercial: false,
withBirthday: false,
withGender: false,
});
cy.selectPaymentMethod('Sofort');

cy.get('#tos').check();
cy.get('#confirmFormSubmit').click();

cy.origin('https://www.sofort.com', () => {
cy.url().should('include', 'sofort');
})
})
})
5 changes: 5 additions & 0 deletions tests/Cypress/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
1 change: 1 addition & 0 deletions tests/Cypress/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@shopware-ag/e2e-testsuite-platform/cypress/plugins');
21 changes: 21 additions & 0 deletions tests/Cypress/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import '../commands/administration'
import '../commands/storefront'

// Alternatively you can use CommonJS syntax:
// require('./commands')
2 changes: 2 additions & 0 deletions tests/Cypress/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Require test suite commands
require('@shopware-ag/e2e-testsuite-platform/cypress/support');
Loading

0 comments on commit e600030

Please sign in to comment.