Unable to test Angular UI Typeahead with Poltergeist and PhantomJS

I have a problem with testing I / O. I use Rails, RSpec, Capybara, Angular UI 0.10, AngularJS, Poltergeist. This is my test:

create(:user, name: "Test User")
fill_in 'User', with: "Test"
find('#delegations').find('li.active').click

If I run it using the Chrome driver, it will work successfully. However, when starting with Poltergeist, the offer window is not displayed, although the server receives the request and returns users accordingly.

I think it fill_inlaunches blurin the field, causing the window to disappear. I used Capybara::Screenshotto see if there was any suggestion, but there wasn’t. The input field does not even get into focus.

+4
source share
1 answer

I found out that this is really because the poltergeist runs blurin fill_in. All I had to do was fill in the typeahead field by running this script:

page.execute_script "$('input[typeahead]').unbind('blur')"

Thus, the UI Typeahead event is blurnot raised, and he believes that he has focus on the field, accordingly creating a proposal window.

If you are not using jQuery, this script works with AngularJS:

elements = document.getElementsByTagName('input');
for (var i = 0; i < elements.length; i++) {
  if (elements[i].hasAttribute('typeahead')) {
    angular.element(elements[i]).unbind('blur');
  }
}
+10
source

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


All Articles