Skip to content

Commit

Permalink
Merge pull request #15156 from boubkerbribri/upgradeTest
Browse files Browse the repository at this point in the history
Adding new Test UpgradeShop with puppeteer
  • Loading branch information
PierreRambaud committed Aug 19, 2019
2 parents 5bb0a1a + bd63ce2 commit 1a32cc7
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 0 deletions.
117 changes: 117 additions & 0 deletions tests/puppeteer/campaigns/upgrade/upgradeShop.js
@@ -0,0 +1,117 @@
// Using chai
const {expect} = require('chai');
// importing pages
const LoginPage = require('../../pages/BO/login');
const DashboardPage = require('../../pages/BO/dashboard');
const BOBasePage = require('../../pages/BO/BObasePage');
const ModuleCatalogPage = require('../../pages/BO/moduleCatalog');
const ModuleManagerPage = require('../../pages/BO/moduleManager');
const ShopParamsGeneralPage = require('../../pages/BO/shopParamsGeneral');
const ShopParamsMaintenancePage = require('../../pages/BO/shopParamsMaintenance');
const AutoUpgradePage = require('../../pages/BO/modulesPages/autoUpgrade');
const HomePage = require('../../pages/FO/home');

let page;
let loginPage;
let dashboardPage;
let bOBasePage;
let moduleCatalogPage;
let moduleManagerPage;
let shopParamsGeneralPage;
let shopParamsMaintenancePage;
let autoUpgradePage;
let homePage;


// creating pages objects in a function
const init = async () => {
page = await global.browser.newPage();
loginPage = await (new LoginPage(page));
dashboardPage = await (new DashboardPage(page));
bOBasePage = await (new BOBasePage(page));
moduleCatalogPage = await (new ModuleCatalogPage(page));
moduleManagerPage = await (new ModuleManagerPage(page));
shopParamsGeneralPage = await (new ShopParamsGeneralPage(page));
shopParamsMaintenancePage = await (new ShopParamsMaintenancePage(page));
autoUpgradePage = await (new AutoUpgradePage(page));
homePage = await (new HomePage(page));
};

