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/.idea/.rakeTasks +1 -1
- data/.idea/selenium_dsl.iml +8 -1
- data/.idea/vcs.xml +1 -0
- data/.idea/workspace.xml +997 -0
- data/CHANGES +4 -0
- data/Gemfile +15 -1
- data/Gemfile.lock +21 -2
- data/lib/selenium_dsl.rb +5 -4
- data/lib/selenium_dsl/capybara/dsl.rb +68 -0
- data/lib/selenium_dsl/capybara/script.rb +19 -0
- data/lib/selenium_dsl/selenium_client/dsl.rb +50 -0
- data/lib/selenium_dsl/{script.rb → selenium_client/script.rb} +33 -33
- data/lib/selenium_dsl/selenium_helper.rb +5 -0
- data/lib/selenium_dsl/selenium_webdriver/dsl.rb +42 -0
- data/lib/selenium_dsl/selenium_webdriver/script.rb +65 -0
- data/lib/selenium_dsl/version.rb +1 -1
- data/lib/selenium_dsl/watir_webdriver/dsl.rb +39 -0
- data/lib/selenium_dsl/watir_webdriver/script.rb +18 -0
- data/selenium_dsl.gemspec +2 -1
- data/spec/access_wikipedia_spec.rb +177 -30
- data/spec/spec_helper.rb +58 -7
- metadata +30 -6
- data/lib/selenium_dsl/dsl.rb +0 -31
data/CHANGES
CHANGED
data/Gemfile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
-
gem "selenium-
|
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
|
-
|
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
|
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/
|
4
|
-
require 'selenium_dsl/
|
5
|
-
require 'selenium_dsl/dsl'
|
6
|
-
require 'selenium_dsl/
|
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
|
-
|
7
|
-
super selenium_driver, [:open, :select, :type]
|
7
|
+
attr_accessor :timeout_in_seconds
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
9
|
+
def initialize selenium, driver
|
10
|
+
super selenium, [:open, :select, :type]
|
12
11
|
|
13
|
-
|
14
|
-
@
|
12
|
+
@selenium = selenium
|
13
|
+
@driver = driver
|
14
|
+
@timeout_in_seconds = 60
|
15
15
|
end
|
16
16
|
|
17
17
|
def click locator, *params
|
18
|
-
|
18
|
+
selenium.click locator, *params
|
19
19
|
|
20
20
|
if params.size > 0
|
21
|
-
|
21
|
+
selenium.wait_for_condition "selenium.browserbot.getCurrentWindow().jQuery.active == 0" if params[0][:ajax]
|
22
22
|
|
23
|
-
|
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
|
-
#
|
28
|
+
# selenium.select "#{prefix}_#{element}", "value=#{value}"
|
29
29
|
# end
|
30
30
|
|
31
31
|
def check_select value, element, prefix
|
32
|
-
|
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(
|
40
|
+
/session_id=(\w+)/.match(selenium.get_cookie)[1]
|
41
41
|
end
|
42
42
|
|
43
43
|
# def enter value, element, prefix
|
44
|
-
#
|
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
|
-
|
49
|
+
selenium.click "id=#{value}"
|
50
50
|
else
|
51
|
-
|
51
|
+
selenium.click "#{prefix}_#{element}_#{value}"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
def go_back
|
56
|
-
|
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
|
-
#
|
64
|
+
# selenium.open path
|
65
65
|
# end
|
66
66
|
|
67
67
|
# def reset_session
|
68
|
-
#
|
69
|
-
#
|
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
|
-
#
|
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
|
-
|
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
|
-
|
103
|
+
selenium.wait_for_condition(script, timeout)
|
104
104
|
end
|
105
105
|
|
106
106
|
def wait_until_enabled( element_id, timeout=10000)
|
107
|
-
|
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,
|
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,
|
127
|
+
# assert_equal expected_value, selenium.get_value(element)
|
128
128
|
# end
|
129
129
|
|
130
130
|
def contains? text
|
131
|
-
/#{text}/ =~
|
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,
|
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(
|
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
|
-
|
190
|
+
selenium.get_html_source
|
191
191
|
end
|
192
192
|
|
193
193
|
def text_for id
|
194
|
-
|
194
|
+
selenium.get_text(id)
|
195
195
|
end
|
196
196
|
|
197
197
|
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
|