testingbot 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ require 'rspec'
2
+ require 'capybara/rspec'
3
+ require 'selenium/webdriver'
4
+ require 'testingbot'
5
+
6
+ RSpec.configure do |config|
7
+ caps = Selenium::WebDriver::Remote::Capabilities.firefox
8
+ caps.version = "8"
9
+ caps.platform = :WINDOWS
10
+
11
+ Capybara.default_driver = :testingbot
12
+ Capybara.register_driver :testingbot do |app|
13
+ client = Selenium::WebDriver::Remote::Http::Default.new
14
+ client.timeout = 120
15
+ Capybara::Selenium::Driver.new(app,
16
+ :browser => :remote,
17
+ :url => "http://key:secret@hub.testingbot.com:4444/wd/hub",
18
+ :http_client => client,
19
+ :desired_capabilities => caps)
20
+ end
21
+ end
22
+
23
+ describe "People", :type => :request do
24
+ before :all do
25
+ Capybara.app_host = "http://testingbot.com"
26
+ end
27
+
28
+ it 'has a homepage with the word Selenium' do
29
+ visit '/'
30
+ page.should have_content('Selenium')
31
+ end
32
+ end
@@ -1,36 +1,39 @@
1
1
  require 'rubygems'
2
- gem "rspec", ">=1.2.8"
3
- gem "selenium-client", ">=1.2.18"
4
2
  require "selenium/client"
5
- require "selenium/rspec/spec_helper"
6
- gem "testingbot"
7
- require "testingbot"
3
+ require 'rspec'
4
+ require 'testingbot'
5
+ #require 'testingbot/tunnel'
8
6
 
9
- describe "People" do
7
+ # rspec 2
8
+ describe "People", :type => :selenium do
10
9
  attr_reader :selenium_driver
11
- alias :page :selenium_driver
12
-
13
- before(:all) do
10
+ before(:all) do
11
+ #TestingBot::Tunnel.start_tunnel("selenium@tunnel.testingbot.com", 2052)
12
+
14
13
  @selenium_driver = Selenium::Client::Driver.new \
15
- :host => "http://hub.testingbot.com",
14
+ :host => "hub.testingbot.com",
16
15
  :port => 4444,
17
16
  :browser => "firefox",
18
17
  :url => "http://www.google.com",
19
18
  :timeout_in_second => 60,
20
19
  :platform => "WINDOWS",
21
- :version => "6"
20
+ :version => "10"
22
21
  end
23
-
22
+
24
23
  before(:each) do
25
- selenium_driver.start_new_browser_session
24
+ @selenium_driver.start_new_browser_session
26
25
  end
27
-
28
- append_after(:each) do
26
+
27
+ after(:each) do
29
28
  @selenium_driver.close_current_browser_session
30
29
  end
31
-
30
+
32
31
  it "can find the right title" do
33
- page.open "/"
34
- page.title.should eql("Google")
32
+ @selenium_driver.open "/"
33
+ @selenium_driver.title.should eql("Google")
35
34
  end
36
- end
35
+
36
+ # after(:all) do
37
+ # TestingBot::Tunnel.stop_tunnel
38
+ # end
39
+ end
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ gem "rspec", "<2"
3
+ gem "selenium-client"
4
+ require "selenium/client"
5
+ require "selenium/rspec/spec_helper"
6
+ gem "testingbot"
7
+ require "testingbot"
8
+
9
+ describe "People" do
10
+ attr_reader :selenium_driver
11
+ alias :page :selenium_driver
12
+
13
+ before(:all) do
14
+ @selenium_driver = Selenium::Client::Driver.new \
15
+ :host => "hub.testingbot.com",
16
+ :port => 4444,
17
+ :browser => "firefox",
18
+ :url => "http://www.google.com",
19
+ :timeout_in_second => 60,
20
+ :platform => "WINDOWS",
21
+ :version => "10"
22
+ end
23
+
24
+ before(:each) do
25
+ selenium_driver.start_new_browser_session
26
+ end
27
+
28
+ append_after(:each) do
29
+ @selenium_driver.close_current_browser_session
30
+ end
31
+
32
+ it "can find the right title" do
33
+ page.open "/"
34
+ page.title.should eql("Google")
35
+ end
36
+ end
@@ -12,7 +12,7 @@ class ExampleTest < TestingBot::TestCase
12
12
 
13
13
  def setup
14
14
  @browser = Selenium::Client::Driver.new \
15
- :host => "hub.testingbot.com",
15
+ :host => "hub.testingbot.com",
16
16
  :port => 4444,
17
17
  :browser => "iexplore",
18
18
  :platform => "WINDOWS",
