Friday, September 29, 2017

Basic behavior of protractor with functions outside of the it block

I tried to source one function out in protractor so that it is outside of the it-block. Before the “outsourcing” it worked fine.

That’s my Code:

it('should delete a private linked clone', function () {
            let countPrivateLinkedClonesBefore;
            let countPrivateLinkedClonesAfter;
            vmPortal.navigationbar.navPersonalClients.click();

            countPrivateLinkedClonesBefore = countPrivateLinkedClones();

            console.log(Count of private linked Clones before elimination: ', countPrivateLinkedClonesBefore);

            vmPortal.personalClients.firstLinkedCloneRow.element(by.css('button.btn-danger')).click();
            vmPortal.modalCreateMachine.btnModalDeleteMachine.click();

            countPrivateLinkedClonesAfter = countPrivateLinkedClones();
            console.log('Count of private linked Clones after elimination: ', countPrivateLinkedClonesBefore);
            expect(countPrivateLinkedClonesAfter === countPrivateLinkedClonesBefore - 1);
 });

so my function is countPrivateLinkedClones()

    countPrivateLinkedClones =  function () {
                let countPLC;

                vmPortal.personalClients.linkedCloneList.count().then(function (count) {
                    console.log("Count of private linked Clones:", count)
                    countPLC = count;
                });
                return countPLC;
}

If I run this the result is:

.Count of private linked Clones before elimination: undefined

Count of private linked Clones after elimination: undefined

Count of private linked Clones: 3

Count of private linked Clones: 2

What is the reason for this behavior?

How to fix it, so that the function is not executed at the end instead of where i want to have it executed?

Thanks in advance!

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/09/29/basic-behavior-of-protractor-with-functions-outside-of-the-it-block/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment