I have a select2 v4 that loads options through AJAX. I am running a Cucumber test where I need to select 2 options of the list, but I can't seem to make the list open up and load (which normally gets populated when I type 2 or characters).
I have tried:
As suggested here:
@session.execute_script("$('#publish_to').select2('open')")
and
@session.first(".input.publish_to .select2-container").click
and
@session.first("#publish_to").find(".select2-choice").click
which do not give me an error, but I am not getting the options to select, so I am assuming that the click is not really working. Things I have tried to select the options:
# This one cannot find the css:
@session.find(".select2-results__options", text: client.email).click
# This one gives me a Timeout error
@session.evaluate_script "$('#publish_to').val(#{client.id}).trigger('change')"
# This one gives me a Timeout error
@session.evaluate_script "$('.select2-search__field').trigger('keydown').val('#{client.email}').trigger('keyup')";
sleep 10
@session.find('.select2-search__option', text: client.email).click
Anything with trigger
gives me a Timeout error, so I tried waiting for jQuery.active
but I never got a true
even waiting for 2 minutes:
counter = 0
timeout_in_sec = 120
while counter < timeout_in_sec && @session.evaluate_script('jQuery.active').zero?
sleep 1.second
counter+=1
end
I tried using the gem capybara-select2 running:
@session.select2 client.email, css: '#publish_to', search: true
but I get the error undefined method
select2' for #and I have
World(CapybaraSelect2)in my
env.rb`
I am using Cucumber v3.1.2
with ruby gem 'cucumber-rails'