Want more features on Pastebin? Sign Up, it's FREE!
Guest

Capyraba MultiThread

By: a guest on Jun 15th, 2012  |  syntax: Ruby  |  size: 1.85 KB  |  views: 57  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'capybara/dsl'
  2. require 'capybara-webkit'
  3.  
  4. # Registro il Driver Crome
  5. Capybara.register_driver :selenium_chrome do |app|
  6.   Capybara::Selenium::Driver.new(app, :browser => :chrome)
  7. end
  8. Capybara.default_driver = :selenium_chrome
  9. Capybara.app_host = "https://exau.casc.eu/ca/web/pages/welcome.iface"
  10.  
  11.  
  12. module Test
  13.   class Casc
  14.     include Capybara::DSL
  15.  
  16.     def set_session(id)
  17.         Capybara.instance_variable_set("@session_pool", {
  18.          "#{Capybara.current_driver}#{Capybara.app.object_id}" => $sessions[id]
  19.         })
  20.     end
  21.  
  22.     def in_session(id, &block)
  23.       $sessions ||= {}
  24.       $sessions[:default] ||= Capybara.current_session
  25.       $sessions[id]       ||= Capybara::Session.new(Capybara.current_driver, Capybara.app)
  26.       set_session(id)
  27.       yield
  28.       set_session(:default)
  29.     end
  30.  
  31.     def home()
  32.         $sessions ||= {}
  33.        
  34.         a=Thread.new do
  35.             $sessions["uno"] = Capybara::Session.new(Capybara.current_driver, Capybara.app)
  36.             Capybara.instance_variable_set("@session_pool", {
  37.              "#{Capybara.current_driver}#{Capybara.app.object_id}" => $sessions["uno"]
  38.             })
  39.             $sessions["uno"].visit('/')
  40.             $sessions["uno"].fill_in "username", :with => "michele.boscolo@eni.com"
  41.         end
  42.  
  43.         b=Thread.new do
  44.             $sessions["due"] = Capybara::Session.new(Capybara.current_driver, Capybara.app)
  45.             Capybara.instance_variable_set("@session_pool", {
  46.              "#{Capybara.current_driver}#{Capybara.app.object_id}" => $sessions["due"]
  47.             })
  48.             $sessions["due"].visit('/')
  49.             $sessions["due"].fill_in "username", :with => "michele.boscolo@eni.com"
  50.         end
  51.         # Attendo che i Thread finiscano
  52.         a.join(20)
  53.         b.join(20)
  54.     end
  55.  
  56.   end
  57. end
  58.  
  59. spider = Test::Casc.new
  60. spider.home()
clone this paste RAW Paste Data