// Upgrade shop from a version to the last stable one
global.scenario('Upgrade Prestashop to last Stable', async () => {
test('should login into BO', async () => {
await loginPage.goTo(global.URL_BO);
await loginPage.login(global.EMAIL, global.PASSWD);
const pageTitle = await dashboardPage.getPageTitle();
await expect(pageTitle).to.contains(dashboardPage.pageTitle);
await bOBasePage.closeOnboardingModal();
});

test('should go the Module Catalog page', async () => {
await bOBasePage.goToSubMenu(bOBasePage.modulesParentLink, bOBasePage.moduleCatalogueLink);
const pageTitle = await moduleCatalogPage.getPageTitle();
await expect(pageTitle).to.contains(moduleCatalogPage.pageTitle);
});

test('should Install module \'1-Click Upgrade\'', async () => {
await moduleCatalogPage.searchModule('autoupgrade', '1-Click Upgrade');
const installResultMessage = await moduleCatalogPage.installModule('1-Click Upgrade');
await expect(installResultMessage)
.to.equal(moduleCatalogPage.installMessageSuccessful.replace('%MODULETAG', 'autoupgrade'));
});

test('should disable Shop', async () => {
await bOBasePage.goToSubMenu(bOBasePage.shopParametersParentLink, bOBasePage.shopParametersGeneralLink);
let pageTitle = await shopParamsGeneralPage.getPageTitle();
await expect(pageTitle).to.contains(shopParamsGeneralPage.pageTitle);
await shopParamsGeneralPage.goToSubTabMaintenance();
pageTitle = await shopParamsMaintenancePage.getPageTitle();
await expect(pageTitle).to.contains(shopParamsMaintenancePage.pageTitle);
await shopParamsMaintenancePage.changeShopStatus(false);
});

test('should Go to configuration module Page', async () => {
await bOBasePage.goToSubMenu(bOBasePage.modulesParentLink, bOBasePage.moduleManagerLink);
let pageTitle = await moduleManagerPage.getPageTitle();
await expect(pageTitle).to.contains(moduleManagerPage.pageTitle);
await moduleManagerPage.searchModule('autoupgrade', '1-Click Upgrade');
await moduleManagerPage.goToConfigurationPage('1-Click Upgrade');
pageTitle = await autoUpgradePage.getPageTitle();
await expect(pageTitle).to.contains(autoUpgradePage.pageTitle);
});

test('should upgrade Prestashop', async () => {
await autoUpgradePage.upgradePrestashop('major');
});

test('should reload and check that user was automatically logged out', async () => {
await bOBasePage.reloadPage();
const pageTitle = await loginPage.getPageTitle();
await expect(pageTitle).to.contains(loginPage.pageTitle);
});

test('should login and verify version in BO', async () => {
await loginPage.goTo(global.URL_BO);
await loginPage.login(global.EMAIL, global.PASSWD);
const pageTitle = await dashboardPage.getPageTitle();
await expect(pageTitle).to.contains(dashboardPage.pageTitle);
const version = await bOBasePage.getTextContent(bOBasePage.shopVersionBloc);
expect(version).to.be.equal('1.7.6.0');
});

test('should enable Shop', async () => {
await bOBasePage.goToSubMenu(bOBasePage.shopParametersParentLink, bOBasePage.shopParametersGeneralLink);
let pageTitle = await shopParamsGeneralPage.getPageTitle();
await expect(pageTitle).to.contains(shopParamsGeneralPage.pageTitle);
await shopParamsGeneralPage.goToSubTabMaintenance();
pageTitle = await shopParamsMaintenancePage.getPageTitle();
await expect(pageTitle).to.contains(shopParamsMaintenancePage.pageTitle);
await shopParamsMaintenancePage.changeShopStatus(true);
});

test('should verify FO', async () => {
page = await bOBasePage.viewMyShop();
await page.waitForSelector(homePage.userInfoLink, {visible: true});
await page.waitForSelector(homePage.contactLink, {visible: true});
});
}, init, true);
26 changes: 26 additions & 0 deletions tests/puppeteer/pages/BO/BObasePage.js
Expand Up @@ -8,6 +8,8 @@ module.exports = class BOBasePage extends CommonPage {
this.headerLogoImage = '#header_logo';
this.userProfileIcon = '#employee_infos';
this.userProfileLogoutLink = 'a#header_logout';
this.shopVersionBloc = '#shop_version';
this.headerShopNameLink = '#header_shopname';

// left navbar
// SELL
Expand All @@ -20,9 +22,24 @@ module.exports = class BOBasePage extends CommonPage {
this.customersParentLink = 'li#subtab-AdminParentCustomer';
this.customersLink = '#subtab-AdminCustomers';

// Modules
this.modulesParentLink = '#subtab-AdminParentModulesSf';
this.moduleCatalogueLink = '#subtab-AdminParentModulesCatalog';
this.moduleManagerLink = '#subtab-AdminModulesSf';

// Shop Parameters
this.shopParametersParentLink = '#subtab-ShopParameters';
this.shopParametersGeneralLink = '#subtab-AdminParentPreferences';

// welcome module
this.onboardingCloseButton = 'button.onboarding-button-shut-down';
this.onboardingStopButton = 'a.onboarding-button-stop';

// Growls
this.growlMessageBloc = '#growls .growl-message';

// Alert Text
this.alertSuccessBloc = 'div.alert.alert-success';
}

/*
Expand Down Expand Up @@ -69,4 +86,13 @@ module.exports = class BOBasePage extends CommonPage {
await this.page.click(this.onboardingStopButton);
}
}

/**
* Click on View My Shop and wait for page to open in a new Tab
* @return FOPage, page opened
*/
async viewMyShop() {
const FOPage = await this.openLinkWithTargetBlank(this.page, this.headerShopNameLink);
return FOPage;
}
};
44 changes: 44 additions & 0 deletions tests/puppeteer/pages/BO/moduleCatalog.js
@@ -0,0 +1,44 @@
const BOBasePage = require('../../pages/BO/BObasePage');

