开发者

change jquery event it's not triggered when running cucumber with capybara

开发者 https://www.devze.com 2023-02-17 03:51 出处:网络
I was testing some jquery code in my browser with cucumber and capybara, and in a text field when the change event happen, it calls a certain function, when I manually do this action everything works,

I was testing some jquery code in my browser with cucumber and capybara, and in a text field when the change event happen, it calls a certain function, when I manually do this action everything works, but when running cucumber i fill the text field with a new value but the function is not executed.

Meanwhile, there is another text field linked with a keyup jquery event that triggers another function开发者_高级运维 and that works manually in the browser or running cucumber

so which could be the reason for the change event callback function isn't triggered when running cucumber?


I'm having the same error and still not found the solution. But this guy (http://pullmonkey.com/2011/03/03/capybara-does-not-trigger-js-change-event-with-celertiy-driver/) simulate a change event and seems to work.


One easy workaround I've found is to fill/interact with another input so the one being tested loses focus and browser will trigger change event. Sometimes it's a matter of rearranging sequence of populating inputs, sometimes it's an extra redundant step.


I had this problem as well... Capybara would fill out "12345" and then I would check the password in the database and it would only be 1234 or 123.

My workaround was basically to create a helper method in my global steps that took an "enter" argument.

so it works something like this:

find('css').set(value)

find('css').set("\n") if enter.present?

Essentially, by doing this it "confirms" the input, kind of how you would do as a user. I think it's cleaner than clicking other inputs or toggling things on the page to make it capture what's in your input, since it's relative to the exact same input.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号