selenium_dsl 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -3,3 +3,7 @@
3
3
  == Version 1.0.0
4
4
 
5
5
  * Initial release.
6
+
7
+ == Version 1.1.0
8
+
9
+ * Internal redesign.
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gem "selenium-client"
3
+ gem "selenium-webdriver"
4
+ gem "selenium"
4
5
 
5
6
  group :development do
6
7
  gem "gemspec_deps_gen"
@@ -12,6 +13,19 @@ group :test do
12
13
  gem "rspec-core"
13
14
  gem "rspec-expectations"
14
15
  gem "mocha"
16
+ gem "watir-webdriver"
17
+ #gem "capybara", "1.1.4"
18
+ #gem "capybara-webkit", "0.8.0"
19
+
20
+ # Note: You need to install qt:
21
+ # Mac: brew install qt
22
+ # Ubuntu: sudo apt-get install libqt4-dev libqtwebkit-dev
23
+ # Debian: sudo apt-get install libqt4-dev
24
+ # Fedora: yum install qt-webkit-devell
25
+
26
+ unless File.exist? "/usr/local/Cellar/qt"
27
+ system "brew install qt"
28
+ end
15
29
  end
16
30
 
17
31
  group :debug do
data/Gemfile.lock CHANGED
@@ -2,17 +2,23 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  archive-tar-minitar (0.5.2)
5
+ childprocess (0.3.8)
6
+ ffi (~> 1.0, >= 1.0.11)
5
7
  columnize (0.3.6)
6
8
  diff-lcs (1.1.3)
9
+ ffi (1.4.0)
7
10
  file_utils (1.0.6)
8
11
  gemcutter (0.7.1)
9
12
  gemspec_deps_gen (1.0.5)
10
13
  file_utils
14
+ jar_wrapper (0.1.7)
15
+ zip
11
16
  linecache19 (0.5.13)
12
17
  ruby_core_source (>= 0.1.4)
13
18
  metaclass (0.0.1)
14
19
  mocha (0.13.2)
15
20
  metaclass (~> 0.0.1)
21
+ multi_json (1.6.1)
16
22
  rake (10.0.3)
17
23
  rspec (2.12.0)
18
24
  rspec-core (~> 2.12.0)
@@ -31,7 +37,18 @@ GEM
31
37
  rake (>= 0.8.1)
32
38
  ruby_core_source (0.1.5)
33
39
  archive-tar-minitar (>= 0.5.2)
34
- selenium-client (1.2.18)
40
+ rubyzip (0.9.9)
41
+ selenium (0.2.9)
42
+ jar_wrapper
43
+ selenium-webdriver (2.30.0)
44
+ childprocess (>= 0.2.5)
45
+ multi_json (~> 1.0)
46
+ rubyzip
47
+ websocket (~> 1.0.4)
48
+ watir-webdriver (0.6.2)
49
+ selenium-webdriver (>= 2.18.0)
50
+ websocket (1.0.7)
51
+ zip (2.0.2)
35
52
 
36
53
  PLATFORMS
37
54
  ruby
@@ -46,4 +63,6 @@ DEPENDENCIES
46
63
  rspec-expectations
47
64
  ruby-debug-base19x (= 0.11.30.pre10)
48
65
  ruby-debug-ide (= 0.4.17.beta14)
49
- selenium-client
66
+ selenium
67
+ selenium-webdriver
68
+ watir-webdriver
data/lib/selenium_dsl.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems' unless Object.const_defined?(:Gem)
2
2
 
3
- require 'selenium_dsl/proxy'
4
- require 'selenium_dsl/script'
5
- require 'selenium_dsl/dsl'
6
- require 'selenium_dsl/version'
3
+ require 'selenium_dsl/version'
4
+ require 'selenium_dsl/selenium_client/dsl'
5
+ require 'selenium_dsl/selenium_webdriver/dsl'
6
+ require 'selenium_dsl/watir_webdriver/dsl'
7
+ #require 'selenium_dsl/capybara/dsl'
@@ -0,0 +1,68 @@
1
+ require 'capybara'
2
+ require 'capybara/dsl'
3
+ require 'capybara/webkit'
4
+ require 'selenium_dsl/proxy'
5
+ require 'selenium_dsl/selenium_helper'
6
+ require 'selenium_dsl/capybara/script'
7
+
8
+ module SeleniumDSL::Capybara
9
+ class DSL
10
+ include SeleniumHelper
11
+
12
+ attr_reader :script, :driver
13
+
14
+ attr_writer :timeout_in_seconds
15
+
16
+ def initialize(selenium_host, selenium_port, browser, webapp_url, requested_driver, capabilities={})
17
+ Capybara.run_server = false
18
+ Capybara.app_host = webapp_url
19
+
20
+ if requested_driver == :selenium
21
+ requested_driver = "selenium_#{browser}".to_sym
22
+
23
+ Capybara.register_driver requested_driver do |app|
24
+ client = Selenium::WebDriver::Remote::Http::Default.new
25
+ client.timeout = 120
26
+ #caps = Selenium::WebDriver::Remote::Capabilities.firefox
27
+
28
+ Capybara::Selenium::Driver.new(app, {:url => construct_selenium_url(selenium_host, selenium_port),
29
+ :browser => :remote, :desired_capabilities => browser.to_sym,
30
+ :http_client => client})
31
+ end
32
+ end
33
+
34
+ Capybara.javascript_driver = requested_driver.to_sym
35
+ Capybara.current_driver = requested_driver.to_sym
36
+
37
+ @session = Capybara::Session.new(requested_driver.to_sym, nil)
38
+
39
+ @script = SeleniumDSL::Capybara::Script.new @session
40
+ end
41
+
42
+ def timeout_in_seconds= timeout_in_seconds
43
+ Capybara.default_wait_time = timeout_in_seconds.to_i
44
+ end
45
+
46
+ def start
47
+ end
48
+
49
+ def stop
50
+ @session.reset!
51
+
52
+ Capybara.use_default_driver
53
+ Capybara.app_host = nil
54
+
55
+ #Capybara::Driver::Webkit::Browser
56
+
57
+ #@session.driver.browser.close
58
+ end
59
+
60
+ def capybara(&block)
61
+ @script.instance_eval(&block)
62
+
63
+ @script
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,19 @@
1
+ require 'capybara'
2
+ require 'selenium_dsl/proxy'
3
+
4
+ module SeleniumDSL::Capybara
5
+ class Script < SeleniumDSL::Proxy
6
+ attr_reader :driver
7
+
8
+ attr_accessor :timeout_in_seconds
9
+
10
+ def initialize driver
11
+ super driver, [:open, :select, :type]
12
+
13
+ @driver = driver
14
+
15
+ @timeout_in_seconds = 60
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,50 @@
1
+ require "selenium/client"
2
+ require 'selenium_dsl/proxy'
3
+ require 'selenium_dsl/selenium_helper'
4
+ require 'selenium_dsl/selenium_client/script'
5
+
6
+ module SeleniumDSL::SeleniumClient
7
+ class DSL
8
+ include SeleniumHelper
9
+
10
+ attr_reader :script, :driver
11
+
12
+ def initialize(selenium_host, selenium_port, browser, webapp_url, capabilities={})
13
+ @selenium = Selenium::Client::Driver.new \
14
+ :host => selenium_host,
15
+ :port => selenium_port.to_i,
16
+ :browser => "*webdriver",
17
+ :url => webapp_url
18
+
19
+ @driver = Selenium::WebDriver.for :remote,
20
+ :url => construct_selenium_url(selenium_host, selenium_port),
21
+ :desired_capabilities => browser.to_sym
22
+
23
+ @driver.capabilities.merge(capabilities) unless capabilities.empty?
24
+
25
+ @script = SeleniumDSL::SeleniumClient::Script.new @selenium, @driver
26
+ end
27
+
28
+ def timeout_in_seconds= timeout_in_seconds
29
+ @script.timeout_in_seconds = timeout_in_seconds
30
+ end
31
+
32
+ def start
33
+ #@selenium.start_new_browser_session
34
+ @selenium.start :driver => @driver
35
+ end
36
+
37
+ def stop
38
+ #@selenium.close_current_browser_session
39
+ @driver.quit
40
+ @selenium.stop
41
+ end
42
+
43
+ def selenium_client(&block)
44
+ @script.instance_eval(&block)
45
+
46
+ @script
47
+ end
48
+
49
+ end
50
+ end
@@ -1,35 +1,35 @@
1
1
  require 'selenium_dsl/proxy'
2
2
 
3
- module SeleniumDSL
4
- class Script < Proxy
3
+ module SeleniumDSL::SeleniumClient
4
+ class Script < SeleniumDSL::Proxy
5
+ attr_reader :selenium, :driver
5
6
 
6
- def initialize selenium_driver, timeout_in_seconds
7
- super selenium_driver, [:open, :select, :type]
7
+ attr_accessor :timeout_in_seconds
8
8
 
9
- @page = selenium_driver
10
- @timeout_in_seconds = timeout_in_seconds
11
- end
9
+ def initialize selenium, driver
10
+ super selenium, [:open, :select, :type]
12
11
 
13
- def timeout_in_seconds
14
- @timeout_in_seconds
12
+ @selenium = selenium
13
+ @driver = driver
14
+ @timeout_in_seconds = 60
15
15
  end
16
16
 
17
17
  def click locator, *params
18
- @page.click locator, *params
18
+ selenium.click locator, *params
19
19
 
20
20
  if params.size > 0
21
- @page.wait_for_condition "selenium.browserbot.getCurrentWindow().jQuery.active == 0" if params[0][:ajax] == true
21
+ selenium.wait_for_condition "selenium.browserbot.getCurrentWindow().jQuery.active == 0" if params[0][:ajax]
22
22
 
23
- @page.wait_for_page_to_load @timeout_in_seconds if params[0][:wait] == true
23
+ selenium.wait_for_page_to_load @timeout_in_seconds if params[0][:wait]
24
24
  end
25
25
  end
26
26
 
27
27
  # def select_value value, element, prefix
28
- # @page.select "#{prefix}_#{element}", "value=#{value}"
28
+ # selenium.select "#{prefix}_#{element}", "value=#{value}"
29
29
  # end
30
30
 
31
31
  def check_select value, element, prefix
32
- @page.click full_input_name(prefix, element)
32
+ selenium.click full_input_name(prefix, element)
33
33
  end
34
34
 
35
35
  def full_input_name(prefix, input_name)
@@ -37,23 +37,23 @@ module SeleniumDSL
37
37
  end
38
38
 
39
39
  def session_id
40
- /session_id=(\w+)/.match(@page.get_cookie)[1]
40
+ /session_id=(\w+)/.match(selenium.get_cookie)[1]
41
41
  end
42
42
 
43
43
  # def enter value, element, prefix
44
- # @page.type "#{prefix}_#{element}", value
44
+ # selenium.type "#{prefix}_#{element}", value
45
45
  # end
46
46
 
47
47
  def radio_select value, element, prefix
48
48
  if prefix.nil?
49
- @page.click "id=#{value}"
49
+ selenium.click "id=#{value}"
50
50
  else
51
- @page.click "#{prefix}_#{element}_#{value}"
51
+ selenium.click "#{prefix}_#{element}_#{value}"
52
52
  end
53
53
  end
54
54
 
55
55
  def go_back
56
- @page.go_back
56
+ selenium.go_back
57
57
  end
58
58
 
59
59
  # def new_session(path)
@@ -61,16 +61,16 @@ module SeleniumDSL
61
61
  # end
62
62
 
63
63
  # def goto path
64
- # @page.open path
64
+ # selenium.open path
65
65
  # end
66
66
 
67
67
  # def reset_session
68
- # @page.delete_cookie('_proteus_session', '/')
69
- # @page.delete_cookie('login', '/')
68
+ # selenium.delete_cookie('_proteus_session', '/')
69
+ # selenium.delete_cookie('login', '/')
70
70
  # end
71
71
 
72
72
  # def select_value value, element, prefix
73
- # @page.select "#{prefix}_#{element}", "value=#{value}"
73
+ # selenium.select "#{prefix}_#{element}", "value=#{value}"
74
74
  # end
75
75
 
76
76
  def wait_for_text value, element_id, timeout=10000
@@ -80,7 +80,7 @@ var included = false;
80
80
  if (element.value == '#{value}') included = true;
81
81
  included;
82
82
  EOF
83
- @page.wait_for_condition(script, timeout)
83
+ selenium.wait_for_condition(script, timeout)
84
84
  end
85
85
 
86
86
  def wait_for_option(value, element, prefix, timeout=30000)
