As Jasmine “expects” awaits the protractor’s promise to resolve

I am working on testing e2e. I have a pop confirmation that does not exist on the page until I click the button. After creating a confirmation popup, I get the text from the item.

After that, I click the "OK" button, which causes the confirmation to be removed from the DOM, as well as adding a new element to the DOM with the value that I received earlier.

the problem is that getText () returns a promise, by the time I do the comparison, the first element is missing from the screen and the test fails.

if I expect that during the confirmation pop-up on the screen, I can see the text of the confirmation pop-up element.

How does Jasmine expect () to resolve a promise?

early

+6
source share
2 answers

Something like that?

element(by.id('dangerous-activity')).click().then(function () { element(by.id('confirmation-text')).getText().then(function (textToConfirm) { element(by.id('confirm-button')).click().then(function () { element(by.id('new-element')).getText().then(function (newText)) { expect(newText).toBe(textToConfirm); }); }); }); }); 

Here, all promises are explicitly allowed, so Jasmine no longer needs to make any promises.

You can let expect resolve the new-element promise by replacing the last two lines with:

  .... expect(element(by.id('new-element')).getText()).toBe(textToConfirm); .... 

But you cannot get textToConfirm in the same expectation, since it disappeared when you specified.

+6
source

This should be the easiest way to do what you want:

 $('#open-popup').click(); var textToConfirm = $('#popup-text').getText(); $('#confirm-button').click(); var newText = $('#new-element').getText(); expect(newText).toBe(textToConfirm); 

Please note that this will not work:

 $('#open-popup').click(); var textToConfirmElement = $('#popup-text'); $('#confirm-button').click(); var newText = $('#new-element').getText(); expect(newText).toBe(textToConfirmElement.getText()); 

because here you get the text after the popup is already closed.

+3
source

Source: https://habr.com/ru/post/980695/


All Articles