@@ -20,9 +20,6 @@ class ExampleTest < TestingBot::TestCase
20
20
  :url => "http://www.google.com",
21
21
  :timeout_in_second => 60
22
22
 
23
- browser.options = {
24
- }
25
-
26
23
  browser.extra = "First test" # some custom data you can pass with your tests
27
24
 
28
25
  browser.start_new_browser_session
@@ -33,11 +30,7 @@ class ExampleTest < TestingBot::TestCase
33
30
  end
34
31
 
35
32
  def test_page_search
36
- # browser.window_maximize
37
33
  browser.open "/"
38
- #browser.type "q", "selenium rc"
39
- #browser.click "btnG"
40
- #sleep 150
41
34
  assert_equal "Google", browser.title
42
35
  end
43
- end
36
+ end
@@ -1,122 +1,200 @@
1
1
  require "testingbot/version"
2
2
 
3
- module Selenium
4
- module Client
5
- module Protocol
6
- attr_writer :client_key, :client_secret
7
-
8
- def client_key
9
- if @client_key.nil?
10
- @client_key, @client_secret = get_testingbot_credentials
3
+ # if selenium RC, add testingbot credentials to request
4
+ if defined?(Selenium) && defined?(Selenium::Client) && defined?(Selenium::Client::Protocol)
5
+ module Selenium
6
+ module Client
7
+ module Protocol
8
+ attr_writer :client_key, :client_secret
9
+
10
+ def client_key
11
+ if @client_key.nil?
12
+ @client_key, @client_secret = get_testingbot_credentials
13
+ end
14
+ @client_key
11
15
  end
12
- @client_key
13
- end
16
+
17
+ def client_secret
18
+ if @client_secret.nil?
19
+ @client_key, @client_secret = get_testingbot_credentials
20
+ end
21
+ @client_secret
22
+ end
23
+
24
+ def get_testingbot_credentials
25
+ if File.exists?(File.expand_path("~/.testingbot"))
26
+ str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp
27
+ str.split(':')
28
+ else
29
+ raise "Please run the testingbot install tool first"
30
+ end
31
+ end
32
+
33
+ # add custom parameters for testingbot.com
34
+ def http_request_for_testingbot(verb, args)
35
+ data = http_request_for_original(verb, args)
36
+ data << "&client_key=#{client_key}&client_secret=#{client_secret}"
37
+ end
38
+
39
+ begin
40
+ alias http_request_for_original http_request_for
41
+ alias http_request_for http_request_for_testingbot
42
+ rescue
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ if defined?(Selenium) && defined?(Selenium::Client) && defined?(Selenium::Client::Base)
50
+ module Selenium
51
+ module Client
52
+ module Base
53
+ DEFAULT_OPTIONS = {
54
+ :screenshot => true
55
+ }
14
56
 
15
- def client_secret
16
- if @client_secret.nil?
17
- @client_key, @client_secret = get_testingbot_credentials
57
+ alias :close_current_browser_session_old :close_current_browser_session
58
+ alias :start_new_browser_session_old :start_new_browser_session
59
+ alias :initialize_old :initialize
60
+
61
+ attr_accessor :options
62
+ attr_accessor :session_id_backup
63
+ attr_accessor :extra
64
+ attr_accessor :platform
65
+ attr_accessor :version
66
+
67
+ def initialize(*args)
68
+ if args[0].kind_of?(Hash)
69
+ options = args[0]
70
+ @platform = options[:platform] || "WINDOWS"
71
+ @version = options[:version] if options[:version]
18
72
  end
19
- @client_secret
73
+
74
+ @options = DEFAULT_OPTIONS
75
+ initialize_old(*args)
76
+ @host = "hub.testingbot.com" if @host.nil?
77
+ @port = 4444 if @port.nil?
20
78
  end
21
79
 
22
- def get_testingbot_credentials
23
- if File.exists?(File.expand_path("~/.testingbot"))
24
- str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp
25
- str.split(':')
26
- else
27
- raise "Please run the testingbot install tool first"
28
- end
80
+ def close_current_browser_session
81
+ @session_id_backup = @session_id
82
+ close_current_browser_session_old
29
83
  end
30
84
 
31
- # add custom parameters for testingbot.com
32
- def http_request_for_testingbot(verb, args)
33
- data = http_request_for_original(verb, args)
34
- data << "&client_key=#{client_key}&client_secret=#{client_secret}"
85
+ def start_new_browser_session(options={})
86
+ options = @options.merge options
87
+ options[:platform] = @platform
88
+ options[:version] = @version unless @version.nil?
89
+ start_new_browser_session_old(options)
35
90
  end
36
91
 