module.exports = class moduleCatalog extends BOBasePage {
constructor(page) {
super(page);

this.pageTitle = 'Module Catalog •';
this.installMessageSuccessful = 'Install action on module %MODULETAG succeeded.';

// Selectors
this.searchModuleTagInput = '#search-input-group input.pstaggerAddTagInput';
this.searchModuleButton = '#module-search-button';
this.moduleBloc = '#modules-list-container-all div[data-name=\'%MODULENAME\']:not([style])';
this.installModuleButton = `${this.moduleBloc} form>button.module_action_menu_install`;
this.configureModuleButton = `${this.moduleBloc} div.module-actions>a`;
}

/*
Methods
*/

/**
* Search Module in Page module Catalog
* @param moduleTag, Tag of Module
* @param moduleName, Name of module
* @return {Promise<void>}
*/
async searchModule(moduleTag, moduleName) {
await this.page.type(this.searchModuleTagInput, moduleTag);
await this.page.click(this.searchModuleButton);
await this.page.waitForSelector(this.moduleBloc.replace('%MODULENAME', moduleName), {visible: true});
}

/**
* Install Module and waiting for Successful massage
* @param moduleName, Name of module
* @return {Promise<textContent>}
*/
async installModule(moduleName) {
await this.page.click(this.installModuleButton.replace('%MODULENAME', moduleName));
await this.page.waitForSelector(this.growlMessageBloc, {visible: true});
return this.getTextContent(this.growlMessageBloc);
}
};
40 changes: 40 additions & 0 deletions tests/puppeteer/pages/BO/moduleManager.js
@@ -0,0 +1,40 @@
const BOBasePage = require('../../pages/BO/BObasePage');

module.exports = class moduleManager extends BOBasePage {
constructor(page) {
super(page);

this.pageTitle = 'Module manager •';

// Selectors
this.searchModuleTagInput = '#search-input-group input.pstaggerAddTagInput';
this.searchModuleButton = '#module-search-button';
this.moduleBloc = '.module-short-list .module-item-list[data-name=\'%MODULENAME\']';
this.configureModuleButton = `${this.moduleBloc} div.module-actions>a`;
}

/*
Methods
*/

/**
* Search Module in Page module Catalog
* @param moduleTag, Tag of Module
* @param moduleName, Name of module
* @return {Promise<void>}
*/
async searchModule(moduleTag, moduleName) {
await this.page.type(this.searchModuleTagInput, moduleTag);
await this.page.click(this.searchModuleButton);
await this.page.waitForSelector(this.moduleBloc.replace('%MODULENAME', moduleName), {visible: true});
}

/**
* Click on button configure of a module
* @param moduleName, Name of module
* @return {Promise<void>}
*/
async goToConfigurationPage(moduleName) {
await this.page.click(this.configureModuleButton.replace('%MODULENAME', moduleName));
}
};
65 changes: 65 additions & 0 deletions tests/puppeteer/pages/BO/modulesPages/autoUpgrade.js
@@ -0,0 +1,65 @@
const BOBasePage = require('../../BO/BObasePage');

