From b5349bd6a36c0e0ca71465a5349f8d68c1d1e102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81re=CC=81my=20DECOOL?= Date: Wed, 20 Dec 2017 07:07:51 +0100 Subject: [PATCH] Fix issue when fill select2 input when it's already open --- src/Context/Select2Context.php | 3 +++ tests/features/select2.feature | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Context/Select2Context.php b/src/Context/Select2Context.php index afa9f8c..98494ac 100644 --- a/src/Context/Select2Context.php +++ b/src/Context/Select2Context.php @@ -97,6 +97,9 @@ public function iShouldSeeSelectChoices($field, $num) */ private function openField(DocumentElement $page, $field) { + // force select2 to be closed + $page->find('css', 'body')->press(); + $fieldName = sprintf('select[name="%s"] + .select2-container', $field); $inputField = $page->find('css', $fieldName); diff --git a/tests/features/select2.feature b/tests/features/select2.feature index d00104b..a66c361 100644 --- a/tests/features/select2.feature +++ b/tests/features/select2.feature @@ -56,3 +56,12 @@ Feature: Select2 Feature Scenario: Given I am on "/select2-ajax.html" Then I fill in select2 "select_number" with "France" and wait 6 seconds until results are loaded + + @javascript + Scenario: Test fill select2 if list already open + Given I am on "/select2.html" + When I fill in select2 input "select_number" with "F" + Then I should see 2 choice in select2 "select_number" + + When I fill in select2 input "select_number" with "F" + Then I fill in select2 "select_number" with "Four"