In a web form created using AngularJS, I am trying to enter some data into a combo box, then select a value by pressing the down arrow key and then the Enter key. After that, I check that the popup with the list (this is the Combo Box Kendo UI) is no longer visible.
Tests run on Chrome on Windows and Mac OS X. On Windows, the following code works fine:
comboInput.sendKeys('CAN') .sendKeys(protractor.Key.ENTER) .sendKeys(protractor.Key.ARROW_DOWN) .sendKeys(protractor.Key.ENTER); expect(input.getAttribute('value')).toBe('id_3'); expect(popup.getAttribute('style')).toContain('display: none');
The protractor enters βCANβ into the combo box, then selects the visible entry using the down arrow key, and then confirms the selection with the βEnterβ key, which also rejects the Combo Box pop-up window.
On OS X, this does not work, the second wait always fails, because the Enter event does not fire before rejecting the popup before evaluating the wait for any reason.
I found that I need to change the code to the following so that it works:
comboInput.sendKeys('CAN') .sendKeys(protractor.Key.ENTER) .sendKeys(protractor.Key.ARROW_DOWN) .sendKeys(protractor.Key.ENTER).then(function() { expect(input.getAttribute('value')).toBe('id_3'); expect(popup.getAttribute('style')).toContain('display: none'); });
sendKeys returns the promise, and if I put the wait there, everything will be fine.
Is this the right way to do this? None of the examples I found on the Internet call then on sendKeys .
And why does the first code work on Windows and not OS X? Am I missing something? Is there a better way to do this?
Change Perhaps this is due to handling built-in keyboard events in OS X? The Protractor documentation at http://angular.imtqy.com/protractor/#/api?view=webdriver.WebElement.prototype.sendKeys has the following:
Note. In browsers where native keyboard events are not yet supported (for example, Firefox on OS X), key events will be synthesized. Special control keys will be synthesized in accordance with the standard QWERTY en-us keyboard layout.
javascript angularjs protractor
nwinkler
source share