Testing jQuery Selectable capybara or selenium (ctrl + click)

后端 未结 1 1660
迷失自我
迷失自我 2021-01-15 05:35

I\'m using jQuery Selectable to manage a calendar. This function works great, its just a matter of getting in to test automation.

I need to select multiple non-cons

相关标签:
1条回答
  • 2021-01-15 06:10

    You can use selenium-webdriver's action builder. However, there seems to be a bug in the firefoxdriver that prevents this from working at the moment (possibly issue 4863).

    Here is a working example of the JQuery Selectable page using Chrome:

    require 'capybara'
    require 'capybara/dsl'
    include Capybara::DSL
    
    #Use selenium-webdriver with chrome
    Capybara.register_driver :selenium do |app|
      Capybara::Selenium::Driver.new(app, :browser => :chrome)
    end
    Capybara.current_driver = :selenium
    
    #Go to the JQuery Selectable example page
    Capybara.app_host = 'http://jqueryui.com/selectable/'
    page.visit('')
    
    #The controls are in a frame, so need to switch to it
    within_frame 0 do
        #Create a selenium-webdriver action builder
        builder = page.driver.browser.action
    
        #Hold control key down
        builder.key_down(:control)
    
        #Click all elements that you want, in this case we click all lis
        #Note that you can retrieve the elements using capybara's
        #  standard methods. When passing them to the builder
        #  make sure to do .native
        elements = page.all('ol#selectable li')
        elements.each do |e|        
            builder.click(e.native)
        end
    
        #Release control key
        builder.key_up(:control)
    
        #Do the action setup
        builder.perform
    end
    
    0 讨论(0)
提交回复
热议问题