37
- alias http_request_for_original http_request_for
38
- alias http_request_for http_request_for_testingbot
92
+ def extra=(str)
93
+ @extra = str
94
+ end
95
+
96
+ def options=(opts = {})
97
+ @options = @options.merge opts
98
+ end
99
+ end
39
100
  end
40
101
  end
41
102
  end
42
103
 
43
- module Selenium
44
- module Client
45
- module Base
46
- DEFAULT_OPTIONS = {
47
- :screenshot => true
48
- }
49
-
50
- alias :close_current_browser_session_old :close_current_browser_session
51
- alias :start_new_browser_session_old :start_new_browser_session
52
- alias :initialize_old :initialize
53
-
54
- attr_accessor :options
55
- attr_accessor :session_id_backup
56
- attr_accessor :extra
57
- attr_accessor :platform
58
- attr_accessor :version
59
-
60
- def initialize(*args)
61
- if args[0].kind_of?(Hash)
62
- options = args[0]
63
- @platform = options[:platform] || "WINDOWS"
64
- @version = options[:version] if options[:version]
65
- end
104
+ # rspec 1
105
+ begin
106
+ require 'spec'
107
+ require "selenium/rspec/spec_helper"
108
+ Spec::Runner.configure do |config|
109
+ config.prepend_after(:each) do
110
+ if File.exists?(File.expand_path("~/.testingbot"))
111
+ str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp
112
+ client_key, client_secret = str.split(':')
113
+
114
+ session_id = nil
115
+
116
+ if !@selenium_driver.nil?
117
+ session_id = @selenium_driver.session_id_backup
118
+ elsif defined?(Capybara)
119
+ session_id = Capybara.drivers[:testingbot].call.browser.instance_variable_get("@bridge").instance_variable_get("@session_id")
120
+ end
121
+
122
+ if session_id.nil?
123
+ return
124
+ end
125
+
126
+ params = {
127
+ "session_id" => session_id,
128
+ "client_key" => client_key,
129
+ "client_secret" => client_secret,
130
+ "status_message" => @execution_error,
131
+ "success" => !actual_failure?,
132
+ "name" => description.to_s,
133
+ "kind" => 2,
134
+ "extra" => @selenium_driver.extra
135
+ }
66
136
 
67
- @options = DEFAULT_OPTIONS
68
- initialize_old(*args)
69
- @host = "hub.testingbot.com" if @host.nil?
70
- @port = 4444 if @port.nil?
137
+ url = URI.parse('http://testingbot.com/hq')
138
+ http = Net::HTTP.new(url.host, url.port)
139
+ response = http.post(url.path, params.map { |k, v| "#{k.to_s}=#{v}" }.join("&"))
140
+ else
141
+ puts "Can't post test results to TestingBot since I could not a .testingbot file in your home-directory."
142
+ end
71
143
  end
72
-
73
- def close_current_browser_session
74
- @session_id_backup = @session_id
75
- close_current_browser_session_old
144
+ end
145
+ rescue LoadError
146
+ end
147
+
148
+ # rspec 2
149
+ begin
150
+ require 'rspec'
151
+
152
+ ::RSpec.configuration.after :each do
153
+ if File.exists?(File.expand_path("~/.testingbot"))
154
+ str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp
155
+ client_key, client_secret = str.split(':')
156
+
157
+ test_name = ""
158
+ if example.metadata && example.metadata[:example_group]
159
+ if example.metadata[:example_group][:description_args]
160
+ test_name = example.metadata[:example_group][:description_args].join(" ")
161
+ end
76
162
  end
77
163
 
78
- def start_new_browser_session(options={})
79
- options = @options.merge options
80
- options[:platform] = @platform
81
- options[:version] = @version unless @version.nil?
82
- start_new_browser_session_old(options)
83
- end
164
+ session_id = nil
84
165
 
85
- def extra=(str)
86
- @extra = str
166
+ if !@selenium_driver.nil?
167
+ session_id = @selenium_driver.session_id_backup
168
+ elsif defined?(Capybara)
169
+ session_id = Capybara.drivers[:testingbot].call.browser.instance_variable_get("@bridge").instance_variable_get("@session_id")
87
170
  end
88
171
 
89
- def options=(opts = {})
90
- @options = @options.merge opts
172
+ if session_id.nil?
173
+ return
91
174
  end
92
- end
93
- end
94
- end
95
-
96
- if defined?(Spec)
97
- Spec::Runner.configure do |config|
98
- config.prepend_after(:each) do
99
- if File.exists?(File.expand_path("~/.testingbot"))
100
- str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp
101
- client_key, client_secret = str.split(':')
102
175
 
