davidtrogers-webrat 0.4.4.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -1
- data/Gemfile +19 -0
- data/History.txt +99 -9
- data/Rakefile +141 -207
- data/Thorfile +118 -0
- data/lib/webrat.rb +10 -23
- data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +6 -2
- data/lib/webrat/adapters/merb.rb +11 -0
- data/lib/webrat/adapters/rack.rb +25 -0
- data/lib/webrat/{rails.rb → adapters/rails.rb} +5 -37
- data/lib/webrat/adapters/sinatra.rb +9 -0
- data/lib/webrat/core.rb +0 -1
- data/lib/webrat/core/configuration.rb +22 -18
- data/lib/webrat/core/elements/area.rb +2 -2
- data/lib/webrat/core/elements/element.rb +3 -3
- data/lib/webrat/core/elements/field.rb +113 -31
- data/lib/webrat/core/elements/form.rb +4 -4
- data/lib/webrat/core/elements/label.rb +4 -4
- data/lib/webrat/core/elements/link.rb +8 -7
- data/lib/webrat/core/elements/select_option.rb +15 -2
- data/lib/webrat/core/locators.rb +1 -1
- data/lib/webrat/core/locators/area_locator.rb +3 -3
- data/lib/webrat/core/locators/button_locator.rb +6 -6
- data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
- data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
- data/lib/webrat/core/locators/field_named_locator.rb +3 -3
- data/lib/webrat/core/locators/form_locator.rb +1 -1
- data/lib/webrat/core/locators/label_locator.rb +2 -2
- data/lib/webrat/core/locators/link_locator.rb +16 -8
- data/lib/webrat/core/locators/select_option_locator.rb +5 -5
- data/lib/webrat/core/logging.rb +4 -5
- data/lib/webrat/core/matchers/have_content.rb +3 -8
- data/lib/webrat/core/matchers/have_xpath.rb +3 -28
- data/lib/webrat/core/methods.rb +5 -4
- data/lib/webrat/core/mime.rb +11 -22
- data/lib/webrat/core/save_and_open_page.rb +7 -29
- data/lib/webrat/core/scope.rb +17 -2
- data/lib/webrat/core/session.rb +31 -19
- data/lib/webrat/core/xml.rb +41 -84
- data/lib/webrat/integrations/merb.rb +10 -0
- data/lib/webrat/integrations/rails.rb +25 -0
- data/lib/webrat/integrations/rspec-rails.rb +11 -0
- data/lib/webrat/integrations/selenium.rb +11 -0
- data/lib/webrat/rspec-rails.rb +2 -13
- data/lib/webrat/selenium.rb +0 -11
- data/lib/webrat/selenium/application_server_factory.rb +40 -0
- data/lib/webrat/selenium/application_servers.rb +5 -0
- data/lib/webrat/selenium/application_servers/base.rb +46 -0
- data/lib/webrat/selenium/application_servers/external.rb +26 -0
- data/lib/webrat/selenium/application_servers/merb.rb +50 -0
- data/lib/webrat/selenium/application_servers/rails.rb +44 -0
- data/lib/webrat/selenium/application_servers/sinatra.rb +37 -0
- data/lib/webrat/selenium/location_strategy_javascript/label.js +30 -3
- data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
- data/lib/webrat/selenium/matchers/have_content.rb +22 -10
- data/lib/webrat/selenium/matchers/have_selector.rb +8 -0
- data/lib/webrat/selenium/matchers/have_xpath.rb +8 -0
- data/lib/webrat/selenium/selenium_rc_server.rb +8 -6
- data/lib/webrat/selenium/selenium_session.rb +43 -14
- data/lib/webrat/selenium/silence_stream.rb +2 -2
- data/spec/fakes/{test_session.rb → test_adapter.rb} +4 -5
- data/spec/integration/mechanize/Rakefile +7 -0
- data/spec/integration/mechanize/config.ru +2 -0
- data/spec/integration/mechanize/sample_app.rb +20 -0
- data/spec/integration/mechanize/spec/mechanize_spec.rb +22 -0
- data/spec/integration/mechanize/spec/spec_helper.rb +29 -0
- data/spec/integration/merb/app/controllers/testing.rb +9 -0
- data/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
- data/spec/integration/merb/config/router.rb +1 -0
- data/spec/integration/merb/spec/spec_helper.rb +2 -0
- data/spec/integration/merb/spec/webrat_spec.rb +7 -0
- data/spec/integration/rack/app.rb +89 -0
- data/spec/integration/rack/test/helper.rb +21 -0
- data/spec/integration/rack/test/webrat_rack_test.rb +57 -51
- data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
- data/spec/integration/rails/app/controllers/webrat_controller.rb +16 -9
- data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
- data/spec/integration/rails/app/views/links/show.html.erb +2 -1
- data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
- data/spec/integration/rails/config/environment.rb +1 -1
- data/spec/integration/rails/config/routes.rb +2 -0
- data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
- data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
- data/spec/integration/rails/test/integration/link_click_test.rb +8 -2
- data/spec/integration/rails/test/integration/webrat_test.rb +53 -5
- data/spec/integration/rails/test/test_helper.rb +7 -5
- data/spec/integration/sinatra/test/test_helper.rb +3 -2
- data/spec/private/core/configuration_spec.rb +8 -27
- data/spec/private/core/field_spec.rb +14 -16
- data/spec/private/core/link_spec.rb +1 -1
- data/spec/private/core/session_spec.rb +23 -26
- data/spec/private/mechanize/{mechanize_session_spec.rb → mechanize_adapter_spec.rb} +4 -12
- data/spec/private/nokogiri_spec.rb +2 -2
- data/spec/private/rails/{rails_session_spec.rb → rails_adapter_spec.rb} +11 -42
- data/spec/private/selenium/application_servers/rails_spec.rb +26 -0
- data/spec/public/basic_auth_spec.rb +13 -2
- data/spec/public/click_button_spec.rb +10 -12
- data/spec/public/click_link_spec.rb +21 -0
- data/spec/public/fill_in_spec.rb +15 -0
- data/spec/public/matchers/contain_spec.rb +12 -19
- data/spec/public/matchers/have_selector_spec.rb +6 -2
- data/spec/public/matchers/have_xpath_spec.rb +3 -3
- data/spec/public/save_and_open_spec.rb +15 -17
- data/spec/public/select_spec.rb +232 -26
- data/spec/public/selenium/application_server_factory_spec.rb +49 -0
- data/spec/public/selenium/application_servers/external_spec.rb +12 -0
- data/spec/public/selenium/selenium_session_spec.rb +37 -0
- data/spec/spec_helper.rb +5 -1
- data/vendor/selenium-server.jar +0 -0
- metadata +119 -69
- data/.dotest/0001 +0 -34
- data/.dotest/0002 +0 -34
- data/.dotest/binary +0 -1
- data/.dotest/final-commit +0 -1
- data/.dotest/head-name +0 -1
- data/.dotest/info +0 -5
- data/.dotest/keep +0 -1
- data/.dotest/last +0 -1
- data/.dotest/msg +0 -0
- data/.dotest/msg-clean +0 -0
- data/.dotest/next +0 -1
- data/.dotest/onto +0 -1
- data/.dotest/orig-head +0 -1
- data/.dotest/patch +0 -29
- data/.dotest/sign +0 -1
- data/.dotest/utf8 +0 -1
- data/.dotest/whitespace +0 -1
- data/VERSION +0 -1
- data/lib/webrat/core/xml/hpricot.rb +0 -19
- data/lib/webrat/core/xml/nokogiri.rb +0 -76
- data/lib/webrat/core/xml/rexml.rb +0 -24
- data/lib/webrat/merb_session.rb +0 -65
- data/lib/webrat/rack.rb +0 -24
- data/lib/webrat/rack_test.rb +0 -32
- data/lib/webrat/selenium/application_server.rb +0 -73
- data/lib/webrat/selenium/merb_application_server.rb +0 -48
- data/lib/webrat/selenium/rails_application_server.rb +0 -42
- data/lib/webrat/selenium/sinatra_application_server.rb +0 -35
- data/lib/webrat/sinatra.rb +0 -44
- data/spec/integration/rack/rack_app.rb +0 -16
- data/spec/integration/rack/test/test_helper.rb +0 -20
- data/spec/private/core/logging_spec.rb +0 -10
- data/spec/private/merb/merb_session_spec.rb +0 -42
@@ -0,0 +1,26 @@
|
|
1
|
+
require "webrat/selenium/application_servers/base"
|
2
|
+
|
3
|
+
module Webrat
|
4
|
+
module Selenium
|
5
|
+
module ApplicationServers
|
6
|
+
class External < Webrat::Selenium::ApplicationServers::Base
|
7
|
+
def start
|
8
|
+
warn "Webrat Ignoring Start Of Application Server Due to External Mode"
|
9
|
+
end
|
10
|
+
|
11
|
+
def stop
|
12
|
+
end
|
13
|
+
|
14
|
+
def fail
|
15
|
+
end
|
16
|
+
|
17
|
+
def pid_file
|
18
|
+
end
|
19
|
+
|
20
|
+
def wait
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "webrat/selenium/application_servers/base"
|
2
|
+
|
3
|
+
module Webrat
|
4
|
+
module Selenium
|
5
|
+
module ApplicationServers
|
6
|
+
class Merb < Webrat::Selenium::ApplicationServers::Base
|
7
|
+
|
8
|
+
def start
|
9
|
+
system start_command
|
10
|
+
end
|
11
|
+
|
12
|
+
def stop
|
13
|
+
silence_stream(STDOUT) do
|
14
|
+
pid = File.read(pid_file)
|
15
|
+
system("kill -9 #{pid}")
|
16
|
+
FileUtils.rm_f pid_file
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def fail
|
21
|
+
$stderr.puts
|
22
|
+
$stderr.puts
|
23
|
+
$stderr.puts "==> Failed to boot the Merb application server... exiting!"
|
24
|
+
$stderr.puts
|
25
|
+
$stderr.puts "Verify you can start a Merb server on port #{Webrat.configuration.application_port} with the following command:"
|
26
|
+
$stderr.puts
|
27
|
+
$stderr.puts " #{start_command}"
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
def pid_file
|
32
|
+
"log/merb.#{Webrat.configuration.application_port}.pid"
|
33
|
+
end
|
34
|
+
|
35
|
+
def start_command
|
36
|
+
"#{merb_command} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def merb_command
|
40
|
+
if File.exist?('bin/merb')
|
41
|
+
merb_cmd = 'bin/merb'
|
42
|
+
else
|
43
|
+
merb_cmd = 'merb'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "webrat/selenium/application_servers/base"
|
2
|
+
|
3
|
+
module Webrat
|
4
|
+
module Selenium
|
5
|
+
module ApplicationServers
|
6
|
+
class Rails < Webrat::Selenium::ApplicationServers::Base
|
7
|
+
|
8
|
+
def start
|
9
|
+
system start_command
|
10
|
+
end
|
11
|
+
|
12
|
+
def stop
|
13
|
+
silence_stream(STDOUT) do
|
14
|
+
system stop_command
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def fail
|
19
|
+
$stderr.puts
|
20
|
+
$stderr.puts
|
21
|
+
$stderr.puts "==> Failed to boot the Rails application server... exiting!"
|
22
|
+
$stderr.puts
|
23
|
+
$stderr.puts "Verify you can start a Rails server on port #{Webrat.configuration.application_port} with the following command:"
|
24
|
+
$stderr.puts
|
25
|
+
$stderr.puts " #{start_command}"
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
29
|
+
def pid_file
|
30
|
+
prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium_#{Webrat.configuration.application_port}.pid")
|
31
|
+
end
|
32
|
+
|
33
|
+
def start_command
|
34
|
+
"mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &"
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop_command
|
38
|
+
"mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "webrat/selenium/application_servers/base"
|
2
|
+
|
3
|
+
module Webrat
|
4
|
+
module Selenium
|
5
|
+
module ApplicationServers
|
6
|
+
class Sinatra < Webrat::Selenium::ApplicationServers::Base
|
7
|
+
|
8
|
+
def start
|
9
|
+
fork do
|
10
|
+
File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
|
11
|
+
exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def stop
|
16
|
+
silence_stream(STDOUT) do
|
17
|
+
pid = File.read(pid_file)
|
18
|
+
system("kill -9 #{pid}")
|
19
|
+
FileUtils.rm_f pid_file
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def fail
|
24
|
+
$stderr.puts
|
25
|
+
$stderr.puts
|
26
|
+
$stderr.puts "==> Failed to boot the Sinatra application server... exiting!"
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
def pid_file
|
31
|
+
prepare_pid_file(Dir.pwd, 'rack.pid')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,15 +1,42 @@
|
|
1
|
+
// Credit to: http://simonwillison.net/2006/Jan/20/escape/
|
2
|
+
RegExp.escape = function(text) {
|
3
|
+
if (!arguments.callee.sRE) {
|
4
|
+
var specials = [
|
5
|
+
'/', '.', '*', '+', '?', '|',
|
6
|
+
'(', ')', '[', ']', '{', '}', '\\'
|
7
|
+
];
|
8
|
+
arguments.callee.sRE = new RegExp(
|
9
|
+
'(\\' + specials.join('|\\') + ')', 'g'
|
10
|
+
);
|
11
|
+
}
|
12
|
+
return text.replace(arguments.callee.sRE, '\\$1');
|
13
|
+
}
|
14
|
+
|
1
15
|
var allLabels = inDocument.getElementsByTagName("label");
|
16
|
+
var regExp = new RegExp('^\\W*' + RegExp.escape(locator) + '(\\b|$)', 'i');
|
17
|
+
|
2
18
|
var candidateLabels = $A(allLabels).select(function(candidateLabel){
|
3
19
|
var labelText = getText(candidateLabel).strip();
|
4
|
-
return labelText.
|
20
|
+
return (labelText.search(regExp) >= 0);
|
5
21
|
});
|
22
|
+
|
6
23
|
if (candidateLabels.length == 0) {
|
7
24
|
return null;
|
8
25
|
}
|
9
|
-
|
26
|
+
|
27
|
+
//reverse length sort
|
28
|
+
candidateLabels = candidateLabels.sortBy(function(s) {
|
29
|
+
return s.length * -1;
|
30
|
+
});
|
31
|
+
|
10
32
|
var locatedLabel = candidateLabels.first();
|
11
33
|
var labelFor = locatedLabel.getAttribute('for');
|
34
|
+
|
12
35
|
if ((labelFor == null) && (locatedLabel.hasChildNodes())) {
|
13
|
-
return locatedLabel.
|
36
|
+
return locatedLabel.getElementsByTagName('button')[0]
|
37
|
+
|| locatedLabel.getElementsByTagName('input')[0]
|
38
|
+
|| locatedLabel.getElementsByTagName('textarea')[0]
|
39
|
+
|| locatedLabel.getElementsByTagName('select')[0];
|
14
40
|
}
|
41
|
+
|
15
42
|
return selenium.browserbot.locationStrategies['id'].call(this, labelFor, inDocument, inWindow);
|
@@ -1,4 +1,5 @@
|
|
1
1
|
var locationStrategies = selenium.browserbot.locationStrategies;
|
2
|
+
|
2
3
|
return locationStrategies['id'].call(this, locator, inDocument, inWindow)
|
3
4
|
|| locationStrategies['name'].call(this, locator, inDocument, inWindow)
|
4
5
|
|| locationStrategies['label'].call(this, locator, inDocument, inWindow)
|
@@ -1,12 +1,32 @@
|
|
1
1
|
var links = inDocument.getElementsByTagName('a');
|
2
|
+
|
2
3
|
var candidateLinks = $A(links).select(function(candidateLink) {
|
3
|
-
var textMatched =
|
4
|
-
var
|
5
|
-
var
|
4
|
+
var textMatched = false;
|
5
|
+
var titleMatched = false;
|
6
|
+
var idMatched = false;
|
7
|
+
|
8
|
+
if (getText(candidateLink).toLowerCase().indexOf(locator.toLowerCase()) != -1) {
|
9
|
+
textMatched = true;
|
10
|
+
}
|
11
|
+
|
12
|
+
if (candidateLink.title.toLowerCase().indexOf(locator.toLowerCase()) != -1) {
|
13
|
+
titleMatched = true;
|
14
|
+
}
|
15
|
+
|
16
|
+
if (candidateLink.id.toLowerCase().indexOf(locator.toLowerCase()) != -1) {
|
17
|
+
idMatched = true;
|
18
|
+
}
|
19
|
+
|
6
20
|
return textMatched || idMatched || titleMatched;
|
7
21
|
});
|
22
|
+
|
8
23
|
if (candidateLinks.length == 0) {
|
9
24
|
return null;
|
10
25
|
}
|
11
|
-
|
26
|
+
|
27
|
+
//reverse length sort
|
28
|
+
candidateLinks = candidateLinks.sortBy(function(s) {
|
29
|
+
return s.length * -1;
|
30
|
+
});
|
31
|
+
|
12
32
|
return candidateLinks.first();
|
@@ -7,29 +7,33 @@ module Webrat
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def matches?(response)
|
10
|
-
|
11
|
-
text_finder
|
12
|
-
else
|
13
|
-
text_finder = @content
|
10
|
+
response.session.wait_for do
|
11
|
+
response.selenium.is_text_present(text_finder)
|
14
12
|
end
|
13
|
+
rescue Webrat::TimeoutError => e
|
14
|
+
@error_message = e.message
|
15
|
+
false
|
16
|
+
end
|
15
17
|
|
18
|
+
def does_not_match?(response)
|
16
19
|
response.session.wait_for do
|
17
|
-
response.selenium.is_text_present(text_finder)
|
20
|
+
!response.selenium.is_text_present(text_finder)
|
18
21
|
end
|
19
|
-
|
20
|
-
|
22
|
+
rescue Webrat::TimeoutError => e
|
23
|
+
@error_message = e.message
|
24
|
+
false
|
21
25
|
end
|
22
26
|
|
23
27
|
# ==== Returns
|
24
28
|
# String:: The failure message.
|
25
29
|
def failure_message
|
26
|
-
"expected the
|
30
|
+
"expected the response to #{content_message}:\n#{@error_message}"
|
27
31
|
end
|
28
32
|
|
29
33
|
# ==== Returns
|
30
34
|
# String:: The failure message to be displayed in negative matches.
|
31
35
|
def negative_failure_message
|
32
|
-
"expected the
|
36
|
+
"expected the response to not #{content_message}"
|
33
37
|
end
|
34
38
|
|
35
39
|
def content_message
|
@@ -40,6 +44,14 @@ module Webrat
|
|
40
44
|
"match #{@content.inspect}"
|
41
45
|
end
|
42
46
|
end
|
47
|
+
|
48
|
+
def text_finder
|
49
|
+
if @content.is_a?(Regexp)
|
50
|
+
"regexp:#{@content.source}"
|
51
|
+
else
|
52
|
+
@content
|
53
|
+
end
|
54
|
+
end
|
43
55
|
end
|
44
56
|
|
45
57
|
# Matches the contents of an HTML document with
|
@@ -52,7 +64,7 @@ module Webrat
|
|
52
64
|
# the supplied string or regexp
|
53
65
|
def assert_contain(content)
|
54
66
|
hc = HasContent.new(content)
|
55
|
-
|
67
|
+
assert hc.matches?(response), hc.failure_message
|
56
68
|
end
|
57
69
|
|
58
70
|
# Asserts that the body of the response
|
@@ -14,6 +14,14 @@ module Webrat
|
|
14
14
|
false
|
15
15
|
end
|
16
16
|
|
17
|
+
def does_not_match?(response)
|
18
|
+
response.session.wait_for do
|
19
|
+
!response.selenium.is_element_present("css=#{@expected}")
|
20
|
+
end
|
21
|
+
rescue Webrat::TimeoutError
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
17
25
|
# ==== Returns
|
18
26
|
# String:: The failure message.
|
19
27
|
def failure_message
|
@@ -14,6 +14,14 @@ module Webrat
|
|
14
14
|
false
|
15
15
|
end
|
16
16
|
|
17
|
+
def does_not_match?(response)
|
18
|
+
response.session.wait_for do
|
19
|
+
!response.selenium.is_element_present("xpath=#{@expected}")
|
20
|
+
end
|
21
|
+
rescue Webrat::TimeoutError
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
17
25
|
# ==== Returns
|
18
26
|
# String:: The failure message.
|
19
27
|
def failure_message
|
@@ -2,7 +2,7 @@ module Webrat
|
|
2
2
|
module Selenium
|
3
3
|
|
4
4
|
class SeleniumRCServer
|
5
|
-
|
5
|
+
|
6
6
|
include Webrat::Selenium::SilenceStream
|
7
7
|
|
8
8
|
def self.boot
|
@@ -32,9 +32,9 @@ module Webrat
|
|
32
32
|
def remote_control
|
33
33
|
return @remote_control if @remote_control
|
34
34
|
|
35
|
-
@remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0",
|
36
|
-
Webrat.configuration.selenium_server_port,
|
37
|
-
Webrat.configuration.selenium_browser_startup_timeout)
|
35
|
+
@remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0",
|
36
|
+
Webrat.configuration.selenium_server_port,
|
37
|
+
:timeout => Webrat.configuration.selenium_browser_startup_timeout)
|
38
38
|
@remote_control.jar_file = jar_path
|
39
39
|
|
40
40
|
return @remote_control
|
@@ -61,7 +61,7 @@ module Webrat
|
|
61
61
|
TCPSocket.wait_for_service_with_timeout \
|
62
62
|
:host => (Webrat.configuration.selenium_server_address || "0.0.0.0"),
|
63
63
|
:port => Webrat.configuration.selenium_server_port,
|
64
|
-
:timeout =>
|
64
|
+
:timeout => 45 # seconds
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -74,7 +74,9 @@ module Webrat
|
|
74
74
|
|
75
75
|
def stop
|
76
76
|
silence_stream(STDOUT) do
|
77
|
-
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0",
|
77
|
+
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0",
|
78
|
+
Webrat.configuration.selenium_server_port,
|
79
|
+
:timeout => 5).stop
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require "webrat/core/save_and_open_page"
|
2
2
|
require "webrat/selenium/selenium_rc_server"
|
3
|
-
require "webrat/selenium/
|
3
|
+
require "webrat/selenium/application_server_factory"
|
4
|
+
require "webrat/selenium/application_servers/base"
|
5
|
+
|
6
|
+
require "selenium"
|
4
7
|
|
5
8
|
module Webrat
|
6
9
|
class TimeoutError < WebratError
|
@@ -60,16 +63,15 @@ module Webrat
|
|
60
63
|
selenium.location
|
61
64
|
end
|
62
65
|
|
63
|
-
# modified function to recognize input type=button
|
64
66
|
def click_button(button_text_or_regexp = nil, options = {})
|
65
|
-
puts options
|
66
67
|
if button_text_or_regexp.is_a?(Hash) && options == {}
|
67
68
|
pattern, options = nil, button_text_or_regexp
|
68
69
|
elsif button_text_or_regexp
|
69
70
|
pattern = adjust_if_regexp(button_text_or_regexp)
|
70
71
|
end
|
71
72
|
pattern ||= '*'
|
72
|
-
locator = "
|
73
|
+
locator = "button=#{pattern}"
|
74
|
+
|
73
75
|
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
74
76
|
selenium.click locator
|
75
77
|
end
|
@@ -77,7 +79,12 @@ module Webrat
|
|
77
79
|
webrat_deprecate :clicks_button, :click_button
|
78
80
|
|
79
81
|
def click_link(link_text_or_regexp, options = {})
|
80
|
-
|
82
|
+
if link_text_or_regexp.is_a?(Regexp)
|
83
|
+
pattern = "evalregex:#{link_text_or_regexp.inspect}"
|
84
|
+
else
|
85
|
+
pattern = link_text_or_regexp.to_s
|
86
|
+
end
|
87
|
+
|
81
88
|
locator = "webratlink=#{pattern}"
|
82
89
|
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
83
90
|
selenium.click locator
|
@@ -151,8 +158,10 @@ module Webrat
|
|
151
158
|
|
152
159
|
begin
|
153
160
|
value = yield
|
154
|
-
rescue
|
155
|
-
|
161
|
+
rescue Exception => e
|
162
|
+
unless is_ignorable_wait_for_exception?(e)
|
163
|
+
raise e
|
164
|
+
end
|
156
165
|
end
|
157
166
|
|
158
167
|
return value if value
|
@@ -160,7 +169,19 @@ module Webrat
|
|
160
169
|
sleep 0.25
|
161
170
|
end
|
162
171
|
|
163
|
-
|
172
|
+
error_message = "#{message} (after #{timeout} sec)"
|
173
|
+
|
174
|
+
if $browser
|
175
|
+
error_message += <<-EOS
|
176
|
+
|
177
|
+
|
178
|
+
HTML of the page was:
|
179
|
+
|
180
|
+
#{selenium.get_html_source}"
|
181
|
+
EOS
|
182
|
+
end
|
183
|
+
|
184
|
+
raise Webrat::TimeoutError.new(error_message)
|
164
185
|
true
|
165
186
|
end
|
166
187
|
|
@@ -174,23 +195,31 @@ module Webrat
|
|
174
195
|
|
175
196
|
|
176
197
|
def save_and_open_screengrab
|
177
|
-
return unless File.exist?(
|
198
|
+
return unless File.exist?(Webrat.configuration.saved_pages_dir)
|
178
199
|
|
179
|
-
filename = "#{
|
200
|
+
filename = "#{Webrat.configuration.saved_pages_dir}/webrat-#{Time.now.to_i}.png"
|
180
201
|
|
181
202
|
if $browser.chrome_backend?
|
182
203
|
$browser.capture_entire_page_screenshot(filename, '')
|
183
204
|
else
|
184
205
|
$browser.capture_screenshot(filename)
|
185
206
|
end
|
186
|
-
|
207
|
+
open_in_browser(filename)
|
208
|
+
|
187
209
|
end
|
188
210
|
|
189
|
-
|
211
|
+
protected
|
212
|
+
def is_ignorable_wait_for_exception?(exception) #:nodoc:
|
213
|
+
if defined?(::Spec::Expectations::ExpectationNotMetError)
|
214
|
+
return true if exception.class == ::Spec::Expectations::ExpectationNotMetError
|
215
|
+
end
|
216
|
+
return true if [::Selenium::CommandError, Webrat::WebratError].include?(exception.class)
|
217
|
+
return false
|
218
|
+
end
|
190
219
|
|
191
220
|
def setup #:nodoc:
|
192
221
|
Webrat::Selenium::SeleniumRCServer.boot
|
193
|
-
Webrat::Selenium::
|
222
|
+
Webrat::Selenium::ApplicationServerFactory.app_server_instance.boot
|
194
223
|
|
195
224
|
create_browser
|
196
225
|
$browser.start
|
@@ -203,7 +232,7 @@ module Webrat
|
|
203
232
|
|
204
233
|
def create_browser
|
205
234
|
$browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
|
206
|
-
|
235
|
+
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port_for_selenium}")
|
207
236
|
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address
|
208
237
|
|
209
238
|
at_exit do
|