Expect: does not get the actual value

两盒软妹~` 提交于 2019-12-07 22:37:14

问题


I faced with very strange problem. I had a set of tests which I run daily on Jenkins and without any noticeable changes some asserts(expects) started fail. THe strange thing here is that they fails ONLY if I execute tests from Jenkins on Browserstack. Locally everything just fine, locally on browserstack everything is fine, on saucelabs everything is fine. I have 3 it() blocks with similar expects:

value1 = $('.someclass');
value2 = ..
value3 = ..
expect(value1.getText()).toContain('tratata');
expect(value2.getText()).toContain('uhuhuhu');
expect(value3.getText()).toContain('ahahaha');

they are all situated in different it() blocks. Now strange thing:

When I execute tests, test with 1st assert block passes just fine, on the 2nd it block it says that assert fails(i do some stuff in order to change values), but manually / locally I see that everything is fine. Also while test is getting executed I see that values are getting changed ( i even did screenshots and check visual log on browserstack). In the 3rd it block I did other action and assert fails again, BUT it compare it with value which I was expected from step 2, not step 1!! SO looks like for some reason I am one step behind... If I comment it block or just asserts in the 1st test, 2nd one passes fine, but 3 fails. If I comment 2 it block, 3rd passes fine.

Sounds like that in this particular case for some reason some magic happens and only on Jenkins and only on Browserstack. By the way tests have been working for a while without any problems and started fail without any updates.

I though that for some reason I have problems with control flow, I WAIT for elements to be presented in addition, I tried browser.sleep() anti-pattern also to investigate it better, but it magically keeps be on the step behind.

I am not looking for particular solution directly, but any suggestions will be highly appreciated, I am not sure which additional info I should provide, hope I described the problem enough.

@protractor2.1.0 @jasmine2.3.2

browser.ignoreSynchronization = false



  it('', function () {
        expect(viewBookingDetailsPage.totalCostSection.depositDue.getText()).toContain('542.00');
        expect(viewBookingDetailsPage.totalCostSection.remainingBalance.getText()).toContain('4,878.00');
        expect(viewBookingDetailsPage.totalCostSection.totalDepositAmount.getText()).toContain('5,420.00');
    });


it('', function () {
        $(viewBookingDetailsPage.eventAndItemsSection.addItemsBtn).click();
        helper.waitElementToBeVisisble(viewBookingDetailsPage.addItemsModal.modalOpen);

        viewBookingDetailsPage.addonItemAttribute(0, viewBookingDetailsPage.addItemsModal.events).click();

        helper.waitElementToBeVisisble(viewBookingDetailsPage.addItemsModal.eventSelectionPopup);

        viewBookingDetailsPage.addItemsModal.availableEvents.then(function (events) {
            //Morning event
            events[3].$('i').click();
            viewBookingDetailsPage.addonItemAttribute(0, viewBookingDetailsPage.addItemsModal.selectItem).click();
            viewBookingDetailsPage.addonItemAttribute(1, viewBookingDetailsPage.addItemsModal.selectItem).click();
            viewBookingDetailsPage.addItemsModal.addButton.click();

            helper.waitElementToDisappear(viewBookingDetailsPage.addItemsModal.modalOpen);
            helper.waitElementToBeVisible(viewBookingDetailsPage.addonItemDetail(0, 0, 0, viewBookingDetailsPage.eventAndItemsSection.itemName));

            expect(viewBookingDetailsPage.totalCostSection.depositDue.getText()).toContain('592.00');
            expect(viewBookingDetailsPage.totalCostSection.remainingBalance.getText()).toContain('5,328.00');
            expect(viewBookingDetailsPage.totalCostSection.totalDepositAmount.getText()).toContain('5,920.00');
        });
    });

     it('', function () {

        viewBookingDetailsPage.addonItemDetail(0, 0, 0, viewBookingDetailsPage.eventAndItemsSection.removeItem).click();  ----- method just returns element into multiple internal repeaters

        expect(viewBookingDetailsPage.totalCostSection.depositDue.getText()).toContain('580.00');
        expect(viewBookingDetailsPage.totalCostSection.remainingBalance.getText()).toContain('5,220.00');
        expect(viewBookingDetailsPage.totalCostSection.totalDepositAmount.getText()).toContain('5,800.00');
    });

回答1:


I fixed this with waiting directly to text to change:

browser.wait(function() {
    return viewBookingDetailsPage.totalCostSection.depositDue.getText().then(function(text) {
        return text === '592.00USD';
    });
}, 15000);

I am sure that something goes wrong here, but it worked for me. If I will have some free time I will try to enhance the answer and investigate it deeper.




回答2:


This post hints at the fact that one of the steps could be blocked waiting to complete: http://makandracards.com/makandra/1709-single-step-and-slow-motion-for-cucumber-scenarios-using-javascript-selenium. Not sure if that helps at all.



来源:https://stackoverflow.com/questions/32317703/expect-does-not-get-the-actual-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!