I am currently working on a solution using protractor where I have several options to consider. Specifically, I need to test timeslots between 1600 and 1900, along with an else statement.
For instance, if the 1600 timeslot is selected, then the code should work accordingly for that element and so forth.
When executing the code, it follows this syntax:
npm run e2e.js --params.tiemslot.t1600
Alternatively, it can also be t1900 or no parameters at all.
The test cases are structured as follows:
const utils = require("../utils/utils");
const ServicesPage = require("../objects/servicesPage.obj");
describe("Services page", function () {
servicesPage = new ServicesPage();
if (browser.params.timeslot.t1600) {
it("Should have truck and select the 1600 timeslot delivery",
async function () {
const nextStep = servicesPage.getForm().buttons.nextStep;
await servicesPage.truckLateDelivery();
await utils.elementToBeClickable(nextStep);
await utils.click(nextStep);
})
}
else if (browser.params.timeslot.t1900) {
it("Should have truck and select the 1900 delivery",
async function () {
const nextStep = servicesPage.getForm().buttons.nextStep;
await servicesPage.truckLateDelivery();
await utils.elementToBeClickable(nextStep);
await utils.click(nextStep);
})
}
else {
it("Should have truck and choose the latest delivery",
async function () {
const nextStep = servicesPage.getForm().buttons.nextStep;
await servicesPage.chooseLatestDelivery();
await utils.elementToBeClickable(nextStep);
await utils.click(nextStep);
})
}
});
My object script looks like this:
const utils = require("../utils/utils");
const servicesPage = require("../specs/servicesPage.specs");
module.exports = class DetailsPage {
constructor() {
const _buttons = {
nextStep: servicesPage.nextStepButton,
lateDelivery: servicesPage.lateDeliveryCheckbox,
truck: servicesPage.truckButton,
timeSlotAll: servicesPage.timeslotAll,
timeSlot1600: servicesPage.timeSlot1600,
timeSlot1900: servicesPage.timeSlot1900,
};
this.getFormButtons = function () {
return _buttons;
};
}
getForm() {
return {
buttons: this.getFormButtons()
};
}
async truckLateDelivery() {
const truckButton = this.getForm().buttons.truck;
const lateDelivery = this.getForm().buttons.lateDelivery;
const timeslot = this.getForm().buttons.timeSlot1600;
//Choose Truck
await utils.elementToBeClickable(truckButton);
await utils.click(truckButton);
//Click Late Delivery
await utils.elementToBeClickable(timeslot);
await utils.click(timeslot);
//Click late hour checkbox
await utils.elementToBeClickable(lateDelivery);
await utils.click(lateDelivery);
}
async chooseLatestDelivery() {
const truckButton = this.getForm().buttons.truck;
const lateDelivery = this.getForm().buttons.lateDelivery;
const timeSlots = this.getForm().buttons.timeSlotAll;
//Choose Truck
await utils.elementToBeClickable(truckButton);
await utils.click(truckButton);
//Check if timeslots are available
await utils.presenceOf(timeSlots);
const countElement = await timeSlots.count();
console.log(`Found ${countElement} timeslots buttons`);
//Choose last timeslot
await utils.elementToBeClickable(timeSlots.last());
await utils.click(timeSlots.last());
//Click on checkbox
await utils.elementToBeClickable(lateDelivery);
await utils.click(lateDelivery);
}
};
I am facing a challenge in determining how to make the async truckLateDelivery()
function aware of whether it should run t1600 or t1900 based on the command,
npm run e2e.js --params.tiemslot.t1600
or npm run e2e.js --params.tiemslot.t1900
. How can I achieve this given the setup with the function _buttons
containing the necessary elements and the truckLateDelivery()
function handling the tests?
Any suggestions on how to instruct the test case to correctly choose between t1600 and t1900 based on the commands provided would be greatly appreciated.