103
- params = {
104
- "session_id" => @selenium_driver.session_id_backup,
105
- "client_key" => client_key,
106
- "client_secret" => client_secret,
107
- "status_message" => @execution_error,
108
- "success" => !actual_failure?,
109
- "name" => description.to_s,
110
- "kind" => 2,
111
- "extra" => @selenium_driver.extra
112
- }
113
-
114
- url = URI.parse('http://testingbot.com/hq')
115
- http = Net::HTTP.new(url.host, url.port)
116
- response = http.post(url.path, params.map { |k, v| "#{k.to_s}=#{v}" }.join("&"))
176
+ params = {
177
+ "session_id" => session_id,
178
+ "client_key" => client_key,
179
+ "client_secret" => client_secret,
180
+ "status_message" => @execution_error,
181
+ "success" => example.exception.nil?,
182
+ "name" => test_name,
183
+ "kind" => 2
184
+ }
185
+
186
+ if @selenium_driver && @selenium_driver.extra
187
+ params["extra"] = @selenium_driver.extra
117
188
  end
189
+
190
+ url = URI.parse('http://testingbot.com/hq')
191
+ http = Net::HTTP.new(url.host, url.port)
192
+ response = http.post(url.path, params.map { |k, v| "#{k.to_s}=#{v}" }.join("&"))
193
+ else
194
+ puts "Can't post test results to TestingBot since I could not a .testingbot file in your home-directory."
118
195
  end
119
196
  end
197
+ rescue LoadError
120
198
  end
121
199
 
122
200
  if defined?(Test::Unit::TestCase)
@@ -0,0 +1,26 @@
1
+ if defined?(Cucumber)
2
+ After do |scenario|
3
+ if Capybara.drivers.include?(:testingbot) && File.exists?(File.expand_path("~/.testingbot"))
4
+ unless Capybara.drivers[:testingbot].call.browser.nil?
5
+ session_id = Capybara.drivers[:testingbot].call.browser.instance_variable_get("@bridge").instance_variable_get("@session_id")
6
+
7
+ str = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp
8
+ client_key, client_secret = str.split(':')
9
+
10
+ params = {
11
+ "session_id" => session_id,
12
+ "client_key" => client_key,
13
+ "client_secret" => client_secret,
14
+ "status_message" => (scenario.failed? ? scenario.exception.message : ""),
15
+ "success" => !scenario.failed?,
16
+ "name" => scenario.title,
17
+ "kind" => 2
18
+ }
19
+
20
+ url = URI.parse('http://testingbot.com/hq')
21
+ http = Net::HTTP.new(url.host, url.port)
22
+ response = http.post(url.path, params.map { |k, v| "#{k.to_s}=#{v}" }.join("&"))
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module TestingBot
2
+ module Tunnel
3
+ def self.start_tunnel(host, port, localport = 80)
4
+ @@pid = fork do
5
+ exec "ssh -gNR #{port}:localhost:#{localport} #{host}"
6
+ end
7
+ end
8
+
9
+ def self.stop_tunnel
10
+ if @@pid
11
+ Process.kill "TERM", @@pid
12
+ Process.wait @@pid
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Testingbot
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -17,8 +17,4 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
- s.add_dependency "rspec", "<= 1.3.4"
21
- s.add_dependency "selenium-client"
22
-
23
- s.requirements << "Selenium-Client and RSpec 1"
24
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testingbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,30 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-03 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70105967496820 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - <=
20
- - !ruby/object:Gem::Version
21
- version: 1.3.4
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: *70105967496820
25
- - !ruby/object:Gem::Dependency
26
- name: selenium-client
27
- requirement: &70105967495920 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70105967495920
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
+ dependencies: []
36
14
  description: This gem makes using our Selenium grid on testingbot.com easy
37
15
  email:
38
16
  - info@testingbot.com
@@ -47,9 +25,13 @@ files:
47
25
  - README.rdoc
48
26
  - Rakefile
49
27
  - bin/testingbot
28
+ - examples/capybara.rb
50
29
  - examples/test_rspec.rb
30
+ - examples/test_rspec1.rb
51
31
  - examples/test_unit.rb
52
32
  - lib/testingbot.rb
33
+ - lib/testingbot/cucumber.rb
34
+ - lib/testingbot/tunnel.rb
53
35
  - lib/testingbot/version.rb
54
36
  - testingbot.gemspec
55
37
  homepage: http://www.testingbot.com
@@ -70,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
52
  - - ! '>='
71
53
  - !ruby/object:Gem::Version
72
54
  version: '0'
73
- requirements:
74
- - Selenium-Client and RSpec 1
55
+ requirements: []
75
56
  rubyforge_project: testingbot
76
57
  rubygems_version: 1.8.10
77
58
  signing_key: