Skip to content

Commit

Permalink
Merge pull request #15312 from nesrineabdmouleh/sanity_tests_orders_BO
Browse files Browse the repository at this point in the history
Order BO tests with puppeteer - Sanity tests campaign
  • Loading branch information
matthieu-rolland committed Sep 4, 2019
2 parents 0f95061 + 3106071 commit 930c3aa
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/puppeteer/campaigns/sanity/ordersBO/01_filterOrders.js
@@ -0,0 +1,65 @@
// 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 OrderPage = require('../../../pages/BO/order');

let page;
let loginPage;
let dashboardPage;
let boBasePage;
let orderPage;
// 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));
orderPage = await (new OrderPage(page));
};

/*
Connect to the BO
Filter the Orders table
Logout from the BO
*/
global.scenario('Filter the Orders table by ID, REFERENCE, STATUS', 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 to the Orders page', async () => {
await boBasePage.goToSubMenu(boBasePage.ordersParentLink, orderPage.ordersLink);
const pageTitle = await orderPage.getPageTitle();
await expect(pageTitle).to.contains(orderPage.pageTitle);
});

test('should filter the Orders table by ID and check the result', async () => {
await orderPage.filterTableByInput(orderPage.orderFilterIdInput, '1', orderPage.searchButton);
await boBasePage.checkTextValue(orderPage.orderfirstLineIdTD, '1');
await orderPage.waitForSelectorAndClick(orderPage.resetButton)
});

test('should filter the Orders table by REFERENCE and check the result', async () => {
await orderPage.filterTableByInput(orderPage.orderFilterReferenceInput, 'FFATNOMMJ', orderPage.searchButton);
await boBasePage.checkTextValue(orderPage.orderfirstLineReferenceTD, 'FFATNOMMJ');
await orderPage.waitForSelectorAndClick(orderPage.resetButton)
});

test('should filter the Orders table by STATUS and check the result', async () => {
await orderPage.filterTableBySelect(orderPage.orderFilterStatusSelect, '8');
await orderPage.checkTextValue(orderPage.orderfirstLineStatusTD, 'Payment error');
});

test('should logout from the BO', async () => {
await boBasePage.logoutBO();
const pageTitle = await loginPage.getPageTitle();
await expect(pageTitle).to.contains(loginPage.pageTitle);
});
}, init, true);
62 changes: 62 additions & 0 deletions tests/puppeteer/campaigns/sanity/ordersBO/02_editOrder.js
@@ -0,0 +1,62 @@
// 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 OrderPage = require('../../../pages/BO/order');

let page;
let loginPage;
let dashboardPage;
let boBasePage;
let orderPage;
// 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));
orderPage = await (new OrderPage(page));
};

/*
Connect to the BO
Edit the first order
Logout from the BO
*/
global.scenario('Edit Order BO', 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 to the Orders page', async () => {
await boBasePage.goToSubMenu(boBasePage.ordersParentLink, orderPage.ordersLink);
const pageTitle = await orderPage.getPageTitle();
await expect(pageTitle).to.contains(orderPage.pageTitle);
});

test('should go to the first order page', async () => {
await boBasePage.waitForSelectorAndClick(orderPage.orderfirstLineIdTD);
const pageTitle = await orderPage.getPageTitle();
await expect(pageTitle).to.contains(orderPage.orderPageTitle);
});

test('should modify the product quantity and check the validation', async () => {
await orderPage.modifyProductQuantity('1', '5');
});

test('should modify the order status and check the validation', async () => {
await orderPage.modifyOrderStatus('Payment accepted');
});

