{"action":"created","issue":{"url":"https://api.github.com/repos/minkphp/MinkSelenium2Driver/issues/198","labels_url":"https://api.github.com/repos/minkphp/MinkSelenium2Driver/issues/198/labels{/name}","comments_url":"https://api.github.com/repos/minkphp/MinkSelenium2Driver/issues/198/comments","events_url":"https://api.github.com/repos/minkphp/MinkSelenium2Driver/issues/198/events","html_url":"https://github.com/minkphp/MinkSelenium2Driver/issues/198","id":56439763,"number":198,"title":"setValue does not work correctly with focused fields","user":{"login":"Chekote","id":550486,"avatar_url":"https://avatars.githubusercontent.com/u/550486?v=3","gravatar_id":"","url":"https://api.github.com/users/Chekote","html_url":"https://github.com/Chekote","followers_url":"https://api.github.com/users/Chekote/followers","following_url":"https://api.github.com/users/Chekote/following{/other_user}","gists_url":"https://api.github.com/users/Chekote/gists{/gist_id}","starred_url":"https://api.github.com/users/Chekote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chekote/subscriptions","organizations_url":"https://api.github.com/users/Chekote/orgs","repos_url":"https://api.github.com/users/Chekote/repos","events_url":"https://api.github.com/users/Chekote/events{/privacy}","received_events_url":"https://api.github.com/users/Chekote/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/minkphp/MinkSelenium2Driver/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":31,"created_at":"2015-02-03T21:26:02Z","updated_at":"2015-03-16T19:46:35Z","closed_at":null,"body":"This took me a long time to track down, and it's somewhat difficult to explain, but here goes...\r\n\r\nThis is causing tests to fail on my project because I'm testing pages that have certain fields auto-focused depending on user actions.\r\n\r\nOS: Mac OS X 10.10\r\nBrowser: Firefox 31.4.0esr, 33.1.1, 34.0.5\r\nSelenium: 2.44\r\n\r\nUnfortunately it's difficult to create a pull request to demonstrate this because this repo uses tests and fixtures defined in one of it's vendors folders, which is outside of version control. So I'm going to have to post details here instead.\r\n\r\nI had a lot of difficulty creating a failing test that would illustrate this issue, because I could not get the field to focus during testing using evaluateScript() or even by adding a simple button with an onclick=\"blablabla.focus()\", because for some reason that didn't work either! *pulls hair out*.\r\n\r\nThe only way I can get this test to fail is to add a function that is called by a button... bizarre. Anyway, onto the details:\r\n\r\nAdd the following snippet to the end of the body tag in `/vendor/behat/mink/driver-testsuite/web-fixtures/basic_form.html`:\r\n\r\n```html\r\n    <button onclick=\"doFocus()\">Focus</button>\r\n\r\n    <script>\r\n      function doFocus() {\r\n        document.getElementById('lastn').focus();\r\n      }\r\n    </script>\r\n```\r\n\r\nThen drop the following into the GeneralTest class in `/vendor/behat/mink/driver-testsuite/tests/Form/GeneralTest.php`:\r\n\r\n```php\r\n    public function testFillFocusedTextField()\r\n    {\r\n        $session = $this->getSession();\r\n\r\n        $session->visit($this->pathTo('/basic_form.html'));\r\n\r\n        $page = $this->getSession()->getPage();\r\n        $page->pressButton('Focus');\r\n\r\n        $webAssert = $this->getAssertSession();\r\n        $field = $webAssert->fieldExists('last_name');\r\n        $field->setValue('Chekote');\r\n\r\n        $this->assertEquals('Chekote', $field->getValue());\r\n    }\r\n```\r\n\r\nThen run the test with `phpunit --filter \"testFillFocusedTextField\"`\r\n\r\nIt shouldn't matter where the caret is when the field is focused, because the Selenium2Driver::setValue() method prepends a backspace and a delete keystroke for each existing character to the value before passing it to the postValue method. This *should* mean that the existing value will be deleted regardless of where the caret is in the field.\r\n\r\nUnfortunately, it is failing with the caret being anywhere except the very end of the existing value. It appears that when the field is already focused, there are two possible scenarios:\r\n\r\n1. If the caret is at the very beginning of the existing value, then only the first \"delete\" keystroke is processed, and the new value inserted. So in the test above, this results in \"Lastname\" changing to \"Chekoteastname\", instead of the expected \"Chekote\".\r\n2. If the caret is anywhere within the existing value, then all of the \"delete\" keystrokes seem to be completely ignored. A few examples:\r\n\r\n```\r\nCaret positon:    Result:\r\nL|astname          Chekoteastname\r\nLa|stname          Chekotestname\r\nLas|tname          Chekotetname\r\nLast|name          Chekotename\r\n```\r\n\r\nI can fix this on my machine with a call to $element->clear() before calling the postValue(), but I understand that this probably introduces issues with events (which is why I'm guessing it was removed in 23ec6b4d4aaba1a6de8affe097a95682b90022bf).\r\n\r\nAny advice / help would be greatly appreciated."},"comment":{"url":"https://api.github.com/repos/minkphp/MinkSelenium2Driver/issues/comments/81895434","html_url":"https://github.com/minkphp/MinkSelenium2Driver/issues/198#issuecomment-81895434","issue_url":"https://api.github.com/repos/minkphp/MinkSelenium2Driver/issues/198","id":81895434,"user":{"login":"Chekote","id":550486,"avatar_url":"https://avatars.githubusercontent.com/u/550486?v=3","gravatar_id":"","url":"https://api.github.com/users/Chekote","html_url":"https://github.com/Chekote","followers_url":"https://api.github.com/users/Chekote/followers","following_url":"https://api.github.com/users/Chekote/following{/other_user}","gists_url":"https://api.github.com/users/Chekote/gists{/gist_id}","starred_url":"https://api.github.com/users/Chekote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chekote/subscriptions","organizations_url":"https://api.github.com/users/Chekote/orgs","repos_url":"https://api.github.com/users/Chekote/repos","events_url":"https://api.github.com/users/Chekote/events{/privacy}","received_events_url":"https://api.github.com/users/Chekote/received_events","type":"User","site_admin":false},"created_at":"2015-03-16T19:46:35Z","updated_at":"2015-03-16T19:46:35Z","body":"@aik099 I just saw your comment. I'm not sure why the test would be failing on your environment, as I've been running it all day and it's consistently passing for me. I'm working with the following versions at the moment:\r\n\r\nMac OS X 10.10.2\r\nFirefox 34.0.5\r\nPHPUnit 4.5.0\r\nSelenium 2.44"}}