A dropdown is not selected when it should be ... why?

I am trying to solve a mistake in our tests, which, in my opinion, should work. I am sure this is a mistake in selectize or capybara, but I cannot understand why.

I went to the source for capybara, and everything seems to work as it should. I'm not sure how to move on.

To test this error, I removed the error as much as possible in a small test application. See Settings below

bugs/show.html.erb <select id="select-repo" class="repositories selectized" placeholder="Pick a repository..."> </select> <select id="dropdown1"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> <option value="4">Four</option> </select> <select id="dropdown2"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> <option value="4">Four</option> </select> bug_spec.rb feature 'bug' do it "spec setup", js: true do visit bug_path find('div.selectize-input input', match: :first).set('exercism.io') select 'Four', from: 'dropdown1' # this is not getting selected select 'Four', from: 'dropdown2' sleep 2 expect(page).to have_select('dropdown1', selected: 'Four') # testing that dropdown1 is being selected end end # note that the javascript to initialize the selectize drop down is in application.js if you want to look at it go to the github application. 

The above test visits a page on which ajax selectize is highlighted and two elements of normal selection. It tries to put the text - "exercism.io" - in the selectize drop-down list (usually I have another line to actually simulate a hit of an enter key, but an error occurs with this line), and then it continues to set the value of dropdown1 and dropdown2. I did a js: true and sleep 2 test to make ajax work, and so you can see what actually happens when the test starts.

The problem is that it cannot set the value of dropdown1. When you run the test and see what happens, you can see that it finds a value for the installation, but it is not actually installed. He just moves on to the next choice.

Another strange thing is to change the test, as shown below, the test passes. Therefore, I am sure that this is due to the installation of a drop-down list.

bug_spec.rb

 feature 'bug' do it "spec setup", js: true do visit bug_path select 'Four', from: 'dropdown1' # this is not getting selected select 'Four', from: 'dropdown2' find('div.selectize-input input', match: :first).set('exercism.io') sleep 2 expect(page).to have_select('dropdown1', selected: 'Four') # testing that dropdown1 is being selected end end 

I reproduced this error in a demo application which can be found on github.

Sorry if this is a long time, I was not sure how else to answer this question.

Please note that this example is being deleted. In my actual code, I use the code that the guys have to use capybara and select together.

+6
source share
1 answer

I got an answer on the capybara forums .

It looks like the browser focus issue was mentioned in @tgf (in link )

Thanks.

0
source

Source: https://habr.com/ru/post/985881/


All Articles