selenium-connect 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,30 +1,23 @@
1
1
  #selenium-connect [![Code Climate](https://codeclimate.com/github/arrgyle/selenium-connect.png)](https://codeclimate.com/github/arrgyle/selenium-connect)
2
2
 
3
- This library aims to make configuring and running your Selenium tests against a Selenium Server simple for both local and remote execution.
3
+ A stupid simple way to run your Selenium tests on your computer, against a Selenium Grid, or in the cloud (e.g. SauceLabs).
4
4
 
5
5
  ## Getting Started
6
6
  ```ruby
7
7
  require 'selenium-connect'
8
8
 
9
9
  SeleniumConnect.configure do |c|
10
- c.host = "localhost"
11
- c.port = "4444"
10
+ c.host = "localhost" #or "grid_ip_address" or "saucelabs"
12
11
  c.browser = "firefox"
13
- c.profile_path = "#{Dir.pwd}/profiles/your_custom_firefox_profile" # or c.profile_name = "profile"
14
12
  end
15
13
 
16
14
  @driver = SeleniumConnect.start
17
-
18
15
  @driver.get "http://www.google.com"
19
-
20
16
  SeleniumConnect.finish
21
17
  ```
22
18
 
23
19
  ## Helpful bits
24
20
 
25
- ### Selenium Actions
26
- This library uses the Selenium WebDriver Remote Bridge actions. You can find them [here](http://www.ruby-doc.org/gems/docs/b/bbc-selenium-webdriver-1.17.0/Selenium/WebDriver/Remote/Bridge.html).
27
-
28
21
  ### Start
29
22
  If host is set to "localhost", it will download the latest selenium-standalone-server.jar (unless it already has) and run it. Or, you can specify your own jar (if you have one you prefer to use). If no additional parameters are set, it will be exected in the background, with logging disabled. This functionality is driven using the [Selenium Rake Server Task](http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/Rake/ServerTask.html).
30
23
 
@@ -32,7 +25,10 @@ If host is set to "localhost", it will download the latest selenium-standalone-s
32
25
  Issues a quit command to the driver (and stops the local server if your host is set to "localhost").
33
26
 
34
27
  ### Support
35
- Currently, Firefox solo & with a pre-fab custom profile is all that is supported. More coming soon!
28
+ - Firefox (standard, profile by path, profile by name, browser binary)
29
+ - Internet Explorer
30
+ - Chrome
31
+ - SauceLabs
36
32
 
37
33
  ### Versioning
38
- This project loosely follows [Semantic Versioning](http://semver.org/).
34
+ This project follows [Semantic Versioning](http://semver.org/).
@@ -1,6 +1,16 @@
1
1
  module SeleniumConnect
2
2
  class Configuration
3
- attr_accessor :host, :port, :browser, :browser_path, :profile_path, :profile_name, :version, :background, :log, :jar
3
+ #Selenium Server
4
+ attr_accessor :host, :port, :version,
5
+ :background, :log, :jar
6
+
7
+ #Browsers
8
+ attr_accessor :browser, :browser_path,
9
+ :profile_path, :profile_name
10
+
11
+ #SauceLabs
12
+ attr_accessor :sauce_username, :sauce_api_key,
13
+ :os, :browser_version, :description
4
14
 
5
15
  def initialize
6
16
  defaults
@@ -9,10 +19,10 @@ module SeleniumConnect
9
19
  private
10
20
 
11
21
  def defaults
12
- @host = "localhost" unless host
13
- @port = "4444" unless port
14
- @browser = "firefox" unless browser
22
+ @host = 'localhost' unless host
23
+ @port = 4444 unless port
15
24
  @log = false unless log
25
+ @browser = 'firefox' unless browser
16
26
  end
17
27
  end
18
28
  end
@@ -1,8 +1,8 @@
1
1
  require 'selenium/rake/server_task'
2
2
 
3
3
  Selenium::Rake::ServerTask.new(:server) do |t|
4
- t.jar = '/Users/more/Dropbox/_dev/Arrgyle/selenium-connect/selenium-server-standalone-2.32.0.jar'
4
+ t.version = :latest
5
5
  t.background
6
- t.log = 'false'
6
+ t.log = false
7
7
  t.port = 4444
8
8
  end
@@ -1,5 +1,8 @@
1
- require 'selenium-connect/runner/firefox'
2
- require 'selenium-connect/runner/ie'
1
+ require 'selenium-connect/runners/firefox'
2
+ require 'selenium-connect/runners/ie'
3
+ require 'selenium-connect/runners/chrome'
4
+ require 'selenium-connect/runners/no_browser'
5
+ require 'selenium-connect/runners/saucelabs'
3
6
 
4
7
  module SeleniumConnect
5
8
  class Runner
@@ -17,21 +20,28 @@ module SeleniumConnect
17
20
  end
18
21
 
19
22
  def init_driver
20
- Selenium::WebDriver.for(
21
- :remote,
22
- :url => set_server_url,
23
- :desired_capabilities => get_browser)
23
+ if config.host == 'saucelabs'
24
+ Saucelabs.new(config).launch
25
+ else
26
+ Selenium::WebDriver.for(
27
+ :remote,
28
+ :url => set_server_url,
29
+ :desired_capabilities => get_browser)
30
+ end
24
31
  end
25
32
 
26
33
  def get_browser
27
- case config.browser
28
- when "firefox"
29
- Firefox.new(config).capabilities
30
- when "ie"
31
- InternetExplorer.new(config).capabilities
32
- else
33
- puts "No valid browser specified"
34
- end
34
+ browser = browsers.find { |browser| browser.match? }
35
+ browser.launch
36
+ end
37
+
38
+ def browsers
39
+ firefox = Firefox.new(config)
40
+ ie = InternetExplorer.new(config)
41
+ chrome = Chrome.new(config)
42
+ no_browser = NoBrowser.new(config)
43
+
44
+ browsers = [ firefox, ie, chrome, no_browser ]
35
45
  end
36
46
 
37
47
  end #Runner
@@ -0,0 +1,26 @@
1
+ module SeleniumConnect
2
+ class Runner
3
+ class Chrome
4
+ attr_reader :config
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def match?
11
+ config.browser == "chrome"
12
+ end
13
+
14
+ def launch
15
+ init_browser
16
+ end
17
+
18
+ private
19
+
20
+ def init_browser
21
+ config.browser.to_sym
22
+ end
23
+
24
+ end #Chrome
25
+ end #Runner
26
+ end #SeleniumConnect
@@ -1,10 +1,17 @@
1
1
  module SeleniumConnect
2
2
  class Runner
3
3
  class Firefox
4
- attr_reader :config, :capabilities
4
+ attr_reader :config
5
5
 
6
6
  def initialize(config)
7
7
  @config = config
8
+ end
9
+
10
+ def match?
11
+ config.browser == "firefox"
12
+ end
13
+
14
+ def launch
8
15
  init_browser
9
16
  end
10
17
 
@@ -18,16 +25,17 @@ module SeleniumConnect
18
25
  end
19
26
  end
20
27
 
21
- def set_path
22
- end
23
-
24
- def init_browser
28
+ def config_browser
25
29
  profile = get_profile
26
30
  profile.assume_untrusted_certificate_issuer = false unless profile.nil?
27
31
  browser = Selenium::WebDriver::Remote::Capabilities.firefox
28
32
  browser[:firefox_binary] = config.browser_path if config.browser_path
29
33
  browser[:firefox_profile] = profile
30
- @capabilities = browser
34
+ return browser
35
+ end
36
+
37
+ def init_browser
38
+ config_browser
31
39
  end
32
40
 
33
41
  end #Firefox
@@ -1,17 +1,24 @@
1
1
  module SeleniumConnect
2
2
  class Runner
3
3
  class InternetExplorer
4
- attr_reader :config, :capabilities
4
+ attr_reader :config
5
5
 
6
6
  def initialize(config)
7
7
  @config = config
8
+ end
9
+
10
+ def match?
11
+ config.browser == "ie"
12
+ end
13
+
14
+ def launch
8
15
  init_browser
9
16
  end
10
17
 
11
18
  private
12
19
 
13
20
  def init_browser
14
- @capabilities = config.browser.to_sym
21
+ config.browser.to_sym
15
22
  end
16
23
 
17
24
  end #InternetExplorer
@@ -0,0 +1,21 @@
1
+ module SeleniumConnect
2
+ class Runner
3
+ class NoBrowser
4
+ attr_reader :config
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def match?
11
+ true
12
+ end
13
+
14
+ def execute
15
+ puts "Please specify a valid browser."
16
+ exit 1
17
+ end
18
+
19
+ end #NoBrowser
20
+ end #Runner
21
+ end #SeleniumConnect
@@ -0,0 +1,34 @@
1
+ require 'sauce'
2
+
3
+ module SeleniumConnect
4
+ class Runner
5
+ class Saucelabs
6
+ attr_reader :config
7
+
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+
12
+ def launch
13
+ init_browser
14
+ end
15
+
16
+ private
17
+
18
+ def get_credentials
19
+ ENV['SAUCE_USERNAME'] = config.sauce_username
20
+ ENV['SAUCE_ACCESS_KEY'] = config.sauce_api_key
21
+ end
22
+
23
+ def init_browser
24
+ get_credentials
25
+ Sauce::Selenium2.new({
26
+ :os => config.os,
27
+ :browser => config.browser,
28
+ :browser_version => config.browser_version,
29
+ :job_name => config.description })
30
+ end
31
+
32
+ end #Saucelabs
33
+ end #Runner
34
+ end #SeleniumConnect
@@ -32,7 +32,13 @@ module SeleniumConnect
32
32
  end
33
33
  }
34
34
  t.background
35
- t.log = '#{configuration.log}'
35
+ #{
36
+ if configuration.log
37
+ "t.log = '#{configuration.log}'"
38
+ else
39
+ "t.log = false"
40
+ end
41
+ }
36
42
  t.port = #{configuration.port}
37
43
  end"
38
44
  end
@@ -4,28 +4,28 @@ require 'selenium-connect/runner'
4
4
  require 'selenium-connect/server'
5
5
 
6
6
  module SeleniumConnect
7
+
7
8
  extend self
9
+ attr_reader :config, :location, :server, :driver
8
10
 
9
11
  def configure
10
12
  yield configuration
11
13
  end
12
14
 
13
15
  def configuration
14
- @configuration = Configuration.new
16
+ @config = Configuration.new
15
17
  end
16
18
 
17
- attr_reader :server, :driver
18
-
19
19
  def localhost?
20
- @configuration.host == 'localhost'
20
+ config.host == 'localhost'
21
21
  end
22
22
 
23
23
  def run
24
24
  if localhost?
25
- @server = Server.new(@configuration)
25
+ @server = Server.new(config)
26
26
  server.start
27
27
  end
28
- @driver = Runner.new(@configuration).driver
28
+ @driver = Runner.new(config).driver
29
29
  end
30
30
 
31
31
  def finish
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'selenium-connect'
3
- s.version = '1.5.1'
3
+ s.version = '1.6.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Dave Haeffner']
6
6
  s.email = ['dave@arrgyle.com']
7
7
  s.homepage = 'https://github.com/arrgyle/selenium-connect'
8
- s.summary = 'A configurator and runner for your Selenium tests against local and remote Selenium Servers.'
8
+ s.summary = 'A stupid simple way to run your Selenium tests on localhost, against a Selenium Grid, or in the cloud (e.g. SauceLabs).'
9
9
  s.license = 'MIT'
10
10
 
11
11
  s.files = `git ls-files`.split($/)
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_dependency 'selenium-webdriver'
17
17
  s.add_dependency 'rake'
18
+ s.add_dependency 'sauce'
18
19
 
19
20
  s.add_development_dependency 'rspec'
20
21
 
@@ -60,7 +60,7 @@ describe "Acceptance Tests" do
60
60
  end
61
61
  end
62
62
 
63
- it "browser path", :wip => true do
63
+ it "browser path" do
64
64
  #only works with Firefox
65
65
  SeleniumConnect.configure do |c|
66
66
  c.host = "localhost"
@@ -0,0 +1,21 @@
1
+ require 'selenium-connect'
2
+
3
+ describe "Sauce Labs" do
4
+
5
+ it 'hello world', :wip => true do
6
+ SeleniumConnect.configure do |c|
7
+ c.host = 'saucelabs'
8
+ c.sauce_username = 'testing_arrgyle'
9
+ c.sauce_api_key = 'ab7a6e17-16df-42d2-9ef6-c8d2539cc38a'
10
+ c.os = 'windows'
11
+ c.browser = 'iexplore'
12
+ c.browser_version = '7'
13
+ c.description = 'hello world from selenium-connect!'
14
+ end
15
+ driver = SeleniumConnect.start
16
+ driver.get 'http://google.com'
17
+ driver.title.should include('Google')
18
+ SeleniumConnect.finish
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-13 00:00:00.000000000 Z
12
+ date: 2013-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sauce
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: rspec
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -74,11 +90,15 @@ files:
74
90
  - lib/selenium-connect/configuration.rb
75
91
  - lib/selenium-connect/rake.task
76
92
  - lib/selenium-connect/runner.rb
77
- - lib/selenium-connect/runner/firefox.rb
78
- - lib/selenium-connect/runner/ie.rb
93
+ - lib/selenium-connect/runners/chrome.rb
94
+ - lib/selenium-connect/runners/firefox.rb
95
+ - lib/selenium-connect/runners/ie.rb
96
+ - lib/selenium-connect/runners/no_browser.rb
97
+ - lib/selenium-connect/runners/saucelabs.rb
79
98
  - lib/selenium-connect/server.rb
80
99
  - selenium-connect.gemspec
81
100
  - spec/acceptance_spec.rb
101
+ - spec/sauce_spec.rb
82
102
  homepage: https://github.com/arrgyle/selenium-connect
83
103
  licenses:
84
104
  - MIT
@@ -103,6 +123,6 @@ rubyforge_project:
103
123
  rubygems_version: 1.8.24
104
124
  signing_key:
105
125
  specification_version: 3
106
- summary: A configurator and runner for your Selenium tests against local and remote
107
- Selenium Servers.
126
+ summary: A stupid simple way to run your Selenium tests on localhost, against a Selenium
127
+ Grid, or in the cloud (e.g. SauceLabs).
108
128
  test_files: []