mercredi 8 avril 2020

How to select correct value depending on params?

So I am trying to solve a solution with protractor where I have few options. I want to be able to test timeslots which are between 1600, 1900 and a else statement.

If we select 1600 then we obviously do the 1600 element and etc etc.

When I start my code it goes doing the code:

npm run e2e.js --params.tiemslot.t1600

it can also be t1900 or no params at all.

The test cases are following:

const utils = require("../utils/utils");
const ServicesPage = require("../objects/servicesPage.obj");

describe("Services page", function () {
    servicesPage = new ServicesPage();

    if (browser.params.timeslot.t1600) {
        it("Has truck and choose 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("Has truck and choose 1900 delivery",
            async function () {
                const nextStep = servicesPage.getForm().buttons.nextStep;

                await servicesPage.truckLateDelivery();

                await utils.elementToBeClickable(nextStep);
                await utils.click(nextStep);
            })
    }
    else {
        it("Has truck and choose latest delivery",
            async function () {
                const nextStep = servicesPage.getForm().buttons.nextStep;

                await servicesPage.chooseLatestDelivery();

                await utils.elementToBeClickable(nextStep);
                await utils.click(nextStep);
            })
    }
});

and my object script is

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 avaliable
        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);
    }
};

and my problem is that I need by somehow give the value async truckLateDelivery() { to know to run t1600 or t1900 basically and I am not sure how I can do that? Because as you can see I have the function _buttons which has the correct elements and I have the function truckLateDelivery() that handles the tests.

So my question is how can I let the test case know if I want to run npm run e2e.js --params.tiemslot.t1600 to run the t1600 and if I write npm run e2e.js --params.tiemslot.t1900 to run t1900 and to choose the correct element?

Aucun commentaire:

Enregistrer un commentaire