@@ -100,11 +100,11 @@ if( option_list[x].value == '#{value}' ) included = true;
100
100
  included;
101
101
  EOF
102
102
 
103
- @page.wait_for_condition(script, timeout)
103
+ selenium.wait_for_condition(script, timeout)
104
104
  end
105
105
 
106
106
  def wait_until_enabled( element_id, timeout=10000)
107
- @page.wait_for_condition(
107
+ selenium.wait_for_condition(
108
108
  "selenium.browserbot.getCurrentWindow()." +
109
109
  "document.getElementById('#{element_id}').disabled == false;",
110
110
  timeout
@@ -112,7 +112,7 @@ included;
112
112
  end
113
113
 
114
114
  # def assert_title(expected_value)
115
- # assert_equal expected_value, @page.get_title, "Expected title to be: '#{expected_value}' but was '#{@page.get_title}'"
115
+ # assert_equal expected_value, selenium.get_title, "Expected title to be: '#{expected_value}' but was '#{selenium.get_title}'"
116
116
  # end
117
117
  #
118
118
  # def assert_contains text, message=nil
@@ -124,20 +124,20 @@ included;
124
124
  # end
125
125
  #
126
126
  # def assert_value(expected_value, element)
127
- # assert_equal expected_value, @page.get_value(element)
127
+ # assert_equal expected_value, selenium.get_value(element)
128
128
  # end
129
129
 
130
130
  def contains? text
131
- /#{text}/ =~ @page.get_html_source
131
+ /#{text}/ =~ selenium.get_html_source
132
132
  end
133
133
 
134
134
  # def assert_selected value, element, prefix
135
135
  # id = prefix.blank? ? "#{element}" : "#{prefix}[#{element}]"
136
- # assert_equal value, @page.get_selected_value("#{id}")
136
+ # assert_equal value, selenium.get_selected_value("#{id}")
137
137
  # end
138
138
 
139
139
  def match_element id
140
- Regexp.new("<([^>]*)(id *= *['\"]?#{id}['\"]?)([^>]*)>", Regexp::IGNORECASE).match(@page.get_html_source)
140
+ Regexp.new("<([^>]*)(id *= *['\"]?#{id}['\"]?)([^>]*)>", Regexp::IGNORECASE).match(selenium.get_html_source)
141
141
  end
142
142
 
143
143
  def visible? element
@@ -187,11 +187,11 @@ included;
187
187
  end
188
188
 
189
189
  def response_body
190
- @page.get_html_source
190
+ selenium.get_html_source
191
191
  end
192
192
 
193
193
  def text_for id
194
- @page.get_text(id)
194
+ selenium.get_text(id)
195
195
  end
196
196
 
197
197
  end
@@ -0,0 +1,5 @@
1
+ module SeleniumHelper
2
+ def construct_selenium_url host, port
3
+ "http://#{host}:#{port}/wd/hub/"
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'selenium/webdriver'
2
+ require 'selenium_dsl/proxy'
3
+ require 'selenium_dsl/selenium_helper'
4
+ require 'selenium_dsl/selenium_webdriver/script'
5
+
6
+ module SeleniumDSL::SeleniumWebdriver
7
+ class DSL
8
+ include SeleniumHelper
9
+
10
+ attr_reader :script, :driver
11
+
12
+ attr_writer :timeout_in_seconds
13
+
14
+ def initialize(selenium_host, selenium_port, browser, capabilities={})
15
+ @driver = Selenium::WebDriver.for(:remote, :url => construct_selenium_url(selenium_host, selenium_port),
16
+ :desired_capabilities => browser.to_sym)
17
+
18
+ @driver.capabilities.merge(capabilities) unless capabilities.empty?
19
+
20
+ @script = SeleniumDSL::SeleniumWebdriver::Script.new @driver
21
+ end
22
+
23
+ def timeout_in_seconds= timeout_in_seconds
24
+ #@driver.manage.timeouts.implicit_wait = timeout_in_seconds.to_i
25
+ @script.timeout_in_seconds = timeout_in_seconds.to_i
26
+ end
27
+
28
+ def start
29
+ end
30
+
31
+ def stop
32
+ @driver.quit
33
+ end
34
+
35
+ def selenium_webdriver(&block)
36
+ @script.instance_eval(&block)
37
+
38
+ @script
39
+ end
40
+ end
41
+
42
+ end