2

I have this function:

this.checkButton = function (buttonName, element, expectedPresent, expectedEnabled) {
    var enabledCheck = expectedEnabled ? "enabled" : "disabled";
    it('Find a ' + buttonName + ' button and check it is ' + enabledCheck, function () {
        expect(element.isPresent()).toBe(expectedPresent);
        expect(element.isEnabled()).toBe(expectedEnabled);
    });
}

Is there a way I can make this so that if the function is called without the last two parameters then those parameters will both default to true?

0

2 Answers 2

2

Compare the parameters to undefined to know if they are present:

    this.checkButton = function (buttonName, element, expectedPresent, expectedEnabled) {

        if(expectedPresent === undefined) {
            expectedPresent = true;
        }
        if(expectedEnabled === undefined) {
            expectedEnabled = true;
        }
        var enabledCheck = expectedEnabled ? "enabled" : "disabled";
        it('Find a ' + buttonName + ' button and check it is ' + enabledCheck, function () {
            expect(element.isPresent()).toBe(expectedPresent);
            expect(element.isEnabled()).toBe(expectedEnabled);
        });
    }
Sign up to request clarification or add additional context in comments.

Comments

0

If I understood what you want.

Try to say in starting of function.

expectedPresent = (expectedPresent==undefined) ? true : expectedPresent;
expectedEnabled = (expectedEnabled==undefined) ? true : expectedEnabled;

I hope this helps.

8 Comments

That doesn't work. At all.
This way it's not possible to pass expectedPresent as false.
use === instead of ==.
@Barmar sorry for asking, but how does that help?
Never mind, I was wrong.
|