Race condition with Capybara value set
I have faced an issue while using .set(#value)
to fill the text field in registering form, e.g: the phone number i wanna put in is 506307
then it ended up with 063075
.
The work-around i have been made is executing Javascript block like
execute_script("document.querySelector('#selector').value = '#value'")
However, using the same scripts applying for Webmobile based on React.JS, the scripts above just send the text but didn't send the onChange
event, which cause another element cannot be selected/clicked -> made the test failed.
I came up with another approach is to use the send_keys #value
to trigger the key-pressed event that would make browser think there was a key-pressed event happen for that form, but it ended up with race-condition like set(#value)
as i mentioned.
The another work-around is using What is the best way to trigger onchange event in react js , but i tend to use the native Capybara actions before making that tricky Javascript.
So, is there any other way to interact / fill the form field which won't cause that Race condition issue ?
Thanks everybody in advance.
ruby selenium capybara
add a comment |
I have faced an issue while using .set(#value)
to fill the text field in registering form, e.g: the phone number i wanna put in is 506307
then it ended up with 063075
.
The work-around i have been made is executing Javascript block like
execute_script("document.querySelector('#selector').value = '#value'")
However, using the same scripts applying for Webmobile based on React.JS, the scripts above just send the text but didn't send the onChange
event, which cause another element cannot be selected/clicked -> made the test failed.
I came up with another approach is to use the send_keys #value
to trigger the key-pressed event that would make browser think there was a key-pressed event happen for that form, but it ended up with race-condition like set(#value)
as i mentioned.
The another work-around is using What is the best way to trigger onchange event in react js , but i tend to use the native Capybara actions before making that tricky Javascript.
So, is there any other way to interact / fill the form field which won't cause that Race condition issue ?
Thanks everybody in advance.
ruby selenium capybara
add a comment |
I have faced an issue while using .set(#value)
to fill the text field in registering form, e.g: the phone number i wanna put in is 506307
then it ended up with 063075
.
The work-around i have been made is executing Javascript block like
execute_script("document.querySelector('#selector').value = '#value'")
However, using the same scripts applying for Webmobile based on React.JS, the scripts above just send the text but didn't send the onChange
event, which cause another element cannot be selected/clicked -> made the test failed.
I came up with another approach is to use the send_keys #value
to trigger the key-pressed event that would make browser think there was a key-pressed event happen for that form, but it ended up with race-condition like set(#value)
as i mentioned.
The another work-around is using What is the best way to trigger onchange event in react js , but i tend to use the native Capybara actions before making that tricky Javascript.
So, is there any other way to interact / fill the form field which won't cause that Race condition issue ?
Thanks everybody in advance.
ruby selenium capybara
I have faced an issue while using .set(#value)
to fill the text field in registering form, e.g: the phone number i wanna put in is 506307
then it ended up with 063075
.
The work-around i have been made is executing Javascript block like
execute_script("document.querySelector('#selector').value = '#value'")
However, using the same scripts applying for Webmobile based on React.JS, the scripts above just send the text but didn't send the onChange
event, which cause another element cannot be selected/clicked -> made the test failed.
I came up with another approach is to use the send_keys #value
to trigger the key-pressed event that would make browser think there was a key-pressed event happen for that form, but it ended up with race-condition like set(#value)
as i mentioned.
The another work-around is using What is the best way to trigger onchange event in react js , but i tend to use the native Capybara actions before making that tricky Javascript.
So, is there any other way to interact / fill the form field which won't cause that Race condition issue ?
Thanks everybody in advance.
ruby selenium capybara
ruby selenium capybara
asked Nov 13 '18 at 3:23
Dinh LuongDinh Luong
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Note: Any "solution" suggested that is purely the use of execute_script
to run some JS is a terrible idea since it completely bypasses the concept of testing what a user can do and can basically make your test worthless.
The root cause of the issue here is the JS behavior attached to the input not being able to handle the key events fast enough. The proper fix would be to fix the JS, however if that's not possible there's a few things you can try
First you can try changing the clear method being used by set
element.set('506307', clear: :backspace)
or
element.set('506307', clear: :none)
If that doesn't change anything then try clicking on the input, followed by a short sleep before setting the content
element.click
sleep 0.25
element.set('506307')
If none of those work around the issue we need to know exactly what JS behavior you have attached to the input and/or what events that JS behavior is listening to.
Thanks a lot. I tried with the first 2 options and the race-condition happened intermittently. Fortunately, the last one seems to solve the race-condition, by clicking and giving a lil bit sleep then the issue seems disappear. This helps me to remove the tricky Javascript above.
– Dinh Luong
Nov 15 '18 at 6:17
@DinhLuong you’re welcome - if you’re question is answered don’t forget to accept the answer (the check mark) so the question gets marked as answered.
– Thomas Walpole
Nov 15 '18 at 6:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273329%2frace-condition-with-capybara-value-set%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Note: Any "solution" suggested that is purely the use of execute_script
to run some JS is a terrible idea since it completely bypasses the concept of testing what a user can do and can basically make your test worthless.
The root cause of the issue here is the JS behavior attached to the input not being able to handle the key events fast enough. The proper fix would be to fix the JS, however if that's not possible there's a few things you can try
First you can try changing the clear method being used by set
element.set('506307', clear: :backspace)
or
element.set('506307', clear: :none)
If that doesn't change anything then try clicking on the input, followed by a short sleep before setting the content
element.click
sleep 0.25
element.set('506307')
If none of those work around the issue we need to know exactly what JS behavior you have attached to the input and/or what events that JS behavior is listening to.
Thanks a lot. I tried with the first 2 options and the race-condition happened intermittently. Fortunately, the last one seems to solve the race-condition, by clicking and giving a lil bit sleep then the issue seems disappear. This helps me to remove the tricky Javascript above.
– Dinh Luong
Nov 15 '18 at 6:17
@DinhLuong you’re welcome - if you’re question is answered don’t forget to accept the answer (the check mark) so the question gets marked as answered.
– Thomas Walpole
Nov 15 '18 at 6:57
add a comment |
Note: Any "solution" suggested that is purely the use of execute_script
to run some JS is a terrible idea since it completely bypasses the concept of testing what a user can do and can basically make your test worthless.
The root cause of the issue here is the JS behavior attached to the input not being able to handle the key events fast enough. The proper fix would be to fix the JS, however if that's not possible there's a few things you can try
First you can try changing the clear method being used by set
element.set('506307', clear: :backspace)
or
element.set('506307', clear: :none)
If that doesn't change anything then try clicking on the input, followed by a short sleep before setting the content
element.click
sleep 0.25
element.set('506307')
If none of those work around the issue we need to know exactly what JS behavior you have attached to the input and/or what events that JS behavior is listening to.
Thanks a lot. I tried with the first 2 options and the race-condition happened intermittently. Fortunately, the last one seems to solve the race-condition, by clicking and giving a lil bit sleep then the issue seems disappear. This helps me to remove the tricky Javascript above.
– Dinh Luong
Nov 15 '18 at 6:17
@DinhLuong you’re welcome - if you’re question is answered don’t forget to accept the answer (the check mark) so the question gets marked as answered.
– Thomas Walpole
Nov 15 '18 at 6:57
add a comment |
Note: Any "solution" suggested that is purely the use of execute_script
to run some JS is a terrible idea since it completely bypasses the concept of testing what a user can do and can basically make your test worthless.
The root cause of the issue here is the JS behavior attached to the input not being able to handle the key events fast enough. The proper fix would be to fix the JS, however if that's not possible there's a few things you can try
First you can try changing the clear method being used by set
element.set('506307', clear: :backspace)
or
element.set('506307', clear: :none)
If that doesn't change anything then try clicking on the input, followed by a short sleep before setting the content
element.click
sleep 0.25
element.set('506307')
If none of those work around the issue we need to know exactly what JS behavior you have attached to the input and/or what events that JS behavior is listening to.
Note: Any "solution" suggested that is purely the use of execute_script
to run some JS is a terrible idea since it completely bypasses the concept of testing what a user can do and can basically make your test worthless.
The root cause of the issue here is the JS behavior attached to the input not being able to handle the key events fast enough. The proper fix would be to fix the JS, however if that's not possible there's a few things you can try
First you can try changing the clear method being used by set
element.set('506307', clear: :backspace)
or
element.set('506307', clear: :none)
If that doesn't change anything then try clicking on the input, followed by a short sleep before setting the content
element.click
sleep 0.25
element.set('506307')
If none of those work around the issue we need to know exactly what JS behavior you have attached to the input and/or what events that JS behavior is listening to.
edited Nov 13 '18 at 5:32
answered Nov 13 '18 at 5:27
Thomas WalpoleThomas Walpole
30.7k32748
30.7k32748
Thanks a lot. I tried with the first 2 options and the race-condition happened intermittently. Fortunately, the last one seems to solve the race-condition, by clicking and giving a lil bit sleep then the issue seems disappear. This helps me to remove the tricky Javascript above.
– Dinh Luong
Nov 15 '18 at 6:17
@DinhLuong you’re welcome - if you’re question is answered don’t forget to accept the answer (the check mark) so the question gets marked as answered.
– Thomas Walpole
Nov 15 '18 at 6:57
add a comment |
Thanks a lot. I tried with the first 2 options and the race-condition happened intermittently. Fortunately, the last one seems to solve the race-condition, by clicking and giving a lil bit sleep then the issue seems disappear. This helps me to remove the tricky Javascript above.
– Dinh Luong
Nov 15 '18 at 6:17
@DinhLuong you’re welcome - if you’re question is answered don’t forget to accept the answer (the check mark) so the question gets marked as answered.
– Thomas Walpole
Nov 15 '18 at 6:57
Thanks a lot. I tried with the first 2 options and the race-condition happened intermittently. Fortunately, the last one seems to solve the race-condition, by clicking and giving a lil bit sleep then the issue seems disappear. This helps me to remove the tricky Javascript above.
– Dinh Luong
Nov 15 '18 at 6:17
Thanks a lot. I tried with the first 2 options and the race-condition happened intermittently. Fortunately, the last one seems to solve the race-condition, by clicking and giving a lil bit sleep then the issue seems disappear. This helps me to remove the tricky Javascript above.
– Dinh Luong
Nov 15 '18 at 6:17
@DinhLuong you’re welcome - if you’re question is answered don’t forget to accept the answer (the check mark) so the question gets marked as answered.
– Thomas Walpole
Nov 15 '18 at 6:57
@DinhLuong you’re welcome - if you’re question is answered don’t forget to accept the answer (the check mark) so the question gets marked as answered.
– Thomas Walpole
Nov 15 '18 at 6:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273329%2frace-condition-with-capybara-value-set%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown