selenium-selenese 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/README.markdown +308 -0
  2. data/examples/script/google.rb +15 -0
  3. data/lib/nautilus/shell.rb +32 -0
  4. data/lib/selenium.rb +14 -0
  5. data/lib/selenium/client/base.rb +140 -0
  6. data/lib/selenium/client/driver.rb +11 -0
  7. data/lib/selenium/client/extensions.rb +118 -0
  8. data/lib/selenium/client/idiomatic.rb +488 -0
  9. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  10. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  11. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  12. data/lib/selenium/client/legacy_driver.rb +1711 -0
  13. data/lib/selenium/client/protocol.rb +131 -0
  14. data/lib/selenium/client/selenium_helper.rb +36 -0
  15. data/lib/selenium/command_error.rb +4 -0
  16. data/lib/selenium/protocol_error.rb +4 -0
  17. data/lib/selenium/rake/default_tasks.rb +16 -0
  18. data/lib/selenium/rake/remote_control_start_task.rb +71 -0
  19. data/lib/selenium/rake/remote_control_stop_task.rb +44 -0
  20. data/lib/selenium/rake/tasks.rb +6 -0
  21. data/lib/selenium/remote_control/remote_control.rb +35 -0
  22. data/lib/selenium/rspec/reporting/file_path_strategy.rb +78 -0
  23. data/lib/selenium/rspec/reporting/html_report.rb +123 -0
  24. data/lib/selenium/rspec/reporting/selenium_test_report_formatter.rb +87 -0
  25. data/lib/selenium/rspec/reporting/system_capture.rb +72 -0
  26. data/lib/selenium/rspec/rspec_extensions.rb +96 -0
  27. data/lib/selenium/rspec/spec_helper.rb +34 -0
  28. data/lib/selenium/selenese.rb +24 -0
  29. data/lib/tcp_socket_extension.rb +32 -0
  30. data/vendor/selenium-server.jar +0 -0
  31. metadata +101 -0
@@ -0,0 +1,87 @@
1
+ #
2
+ # Explicit requires in this file so that we can invoke RSpec runner with a
3
+ # single:
4
+ # --require 'lib/selenium/rspec/reporting/selenium_test_report_formatter'
5
+ #
6
+ require "digest/md5"
7
+ require "base64"
8
+ require 'tmpdir'
9
+ require "rubygems"
10
+ gem "rspec", ">=1.2.8"
11
+ require "spec"
12
+ require 'spec/runner/formatter/html_formatter'
13
+ require File.expand_path(File.dirname(__FILE__) + "/file_path_strategy")
14
+ require File.expand_path(File.dirname(__FILE__) + "/system_capture")
15
+ require File.expand_path(File.dirname(__FILE__) + "/html_report")
16
+
17
+ module Selenium
18
+ module RSpec
19
+
20
+ class SeleniumTestReportFormatter < Spec::Runner::Formatter::HtmlFormatter
21
+
22
+ def initialize(options, output)
23
+ super
24
+ raise "Unexpected output type #{output.inspect}" unless output.kind_of?(String)
25
+ @@file_path_strategy = Selenium::RSpec::Reporting::FilePathStrategy.new(output)
26
+ end
27
+
28
+ def start(example_count)
29
+ super
30
+ # ensure there's at least 1 example group header (normally 0 with deep_test)
31
+ # prevents js and html validity errors
32
+ example_group = Object.new
33
+ def example_group.description; ""; end
34
+ example_group_started example_group
35
+ end
36
+
37
+ def move_progress
38
+ # we don't have current_example_number, and we don't really care about the progress bar
39
+ end
40
+
41
+ def extra_failure_content(failure)
42
+ Selenium::RSpec::Reporting::HtmlReport.inject_placeholder(super)
43
+ end
44
+
45
+ def example_pending(example_proxy, message, deprecated_pending_location=nil)
46
+ super
47
+ end
48
+
49
+ def example_failed(example, counter, failure)
50
+ old_output = @output
51
+ @output = StringIO.new
52
+ super
53
+
54
+ result = @output.string
55
+ report = Selenium::RSpec::Reporting::HtmlReport.new(@@file_path_strategy)
56
+ report.replace_placeholder_with_system_state_content(result, example)
57
+ old_output.puts result
58
+ old_output.flush
59
+ ensure
60
+ @output = old_output
61
+ end
62
+
63
+ # Should be called from config.after(:each) in spec helper
64
+ def self.capture_system_state(selenium_driver, example)
65
+ system_capture = Selenium::RSpec::Reporting::SystemCapture.new(selenium_driver, example, file_path_strategy)
66
+ system_capture.capture_system_state
67
+ end
68
+
69
+ def global_scripts
70
+ Selenium::RSpec::Reporting::HtmlReport.append_javascript(super)
71
+ end
72
+
73
+ def global_styles
74
+ Selenium::RSpec::Reporting::HtmlReport.append_css(super)
75
+ end
76
+
77
+ def self.file_path_strategy
78
+ ### HACK ####
79
+ # When running with DeepTest the class instance variable could not have been set
80
+ # For now you must set the env variable before launching the tests. We need to revisit the way DeepTest
81
+ # and RSpec reporting work for a proper fix.
82
+ @@file_path_strategy ||= Selenium::RSpec::Reporting::FilePathStrategy.new(ENV["SELENIUM_TEST_REPORT_FILE"])
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,72 @@
1
+ module Selenium
2
+ module RSpec
3
+ module Reporting
4
+
5
+ class SystemCapture
6
+
7
+ def initialize(selenium_driver, example, file_path_strategy)
8
+ @selenium_driver = selenium_driver
9
+ @example = example
10
+ @file_path_strategy = file_path_strategy
11
+ end
12
+
13
+ def capture_system_state
14
+ # Selenium RC seems to 'freeze' every so often when calling
15
+ # getHTMLSource, especially when DeepTest timeout is low, I need to investigate...
16
+ # Set deeptest :timeout_in_seconds => 30 to see it happen
17
+ begin
18
+ retrieve_remote_control_logs
19
+ rescue Exception => e
20
+ STDERR.puts "WARNING: Could not retrieve remote control logs: #{e}"
21
+ end
22
+ begin
23
+ capture_html_snapshot
24
+ rescue Exception => e
25
+ STDERR.puts "WARNING: Could not capture HTML snapshot: #{e}"
26
+ end
27
+ begin
28
+ capture_page_screenshot
29
+ rescue Exception => e
30
+ STDERR.puts "WARNING: Could not capture page screenshot: #{e}"
31
+ end
32
+ begin
33
+ capture_system_screenshot
34
+ rescue Exception => e
35
+ STDERR.puts "WARNING: Could not capture system screenshot: #{e}"
36
+ end
37
+ end
38
+
39
+ def capture_html_snapshot
40
+ # Skipping HTML Snapshot retrieval, if there is no current Selenium session
41
+ return unless @selenium_driver.session_started?
42
+
43
+ html = @selenium_driver.get_html_source
44
+ File.open(@file_path_strategy.file_path_for_html_capture(@example), "w") { |f| f.write html }
45
+ end
46
+
47
+ def capture_system_screenshot
48
+ @selenium_driver.window_maximize if @selenium_driver.session_started?
49
+
50
+ encodedImage = @selenium_driver.capture_screenshot_to_string
51
+ pngImage = Base64.decode64(encodedImage)
52
+ File.open(@file_path_strategy.file_path_for_system_screenshot(@example), "wb") { |f| f.write pngImage }
53
+ end
54
+
55
+ def capture_page_screenshot
56
+ return unless @selenium_driver.chrome_backend? && @selenium_driver.session_started?
57
+
58
+ encodedImage = @selenium_driver.capture_entire_page_screenshot_to_string("")
59
+ pngImage = Base64.decode64(encodedImage)
60
+ File.open(@file_path_strategy.file_path_for_page_screenshot(@example), "wb") { |f| f.write pngImage }
61
+ end
62
+
63
+ def retrieve_remote_control_logs
64
+ logs = @selenium_driver.retrieve_last_remote_control_logs
65
+ File.open(@file_path_strategy.file_path_for_remote_control_logs(@example), "w") { |f| f.write logs }
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,96 @@
1
+ require "rubygems"
2
+ gem "rspec", ">=1.2.8"
3
+ require 'spec'
4
+ require 'spec/example/example_group'
5
+
6
+ #
7
+ # Monkey-patch RSpec Example Group so that we can track whether an
8
+ # example already failed or not in an after(:each) block
9
+ #
10
+ # Useful to only capture Selenium screenshots when a test fails
11
+ #
12
+ # * Changed execution_error to be an instance variable (in lieu of
13
+ # a local variable).
14
+ #
15
+ # * Introduced an unique id (example_uid) that is the same for
16
+ # a real Example (passed in after(:each) when screenshot is
17
+ # taken) as well as the corresponding ExampleProxy
18
+ # (passed to the HTML formatter). This unique id gives us
19
+ # a way to correlate file names between generation and
20
+ # reporting time.
21
+ #
22
+ module Spec
23
+ module Example
24
+ module ExampleMethods
25
+
26
+ attr_reader :execution_error
27
+
28
+ remove_method :execute
29
+ def execute(run_options, instance_variables) # :nodoc:
30
+ @_proxy.options[:actual_example] = self
31
+
32
+ run_options.reporter.example_started(@_proxy)
33
+ set_instance_variables_from_hash(instance_variables)
34
+
35
+ @execution_error = nil
36
+ Timeout.timeout(run_options.timeout) do
37
+ begin
38
+ before_each_example
39
+ instance_eval(&@_implementation)
40
+ rescue Exception => e
41
+ @execution_error ||= e
42
+ end
43
+ begin
44
+ after_each_example
45
+ rescue Exception => e
46
+ @execution_error ||= e
47
+ end
48
+ end
49
+
50
+ run_options.reporter.example_finished(@_proxy.update(description), @execution_error)
51
+ success = @execution_error.nil? || ExamplePendingError === @execution_error
52
+ end
53
+
54
+ def actual_failure?
55
+ case execution_error
56
+ when nil
57
+ false
58
+ when Spec::Example::ExamplePendingError,
59
+ Spec::Example::PendingExampleFixedError,
60
+ Spec::Example::NoDescriptionError
61
+ false
62
+ else
63
+ true
64
+ end
65
+ end
66
+
67
+ def reporting_uid
68
+ # backtrace is not reliable anymore using the implementation proc
69
+ Digest::MD5.hexdigest @_implementation.inspect
70
+ end
71
+
72
+ def pending_for_browsers(*browser_regexps, &block)
73
+ actual_browser = selenium_driver.browser_string
74
+ match_browser_regexps = browser_regexps.inject(false) do |match, regexp|
75
+ match ||= actual_browser =~ Regexp.new(regexp.source, Regexp::IGNORECASE)
76
+ end
77
+ if match_browser_regexps
78
+ pending "#{actual_browser.gsub(/\*/, '').capitalize} does not support this feature yet"
79
+ else
80
+ yield
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ class ExampleProxy
87
+
88
+ def reporting_uid
89
+ options[:actual_example].reporting_uid
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+ end
96
+
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'base64'
4
+ require 'fileutils'
5
+ require File.expand_path(File.dirname(__FILE__) + "/rspec_extensions")
6
+ require File.expand_path(File.dirname(__FILE__) + "/reporting/selenium_test_report_formatter")
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ config.prepend_after(:each) do
11
+ begin
12
+ if actual_failure?
13
+ Selenium::RSpec::SeleniumTestReportFormatter.capture_system_state(selenium_driver, self)
14
+ end
15
+ if selenium_driver.session_started?
16
+ selenium_driver.set_context "Ending example '#{self.description}'"
17
+ end
18
+ rescue Exception => e
19
+ STDERR.puts "Problem while capturing system state" + e
20
+ end
21
+ end
22
+
23
+ config.append_before(:each) do
24
+ begin
25
+ if selenium_driver && selenium_driver.session_started?
26
+ selenium_driver.set_context "Starting example '#{self.description}'"
27
+ end
28
+ rescue Exception => e
29
+ STDERR.puts "Problem while setting context on example start" + e
30
+ end
31
+ end
32
+
33
+ end
34
+
@@ -0,0 +1,24 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'cgi'
4
+ require "digest/md5"
5
+ require 'fileutils'
6
+ require 'tmpdir'
7
+ require File.expand_path(File.dirname(__FILE__) + '/../tcp_socket_extension')
8
+ require File.expand_path(File.dirname(__FILE__) + '/../nautilus/shell')
9
+ require File.expand_path(File.dirname(__FILE__) + '/command_error')
10
+ require File.expand_path(File.dirname(__FILE__) + '/protocol_error')
11
+ require File.expand_path(File.dirname(__FILE__) + '/client/protocol')
12
+ require File.expand_path(File.dirname(__FILE__) + '/client/legacy_driver')
13
+ require File.expand_path(File.dirname(__FILE__) + '/client/javascript_expression_builder')
14
+ require File.expand_path(File.dirname(__FILE__) + '/client/javascript_frameworks/prototype')
15
+ require File.expand_path(File.dirname(__FILE__) + '/client/javascript_frameworks/jquery')
16
+ require File.expand_path(File.dirname(__FILE__) + '/client/extensions')
17
+ require File.expand_path(File.dirname(__FILE__) + '/client/idiomatic')
18
+ require File.expand_path(File.dirname(__FILE__) + '/client/base')
19
+ require File.expand_path(File.dirname(__FILE__) + '/client/driver')
20
+ require File.expand_path(File.dirname(__FILE__) + '/client/selenium_helper')
21
+ require File.expand_path(File.dirname(__FILE__) + '/remote_control/remote_control')
22
+ require File.expand_path(File.dirname(__FILE__) + '/rake/remote_control_start_task')
23
+ require File.expand_path(File.dirname(__FILE__) + '/rake/remote_control_stop_task')
24
+
@@ -0,0 +1,32 @@
1
+ require 'timeout'
2
+ require 'socket'
3
+
4
+ class TCPSocket
5
+
6
+ def self.wait_for_service(options)
7
+ verbose_wait until listening_service?(options)
8
+ end
9
+
10
+ def self.wait_for_service_termination(options)
11
+ verbose_wait while listening_service?(options)
12
+ end
13
+
14
+ def self.listening_service?(options)
15
+ Timeout::timeout(options[:timeout] || 20) do
16
+ begin
17
+ socket = TCPSocket.new(options[:host], options[:port])
18
+ socket.close unless socket.nil?
19
+ true
20
+ rescue Errno::ECONNREFUSED,
21
+ Errno::EBADF # Windows
22
+ false
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.verbose_wait
28
+ puts ".\n"
29
+ sleep 2
30
+ end
31
+
32
+ end
Binary file
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium-selenese
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 3
10
+ version: 1.1.3
11
+ platform: ruby
12
+ authors:
13
+ - Technologies
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-01 00:00:00 +05:30
19
+ default_executable: selenium-rc
20
+ dependencies: []
21
+
22
+ description: The Selenium Server and Selenium client are merged into single gem. This gem gives you the option to convert the selenium commands into selense script.
23
+ email: dharsininitt@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.markdown
30
+ files:
31
+ - lib/nautilus/shell.rb
32
+ - lib/selenium/client/base.rb
33
+ - lib/selenium/client/driver.rb
34
+ - lib/selenium/client/extensions.rb
35
+ - lib/selenium/client/idiomatic.rb
36
+ - lib/selenium/client/javascript_expression_builder.rb
37
+ - lib/selenium/client/javascript_frameworks/jquery.rb
38
+ - lib/selenium/client/javascript_frameworks/prototype.rb
39
+ - lib/selenium/client/legacy_driver.rb
40
+ - lib/selenium/client/protocol.rb
41
+ - lib/selenium/client/selenium_helper.rb
42
+ - lib/selenium/selenese.rb
43
+ - lib/selenium/command_error.rb
44
+ - lib/selenium/protocol_error.rb
45
+ - lib/selenium/rake/default_tasks.rb
46
+ - lib/selenium/rake/remote_control_start_task.rb
47
+ - lib/selenium/rake/remote_control_stop_task.rb
48
+ - lib/selenium/rake/tasks.rb
49
+ - lib/selenium/remote_control/remote_control.rb
50
+ - lib/selenium/rspec/reporting/file_path_strategy.rb
51
+ - lib/selenium/rspec/reporting/html_report.rb
52
+ - lib/selenium/rspec/reporting/selenium_test_report_formatter.rb
53
+ - lib/selenium/rspec/reporting/system_capture.rb
54
+ - lib/selenium/rspec/rspec_extensions.rb
55
+ - lib/selenium/rspec/spec_helper.rb
56
+ - lib/selenium.rb
57
+ - lib/tcp_socket_extension.rb
58
+ - examples/script/google.rb
59
+ - vendor/selenium-server.jar
60
+ - README.markdown
61
+ has_rdoc: true
62
+ homepage: http://github.com/pivotal/selenium-rc
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --charset=UTF-8
68
+ - --title
69
+ - Selenium Selenese
70
+ - --main
71
+ - README
72
+ - --line-numbers
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.7
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: The Selenium Server and Selenium client are merged into single gem. This gem gives you the option to convert the selenium commands into selense script.
100
+ test_files: []
101
+