test('should logout from the BO', async () => {
await boBasePage.logoutBO();
const pageTitle = await loginPage.getPageTitle();
await expect(pageTitle).to.contains(loginPage.pageTitle);
});
}, init, true);
73 changes: 73 additions & 0 deletions tests/puppeteer/pages/BO/order.js
Expand Up @@ -5,9 +5,82 @@ module.exports = class Order extends BOBasePage {
super(page);

this.pageTitle = 'Orders •';
this.orderPageTitle = 'Order';

// Orders page
this.orderFilterIdInput = '#table-order th:nth-child(2) > input';
this.orderFilterReferenceInput = '#table-order th:nth-child(3) > input';
this.orderFilterStatusSelect = '#table-order th:nth-child(9) > select';
this.searchButton = '#submitFilterButtonorder';
this.resetButton = '#table-order button.btn.btn-warning';
this.orderfirstLineIdTD = '#table-order td:nth-child(2)';
this.orderfirstLineReferenceTD = '#table-order td:nth-child(3)';
this.orderfirstLineStatusTD = '#table-order td:nth-child(9)';

//Order page
this.editProductButton = '#orderProducts tr:nth-child(%ID) .edit_product_change_link';
this.editProductQuantityInput = '#orderProducts tr:nth-child(%ID) span.product_quantity_edit > input';
this.productQuantitySpan = '#orderProducts tr:nth-child(%ID) span.product_quantity_show.badge';
this.UpdateProductButton = '#orderProducts tr:nth-child(%ID) .submitProductChange';
this.orderStatusesSelect = '#id_order_state_chosen';
this.orderStatusInput = '#id_order_state_chosen input[type="text"]';
this.orderStatusSearchResult = '#id_order_state_chosen li:nth-child(1)';
this.updateStatusButton = '#submit_state';
this.statusValidation = '#status tr:nth-child(1) > td:nth-child(2)'
}

/*
Methods
*/

/**
* Filter table with an input
* @param selector, input to filter with
* @param value, text to enter in the filter input
* @param searchButton
* @returns {Promise<void>}
*/
async filterTableByInput(selector, value, searchButton) {
await this.page.waitForSelector(selector);
await this.page.type(selector, value);
await this.page.click(searchButton)
}

/**
* Filter table with a select option
* @param selector
* @param value, value to select in the filter select
* @returns {Promise<void>}
*/
async filterTableBySelect(selector, value) {
await this.page.waitForSelector(selector);
await this.page.select(selector, value);
}

/**
* Modify the product quantity
* @param id, product id
* @param quantity, new quantity
* @returns {Promise<void>}
*/
async modifyProductQuantity(id, quantity) {
await this.dialogListener();
await this.waitForSelectorAndClick(this.editProductButton.replace('%ID', id));
await this.setValue(this.editProductQuantityInput.replace('%ID', id), quantity);
await this.waitForSelectorAndClick(this.UpdateProductButton.replace('%ID', id));
await this.checkTextValue(this.productQuantitySpan.replace('%ID', id), quantity);
}

/**
* Modify the order status
* @param status
* @returns {Promise<void>}
*/
async modifyOrderStatus(status) {
await this.waitForSelectorAndClick(this.orderStatusesSelect);
await this.page.type(this.orderStatusInput, status);
await this.page.click(this.orderStatusSearchResult);
await this.page.click(this.updateStatusButton);
await this.checkTextValue(this.statusValidation, status)
}
};
26 changes: 26 additions & 0 deletions tests/puppeteer/pages/commonPage.js
Expand Up @@ -116,4 +116,30 @@ module.exports = class CommonPage {
async reloadPage() {
await this.page.reload({waitUntil: 'networkidle0'});
}

/**
* Delete the existing text from input then set a value
* @param selector, input
* @param value, value to set in the input
* @return {Promise<void>}
*/
async setValue(selector, value) {
await this.waitForSelectorAndClick(selector);
await this.page.click(selector, {clickCount: 3});
await this.page.type(selector, value);
}

/**
* To accept or dismiss a navigator dialog
* @param accept
* @return {Promise<void>}
*/
async dialogListener(accept = true) {
this.page.once("dialog", (dialog) => {
if (accept)
dialog.accept();
else
dialog.dismiss();
});
}
};

0 comments on commit 930c3aa

Please sign in to comment.