module.exports = class autoUpgrade extends BOBasePage {
constructor(page) {
super(page);

this.pageTitle = '1-Click Upgrade > 1-Click Upgrade •';
this.expectedStepsDoneForUpgradeTable = [
'backupFiles',
'backupDb',
'upgradeFiles',
'upgradeDb',
'upgradeModules',
'upgradeComplete',
];
this.actualStepsDoneForUpgradeTable = [];

// Selectors
this.showExpertModeButton = 'input[type=\'button\'][value=\'More options (Expert mode)\']';
this.channelSelect = '#channel';
this.updateChannelSaveButton = '#advanced input[type=\'button\'][value=\'Save\']';
this.upgradePrestashopNowButton = '#upgradeNow';
this.upgradeResultMessageBloc = '#upgradeResultCheck>p';
}

/*
Methods
*/

/**
* Select the channel from where to do the upgrade
* @param upgradeChannelValue, value to select
* @return {Promise<void>}
*/
async chooseUpgradeChannel(upgradeChannelValue) {
if (await this.elementVisible(this.showExpertModeButton)) {
await this.page.click(this.showExpertModeButton);
}
await this.page.waitForSelector(this.channelSelect, {visible: true});
await this.page.select(this.channelSelect, upgradeChannelValue);
await this.page.click(this.updateChannelSaveButton);
await this.page.waitForNavigation({waitUntil: 'networkidle0'});
}

/**
* Select the channel from where to do the upgrade,
* Upgrade Prestashop
* And check successful message and that all steps are passed
* @param upgradeChannelValue, value to select
* @return {Promise<void>}
*/
async upgradePrestashop(upgradeChannelValue) {
await this.chooseUpgradeChannel(upgradeChannelValue);
await this.page.waitForSelector(this.upgradePrestashopNowButton, {visible: true});
this.page.on('response', async (response) => {
if (await response.url().endsWith('ajax-upgradetab.php') && await response.status() === 200) {
const jsonResponse = await response.json();
await this.actualStepsDoneForUpgradeTable.push(jsonResponse.next);
}
});
await this.page.click(this.upgradePrestashopNowButton);
await this.page.waitForSelector(this.upgradeResultMessageBloc, {visible: true, timeout: 300000});
await global.expect(this.actualStepsDoneForUpgradeTable).to.include.members(this.expectedStepsDoneForUpgradeTable);
}
};
24 changes: 24 additions & 0 deletions tests/puppeteer/pages/BO/shopParamsGeneral.js
@@ -0,0 +1,24 @@
const BOBasePage = require('../../pages/BO/BObasePage');

module.exports = class shopParamsGeneral extends BOBasePage {
constructor(page) {
super(page);

this.pageTitle = 'Preferences •';

// Selectors
this.maintenanceNavItemLink = '#subtab-AdminMaintenance';
}

/*
Methods
*/

/**
* Change Tab to Maintenance in Shop Parameters General Page
* @return {Promise<void>}
*/
async goToSubTabMaintenance() {
await this.page.click(this.maintenanceNavItemLink, {waitUntil: 'networkidle2'});
}
};
39 changes: 39 additions & 0 deletions tests/puppeteer/pages/BO/shopParamsMaintenance.js
@@ -0,0 +1,39 @@
const BOBasePage = require('../../pages/BO/BObasePage');

module.exports = class shopParamsMaintenance extends BOBasePage {
constructor(page) {
super(page);

this.pageTitle = 'Maintenance •';

// Selectors
this.generalNavItemLink = '#subtab-AdminPreferences';
this.disableShopLabel = 'label[for=\'form_general_enable_shop_0\']';
this.enableShopLabel = 'label[for=\'form_general_enable_shop_1\']';
this.saveFormButton = 'form .card-footer button';
}

/*
Methods
*/

/**
* Change Tab to General in Shop Parameters Maintenance Page
* @return {Promise<void>}
*/
async goToSubTabGeneral() {
await this.page.click(this.generalNavItemLink, {waitUntil: 'networkidle2'});
}

/**
* Enable / disable shop
* @param toEnable, true to enable and false to disable
* @return {Promise<void>}
*/
async changeShopStatus(toEnable = true) {
if (toEnable) await this.page.click(this.enableShopLabel);
else await this.page.click(this.disableShopLabel);
await this.page.click(this.saveFormButton);
await this.page.waitForSelector(this.alertSuccessBloc);
}
};
2 changes: 2 additions & 0 deletions tests/puppeteer/pages/FO/home.js
Expand Up @@ -7,6 +7,8 @@ module.exports = class Home extends CommonPage {
// Selectors for home page
this.logoHomePage = '#_desktop_logo';
this.productImg = '#content article:nth-child(%NUMBER) img';
this.userInfoLink = '#_desktop_user_info';
this.contactLink = '#contact-link';
}

/**
Expand Down

0 comments on commit 1a32cc7

Please sign in to comment.