-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent firing the "change" event twice #286
Conversation
The #244 pull request changed TAB adding behavior that indirectly made Anyways because of massive failure of test suite on Travis CI I can't have solid proof that it doesn't break any Mink driver tests. Please, if possible, send another PR for fixing test suite failures (only change driver code). |
I am sorry, but I am not sure I understand what exactly I have to do? |
This, an and many other, projects have tests suites in place to ensure that new code changes won't break any of existing behavior. PHP-based projects like to use PHPUnit for that. The Travis CI is website, that runs these tests for us on each PR so before merging we'll know if it breaks anything or not. Unfortunately due rapid Selenium development lately most of the tests now fail and core maintainers of the project are also very busy. The tests link for your PR is: https://travis-ci.org/minkphp/MinkSelenium2Driver/builds/392645545 In there there is a build for every PHP version supported. For example PHP 5.4 link is https://travis-ci.org/minkphp/MinkSelenium2Driver/jobs/392645547 and it fails with a PHP Fatal Error:
The For PHP 7.1/7.0 the build is terribly slow (~40 minutes): https://travis-ci.org/minkphp/MinkSelenium2Driver/jobs/392645550 The PHP 7.0 build using remote Selenium instance finishes in time and no fatal errors: https://travis-ci.org/minkphp/MinkSelenium2Driver/jobs/392645553 , but some |
Hah, I am aware of all the testing stuff :). But thanks for explaining it. I only didn't understand what you mean by
The build with the remote Selenium instance is testing with Firefox. As mentioned in the issue I've noticed the problem with Chrome. Let's see what happens when we use Chrome. |
Mink is the main project. It has different repos for all of it's drivers. And there is another repo to store tests that all drivers must pass. If the test suite is failing for a particular driver, then that driver's code needs to be fixed instead of altering the test code. |
@aik099 I've tried what you've suggested in #243 (comment) and it fixes my test fails. I was thinking about the problem and while I cannot really define our use case I think that it is much safer to call I think that I think that we probably still have to ensure that the currently focused element is still the element we've set the value to. |
The change event triggering via |
But the change event is triggered once you loose focus and not while typing. So why do we want to trigger the change event while typing? |
Now I get it. Then you're correct. |
…y in case that element still has the focus. This will trigger the change event.
I've just updated the PR so that we remove the focus from the currently focused element only in case this is still the element on which we've set the value to. If it is not, then there is nothing to do, as if the element has lost the focus in the meanwhile, then the change event will have been triggered already. |
This PR build https://travis-ci.org/minkphp/MinkSelenium2Driver/builds/394658837 analysis:
To conclude I think this PR is ready to be merged. |
|
Merging, thanks @hchonov . |
Thank you, @aik099 . |
This change is causing my tests to break that are filling in a Drupal autocomplete field. If I revert commit d8adafd then my tests are green again. This matches what @aik099 predicted in #286 (comment) - this is a "typeahead" feature which now doesn't work any more because the field is being blurred. |
Wouldn't it be better to just trigger a change event if we detect that the element still has focus? If the element still has focus, then a change event hasn't triggered yet, and it is safe to trigger it at that point. That approach would better preserve backwards compatibility.
|
@pfrenssen , thanks for testing this out. I wish you had ability to do this prior to the merge. Maybe we should add typeahead test to the test suite to avoid this break again. @hchonov , could you please test the change proposed in #286 (comment) and see if that doesn't break anything on your side. If all is fine I'll happily merge PR. The typeahead control support isn't a feature, but an unexpected side effect of a way how |
I am trying to follow the development quite closely but this wasn't on my radar unfortunately. I am happy to assist in any way I can. I can perhaps try to provide a typeahead test. |
The test for typeahead is likely to be located in https://github.com/minkphp/driver-testsuite/blob/master/tests/Js/JavascriptTest.php , but I'm not sure if other JS-enabled drivers would pass it. |
P.S. I am just trying to find an optimal solution and not simply fixing the test failures ASAP. It will be best for us if we find a good solution and fix this once and forever. |
That won't go though, because this driver method is part of
Unfortunately the Selenium should (and maybe already does to some extent) should fire |
I am actually in agreement with this. Autocomplete fields are an edge case. But unfortunately we are breaking backwards compatibility. I don't know the policy of the maintainers regarding breaking backwards compatibility for edge cases like this? For me personally it would be fine, I already have my workaround. We have to be aware that there are probably other users that will face this once we release a new version.
Thanks for the research. I will use jQuery Autocomplete for the test.
Good idea, this is important information, so I researched this. It turns out that this test was written in September 2016 (ref Issue #2788209: Entity reference field "Autocomplete matching: Starts with" option does not work). The solution with the change event was merged in October 2016 (ref. #244). So this test simply dates from a time when the change event was not being output.
Very good point. Any other suggestions? Would you accept local state to be set? A possible solution would be that we provide an additional interface for drivers that use Selenium, just thinking out loud here. We could then check for this interface and use a local static parameter to track which method to use:
|
Prior to #244 (you can see it on the diff) the |
I searched the Chromium bug tracker and found the issue about the tab key not working in Chrom[eIium] 53: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1484 Apparently this was already fixed less than a week after it was initially reported, here is the commit fixing the issue: https://codereview.chromium.org/2302803004, from September 2, 2016. You can see in the So it looks like this was a very short lived bug which probably only affected Chrome 53. Once we have the test on our end we can check if reverting #244 works now for both the cases of @hchonov and me. |
I have created a test: minkphp/driver-testsuite#22 I have tested it locally and these are the results:
The last point is very interesting. In the current stable release the usage of BTW here is the patch for reverting #244: https://gist.github.com/pfrenssen/0bf4137fb3521334e671d61b3e0f3dff |
What happens with
So what should we do. Revert code state to broken auto-complete? |
I couldn't find a test that contains the exact wording
This 1 error is a known failure, it has been reported in #239. I'm getting the same results for the latest master, when reverting this PR, and when running the test on v1.3.1. |
Great. Then change event when filling the input is indeed fired only once. |
I have proposed a workaround for our project so we have a dedicated way of filling in autocomplete fields. We are using Behat for our tests. If other people are also experiencing this problem they can refer to this: ec-europa/joinup-dev#1301 |
I'm only now realizing why auto-complete tests fail. It's because leading focus of the field to cause As mentioned in #292 current code, that fires change event in non-atomic way cause stale element reference in some cases. |
Well, the issue with that is different expectation for this code:
IMO, the issue here is expecting that |
Then we can't really support both cases automatically. Global flag during driver initialization would process all input fields as auto-completes or not so that's no good. Changing |
I've arrived here from #292 and after opening #301. |
@JordiGiros , you're correct.
@JordiGiros , not possible I'm afraid. Changing the |
@aik099 we do support adding new methods in DriverInterface, as our policy explicitly states that we expect drivers to extend CoreDriver if they want to be covered by BC (and so we can add new method if we also add them in CoreDriver as |
and for usage in Behat, it is still possible to write another Behat step which would use a new API (it would of course require to update the Behat scenario) |
Ah, then with the help of new method we can cover auto-complete inputs. Then PR could be created to cover this. |
As I understund, it is as easy as adding into Mink's CoreDriver.php
And DriverInterface.php
Then we can generate that method in MinkSelenium2Driver project. Isn't it? |
Something, like that. Yes. |
I support this solution, this would solve it for both expected use cases, then it is just a matter of using the right method. Thanks! |
Since version 1.4.0 the Selenium driver for Mink uses again the element on which the value was set (see minkphp/MinkSelenium2Driver#286). When creating a new folder or renaming one sending a new line ("\r") caused the element on which the value was set to be removed, so the element was no longer attached to the DOM when the driver tried to use it again, and thus a "StaleElementReference" exception was thrown. Due to this now it is needed to explicitly click the confirm button when creating a new folder. In the case of the renaming, on the other hand, nothing else besides not sending the new line is needed, as the Selenium driver now unfocuses the element (that is why it uses again the element after setting the value) which triggers the renaming. Signed-off-by: Daniel Calviño Sánchez <[email protected]>
Since version 1.4.0 the Selenium driver for Mink uses again the element on which the value was set (see minkphp/MinkSelenium2Driver#286). When creating a new folder or renaming one sending a new line ("\r") caused the element on which the value was set to be removed, so the element was no longer attached to the DOM when the driver tried to use it again, and thus a "StaleElementReference" exception was thrown. Due to this now it is needed to explicitly click the confirm button when creating a new folder. In the case of the renaming, on the other hand, nothing else besides not sending the new line is needed, as the Selenium driver now unfocuses the element (that is why it uses again the element after setting the value) which triggers the renaming. Besides that, the Selenium driver for Mink uses a library to simulate certain events, bitovi/syn. In version 1.4.0 that library was updated to version 0.0.3, which seems to somehow break pressing the "escape" key. Due to this now the sharing menu has to be closed by pressing "enter" on the share menu button instead. Signed-off-by: Daniel Calviño Sánchez <[email protected]>
Since version 1.4.0 the Selenium driver for Mink uses again the element on which the value was set (see minkphp/MinkSelenium2Driver#286). When creating a new folder or renaming one sending a new line ("\r") caused the element on which the value was set to be removed, so the element was no longer attached to the DOM when the driver tried to use it again, and thus a "StaleElementReference" exception was thrown. Due to this now it is needed to explicitly click the confirm button when creating a new folder. In the case of the renaming, on the other hand, nothing else besides not sending the new line is needed, as the Selenium driver now unfocuses the element (that is why it uses again the element after setting the value) which triggers the renaming. Besides that, the Selenium driver for Mink uses a library to simulate certain events, bitovi/syn. In version 1.4.0 that library was updated to version 0.0.3, which seems to somehow break pressing the "escape" key. Due to this now the sharing menu has to be closed by pressing "enter" on the share menu button instead. Signed-off-by: Daniel Calviño Sánchez <[email protected]>
Fixes #285