selenium-launcher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47064747dcd76f242df501b3316329097660ae37
4
+ data.tar.gz: caae88fe2c13bceeceb425264ba2a127febd0e50
5
+ SHA512:
6
+ metadata.gz: c54ce10a41be5679d2d6346a1f437ad91aa32ffa723391e94a7f0482fb83c850f5a9c8ec09e0a58af396d03c7abe6bb587cbdf5228a51c216f494b6d0f7ccb74
7
+ data.tar.gz: 493f73d610c50b8873b1da8cdf17e5fbd1f55a408553533479ce4142a5245c513fb317de2ec0deea1f727d53d28ece4824dc769a5d6add54417838eae7288396
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.DS_Store/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,4 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/*/.+_spec\.rb$})
3
+ watch(%r{^lib/selenium-connect/*/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ end
data/README.txt ADDED
@@ -0,0 +1,68 @@
1
+ = selenium-launcher
2
+
3
+ == DESCRIPTION:
4
+
5
+ selenium-launcher provides a simple way to configure Selenium and launch a browser.
6
+
7
+ Currently supported approachs include:
8
+ 1. Local browser execution with browser drivers (for easier test authoring)
9
+ 2. Remote execution (for a single node or a grid)
10
+
11
+ == CONSIDERATIONS:
12
+
13
+ + Will need to sort out the best way to handle browser driver downloads and configuration per OS. Will start by letting the user do the work and automate it later (in a separate gem).
14
+ + Cloud execution will need to be added later, but that has additional considerations. So that will be deferred for now.
15
+ + Mobile is also a consideration. Again, one to defer for now.
16
+
17
+ == USAGE:
18
+
19
+ === Environment Variables
20
+
21
+ Configuration occurs through a small set of environment variables:
22
+
23
+ SL_HOST (e.g., 'grid', or nothing)
24
+ SL_HOST_URL (e.g., URL to Standalone Remote or Grid instance)
25
+ SL_BROWSER (e.g., 'chrome', 'firefox', 'internet-explorer', 'safari')
26
+
27
+ If these values are not set properly, a RuntimeError will be returned along with a helpful message.
28
+
29
+
30
+ selenium-launcher will return a Selenium WebDriver object.
31
+
32
+ === Local
33
+
34
+ ENV['SL_BROWSER'] = 'firefox'
35
+ driver = SeleniumLauncher.launch
36
+ driver.quit
37
+
38
+ === Grid
39
+
40
+ ENV['SL_BROWSER'] = 'firefox'
41
+ ENV['SL_HOST'] = 'grid'
42
+ ENV['SL_HOST_URL'] = 'http://localhost:4444/wd/hub'
43
+ driver = SeleniumLauncher.launch
44
+ driver.quit
45
+
46
+ == LICENSE:
47
+
48
+ The MIT License (MIT)
49
+
50
+ Copyright (c) 2014 Dave Haeffner
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining a copy
53
+ of this software and associated documentation files (the "Software"), to deal
54
+ in the Software without restriction, including without limitation the rights
55
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
56
+ copies of the Software, and to permit persons to whom the Software is
57
+ furnished to do so, subject to the following conditions:
58
+
59
+ The above copyright notice and this permission notice shall be included in all
60
+ copies or substantial portions of the Software.
61
+
62
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
65
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
67
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
68
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,28 @@
1
+ require_relative 'browsers/chrome'
2
+ require_relative 'browsers/firefox'
3
+ require_relative 'browsers/internet-explorer'
4
+ require_relative 'browsers/safari'
5
+
6
+ module SeleniumLauncher
7
+ class Browser
8
+
9
+ attr_reader :name
10
+
11
+ def match?
12
+ name == ENV['SL_BROWSER']
13
+ end
14
+
15
+ def capabilities
16
+ #::Selenium::WebDriver::Remote::Capabilities.send(name)
17
+ name.to_sym
18
+ end
19
+
20
+ def self.load
21
+ [ Chrome.new,
22
+ Firefox.new,
23
+ InternetExplorer.new,
24
+ Safari.new ].find { |browser| browser.match? }
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ module SeleniumLauncher
2
+ class Browser
3
+ class Chrome < Browser
4
+
5
+ def name
6
+ 'chrome'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module SeleniumLauncher
2
+ class Browser
3
+ class Firefox < Browser
4
+
5
+ def name
6
+ 'firefox'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module SeleniumLauncher
2
+ class Browser
3
+ class InternetExplorer < Browser
4
+
5
+ def name
6
+ 'internet-explorer'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module SeleniumLauncher
2
+ class Browser
3
+ class Safari < Browser
4
+
5
+ def name
6
+ 'safari'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'browser'
2
+ require 'selenium-webdriver'
3
+
4
+ module SeleniumLauncher
5
+ class Launcher
6
+
7
+ attr_reader :browser, :driver
8
+
9
+ def initialize
10
+ @browser = SeleniumLauncher::Browser.load
11
+ @driver = launch
12
+ end
13
+
14
+ def quit
15
+ driver.quit
16
+ end
17
+
18
+ private
19
+
20
+ def launch
21
+ case ENV['SL_HOST']
22
+ when 'grid'
23
+ ::Selenium::WebDriver.for(
24
+ :remote,
25
+ url: ENV['SL_HOST_URL'],
26
+ desired_capabilities: browser.capabilities)
27
+ else
28
+ ::Selenium::WebDriver.for browser.name.to_sym
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module SeleniumLauncher
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'selenium-launcher/launcher'
2
+
3
+ module SeleniumLauncher
4
+
5
+ def self.launch
6
+ ConfigChecker.new
7
+ SeleniumLauncher::Launcher.new.driver
8
+ end
9
+
10
+ class ConfigChecker
11
+
12
+ def initialize
13
+ browser_check
14
+ grid_check
15
+ end
16
+
17
+ private
18
+
19
+ ERRORS = { NoBrowserSpecified: 'You need to specify a browser (e.g., SL_BROWSER).',
20
+ NoGridURLSpecified: 'You need to specify a URL when using a Grid (e.g., SL_HOST_URL).' }
21
+
22
+ def browser_check
23
+ if ENV['SL_BROWSER'].nil?
24
+ raise ERRORS[:NoBrowserSpecified]
25
+ end
26
+ end
27
+
28
+ def grid_check
29
+ if ENV['SL_HOST'] == 'grid'
30
+ if ENV['SL_HOST_URL'].nil?
31
+ raise ERRORS[:NoGridURLSpecified]
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'selenium-launcher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "selenium-launcher"
8
+ spec.version = SeleniumLauncher::VERSION
9
+ spec.authors = ["Dave Haeffner"]
10
+ spec.email = ["dhaeffner@gmail.com"]
11
+ spec.summary = %q{A simple way to configure and launch a Selenium instance}
12
+ spec.description = %q{See README.txt}
13
+ spec.homepage = "https://github.com/tourdedave/selenium-launcher"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "selenium-webdriver", "~> 2.43.0"
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
24
+ spec.add_development_dependency "guard-rspec", "~> 4.3.1"
25
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../lib/selenium-launcher/browser'
2
+
3
+ describe 'Browser returns', :unit do
4
+
5
+ it 'Chrome' do
6
+ ENV['SL_BROWSER'] = 'chrome'
7
+ browser = SeleniumLauncher::Browser.load
8
+ expect(browser.class).to eql SeleniumLauncher::Browser::Chrome
9
+ end
10
+
11
+ it 'Firefox' do
12
+ ENV['SL_BROWSER'] = 'firefox'
13
+ browser = SeleniumLauncher::Browser.load
14
+ expect(browser.class).to eql SeleniumLauncher::Browser::Firefox
15
+ end
16
+
17
+ it 'Internet Explorer' do
18
+ ENV['SL_BROWSER'] = 'internet-explorer'
19
+ browser = SeleniumLauncher::Browser.load
20
+ expect(browser.class).to eql SeleniumLauncher::Browser::InternetExplorer
21
+ end
22
+
23
+ it 'Safari' do
24
+ ENV['SL_BROWSER'] = 'safari'
25
+ browser = SeleniumLauncher::Browser.load
26
+ expect(browser.class).to eql SeleniumLauncher::Browser::Safari
27
+ end
28
+
29
+ end
@@ -0,0 +1,80 @@
1
+ require_relative 'spec_helper'
2
+ require_relative '../lib/selenium-launcher/launcher'
3
+
4
+ describe 'Launcher', :integration do
5
+
6
+ after(:each) do
7
+ @launcher.quit
8
+ end
9
+
10
+ context '-> Localhost -> ' do
11
+
12
+ it 'Chrome' do
13
+ ENV['SL_BROWSER'] = 'chrome'
14
+ @launcher = SeleniumLauncher::Launcher.new
15
+ expect(@launcher.driver.class).to eql Selenium::WebDriver::Driver
16
+ expect(@launcher.driver.browser).to eql :chrome
17
+ end
18
+
19
+ it 'Firefox' do
20
+ ENV['SL_BROWSER'] = 'firefox'
21
+ @launcher = SeleniumLauncher::Launcher.new
22
+ expect(@launcher.driver.class).to eql Selenium::WebDriver::Driver
23
+ expect(@launcher.driver.browser).to eql :firefox
24
+ end
25
+
26
+ it 'Internet Explorer' do
27
+ pending 'Windows OS required' unless OS.windows?
28
+ ENV['SL_BROWSER'] = 'internet-explorer'
29
+ @launcher = SeleniumLauncher::Launcher.new
30
+ expect(@launcher.driver.class).to eql Selenium::WebDriver::Driver
31
+ expect(@launcher.driver.browser).to eql :"internet-explorer"
32
+ end
33
+
34
+ it 'Safari' do
35
+ ENV['SL_BROWSER'] = 'safari'
36
+ @launcher = SeleniumLauncher::Launcher.new
37
+ expect(@launcher.driver.class).to eql Selenium::WebDriver::Driver
38
+ expect(@launcher.driver.browser).to eql :safari
39
+ end
40
+
41
+ end
42
+
43
+ context '-> Grid -> ' do
44
+
45
+ before(:all) do
46
+ ENV['SL_HOST'] = 'grid'
47
+ ENV['SL_HOST_URL'] = 'http://localhost:4444/wd/hub'
48
+ end
49
+
50
+ it 'Chrome' do
51
+ ENV['SL_BROWSER'] = 'chrome'
52
+ @launcher = SeleniumLauncher::Launcher.new
53
+ expect(@launcher.driver.class).to eql Selenium::WebDriver::Driver
54
+ expect(@launcher.driver.browser).to eql :chrome
55
+ end
56
+
57
+ it 'Firefox' do
58
+ ENV['SL_BROWSER'] = 'firefox'
59
+ @launcher = SeleniumLauncher::Launcher.new
60
+ expect(@launcher.driver.class).to eql Selenium::WebDriver::Driver
61
+ expect(@launcher.driver.browser).to eql :firefox
62
+ end
63
+
64
+ it 'Internet Explorer' do
65
+ pending 'Windows OS required' unless OS.windows?
66
+ ENV['SL_BROWSER'] = 'internet-explorer'
67
+ @launcher = SeleniumLauncher::Launcher.new
68
+ expect(@launcher.driver.class).to eql Selenium::WebDriver::Driver
69
+ expect(@launcher.driver.browser).to eql :"internet-explorer"
70
+ end
71
+
72
+ it 'Safari' do
73
+ ENV['SL_BROWSER'] = 'safari'
74
+ @launcher = SeleniumLauncher::Launcher.new
75
+ expect(@launcher.driver.class).to eql Selenium::WebDriver::Driver
76
+ expect(@launcher.driver.browser).to eql :safari
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../lib/selenium-launcher'
2
+
3
+ describe 'Selenium Launcher', :acceptance do
4
+
5
+ it 'runs' do
6
+ ENV['SL_BROWSER'] = 'firefox'
7
+ driver = SeleniumLauncher.launch
8
+ expect(driver.class).to eql Selenium::WebDriver::Driver
9
+ expect(driver.browser).to eql :firefox
10
+ driver.quit
11
+ end
12
+
13
+ context '-> Config Checker -> ' do
14
+
15
+ before(:each) do
16
+ ENV['SL_BROWSER'] = nil
17
+ ENV['SL_HOST'] = nil
18
+ ENV['SL_HOST_URL'] = nil
19
+ end
20
+
21
+ it 'no browser' do
22
+ expect { driver = SeleniumLauncher.launch }.to raise_error(
23
+ RuntimeError,
24
+ 'You need to specify a browser (e.g., SL_BROWSER).')
25
+ end
26
+
27
+ it 'no Grid host URL' do
28
+ ENV['SL_BROWSER'] = 'firefox'
29
+ ENV['SL_HOST'] = 'grid'
30
+ expect { driver = SeleniumLauncher.launch }.to raise_error(
31
+ RuntimeError,
32
+ 'You need to specify a URL when using a Grid (e.g., SL_HOST_URL).')
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,19 @@
1
+ module OS
2
+ def OS.windows?
3
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
4
+ end
5
+
6
+ def OS.mac?
7
+ (/darwin/ =~ RUBY_PLATFORM) != nil
8
+ end
9
+
10
+ def OS.unix?
11
+ !OS.windows?
12
+ end
13
+
14
+ def OS.linux?
15
+ OS.unix? and not OS.mac?
16
+ end
17
+ end
18
+
19
+ include OS
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium-launcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Haeffner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: selenium-webdriver
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.43.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.43.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.3.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.3.1
83
+ description: See README.txt
84
+ email:
85
+ - dhaeffner@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Guardfile
93
+ - README.txt
94
+ - Rakefile
95
+ - lib/selenium-launcher.rb
96
+ - lib/selenium-launcher/browser.rb
97
+ - lib/selenium-launcher/browsers/chrome.rb
98
+ - lib/selenium-launcher/browsers/firefox.rb
99
+ - lib/selenium-launcher/browsers/internet-explorer.rb
100
+ - lib/selenium-launcher/browsers/safari.rb
101
+ - lib/selenium-launcher/launcher.rb
102
+ - lib/selenium-launcher/version.rb
103
+ - selenium-launcher.gemspec
104
+ - spec/browser_spec.rb
105
+ - spec/launcher_spec.rb
106
+ - spec/selenium-connect_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/tourdedave/selenium-launcher
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A simple way to configure and launch a Selenium instance
132
+ test_files:
133
+ - spec/browser_spec.rb
134
+ - spec/launcher_spec.rb
135
+ - spec/selenium-connect_spec.rb
136
+ - spec/spec_helper.rb