selenium-connect 2.3.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.coveralls.yml +1 -0
- data/.gitignore +1 -0
- data/.rspec +6 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +16 -0
- data/Guardfile +6 -0
- data/README.md +121 -16
- data/Rakefile +36 -12
- data/lib/selenium-connect.rb +3 -82
- data/lib/selenium_connect.rb +49 -0
- data/lib/{selenium-connect → selenium_connect}/configuration.rb +4 -2
- data/lib/selenium_connect/job.rb +102 -0
- data/lib/selenium_connect/report/job_report.rb +17 -0
- data/lib/selenium_connect/report/main_report.rb +17 -0
- data/lib/selenium_connect/report/report_factory.rb +25 -0
- data/lib/{selenium-connect → selenium_connect}/runner.rb +9 -8
- data/lib/{selenium-connect → selenium_connect}/runners/chrome.rb +1 -1
- data/lib/{selenium-connect → selenium_connect}/runners/firefox.rb +1 -1
- data/lib/{selenium-connect → selenium_connect}/runners/ie.rb +1 -1
- data/lib/{selenium-connect → selenium_connect}/runners/no_browser.rb +1 -1
- data/lib/{selenium-connect → selenium_connect}/runners/phantomjs.rb +1 -1
- data/lib/{selenium-connect → selenium_connect}/runners/saucelabs.rb +2 -1
- data/lib/{selenium-connect → selenium_connect}/server.rb +2 -1
- data/selenium-connect.gemspec +9 -4
- data/spec/integration/lib/selenium_connect/runners/chrome_spec.rb +19 -0
- data/spec/integration/lib/selenium_connect/runners/firefox_spec.rb +55 -0
- data/spec/integration/lib/selenium_connect/runners/headless_spec.rb +33 -0
- data/spec/integration/lib/selenium_connect/runners/ie_spec.rb +24 -0
- data/spec/{runners → integration/lib/selenium_connect/runners}/phantomjs_spec.rb +4 -3
- data/spec/integration/lib/selenium_connect/runners/sauce_spec.rb +63 -0
- data/spec/integration/lib/selenium_connect_spec.rb +41 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/{example.yaml → support/example.yaml} +0 -0
- data/spec/{acceptance/helper.rb → support/example_page_object.rb} +1 -1
- data/spec/support/integration_helper.rb +9 -0
- data/spec/unit/lib/selenium-connect_spec.rb +15 -0
- data/spec/{configuration_spec.rb → unit/lib/selenium_connect/configuration_spec.rb} +9 -3
- data/spec/unit/lib/selenium_connect/job_spec.rb +38 -0
- data/spec/unit/lib/selenium_connect/report/job_report_spec.rb +20 -0
- data/spec/unit/lib/selenium_connect/report/main_report_spec.rb +20 -0
- data/spec/unit/lib/selenium_connect/report/report_factory_spec.rb +27 -0
- data/spec/unit/lib/selenium_connect/runners/.gitkeep +0 -0
- data/spec/unit/lib/selenium_connect_spec.rb +58 -0
- metadata +125 -29
- data/spec/acceptance/chrome_spec.rb +0 -21
- data/spec/acceptance/firefox_spec.rb +0 -62
- data/spec/acceptance/headless_spec.rb +0 -29
- data/spec/acceptance/ie_spec.rb +0 -21
- data/spec/acceptance/logging_spec.rb +0 -28
- data/spec/acceptance/sauce_spec.rb +0 -27
- data/spec/quit_and_finish_spec.rb +0 -14
- data/spec/yaml_spec.rb +0 -51
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
#3.0.0 (2013-07-14)
|
2
|
+
- updated rake file to run all the tests on a release start
|
3
|
+
- Bumped version to 3.0.0 to prepare for release.
|
4
|
+
- updated coverage badge in the docs and did a little ditty to jive gem name with proper file naming
|
5
|
+
- updated the build process to add the version number and date to the top of the readme on release so that people know how old the docs is #5
|
6
|
+
- updated documentation to reflect the changes in #5
|
7
|
+
- added a facility to download a job tagged failure image to the logs directory
|
8
|
+
- now sending a passed or failed bool in the finish command will mark sauce labs jobs as such #5
|
9
|
+
- major refactoring of public api per #5 and updating the tests to match
|
10
|
+
- added guard configuration and updated the coverage reports to go to the build directory #5
|
11
|
+
- added coveralls code coverage information #5
|
12
|
+
- added catch to rakefile for log deletions #5
|
13
|
+
- updated tests for new support files location, cleaned up build process adding good logging and seperation of unit, integration, and system tests #5
|
14
|
+
- moved specs into standard format, updated names to standard class file name convention #5
|
15
|
+
- fixed some minor code quality issues
|
16
|
+
|
1
17
|
#2.3.0 (2013-07-12)
|
2
18
|
- removed debug information from the sauce_spec
|
3
19
|
- Bumped version to 2.3.0 to prepare for release.
|
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,34 +1,51 @@
|
|
1
|
-
|
1
|
+
#selenium-connect 3.0.0 (2013-07-14)
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/selenium-connect.png)](http://badge.fury.io/rb/selenium-connect) [![Build Status](https://travis-ci.org/arrgyle/selenium-connect.png?branch=develop)](https://travis-ci.org/arrgyle/selenium-connect) [![Code Climate](https://codeclimate.com/github/arrgyle/selenium-connect.png)](https://codeclimate.com/github/arrgyle/selenium-connect) [![Coverage Status](https://coveralls.io/repos/arrgyle/selenium-connect/badge.png?branch=develop)](https://coveralls.io/r/arrgyle/selenium-connect?branch=develop)
|
4
4
|
|
5
|
-
|
5
|
+
A stupid simple way to run your Selenium tests on your computer, against a Selenium Grid, or in the cloud (e.g. SauceLabs). For a rocking implementation of this library, checkout [ChemistryKit](https://github.com/arrgyle/chemistrykit)!
|
6
6
|
|
7
|
-
|
7
|
+
All the documentation for Selenium Connect can be found in this README, organized as follows:
|
8
|
+
|
9
|
+
- [Getting Started](#getting-started)
|
10
|
+
- [Helpful Bits](#helpful-bits)
|
11
|
+
- [Configuration](#configuration)
|
12
|
+
- [Contribution Guidelines](#contribution-guidelines)
|
13
|
+
- [Deployment](#deployment)
|
8
14
|
|
9
15
|
## Getting Started
|
10
16
|
```ruby
|
11
17
|
require 'selenium-connect'
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
# generate a config object
|
20
|
+
config = SeleniumConnect::Configuration.new browser: 'firefox'
|
21
|
+
|
22
|
+
# get connected
|
23
|
+
sc = SeleniumConnect.start config
|
24
|
+
|
25
|
+
# create a job
|
26
|
+
job = sc.create_job
|
17
27
|
|
28
|
+
# start the job to get a driver
|
29
|
+
@driver = job.start
|
30
|
+
|
31
|
+
# get on the road!
|
18
32
|
@driver = SeleniumConnect.start
|
19
33
|
@driver.get "http://www.google.com"
|
20
|
-
SeleniumConnect.finish
|
21
|
-
```
|
22
34
|
|
23
|
-
|
35
|
+
# finish your job
|
36
|
+
job.finish
|
37
|
+
|
38
|
+
# go have some fun!
|
39
|
+
sc.finish
|
40
|
+
|
41
|
+
## Helpful Bits
|
24
42
|
|
25
43
|
### Start
|
26
44
|
If host is set to "localhost" and no jar file is specified, it will run the version of [selenium-standalone-server.jar](https://code.google.com/p/selenium/downloads/list) that is bundled with the library (currently 2.33.0). Or, you can specify your own jar if you have one you prefer to use. This is done with c.jar = 'path-to-jar-file'.
|
27
45
|
|
28
|
-
If no additional parameters are set, the Selenium Server will be run in the background with logging disabled. If a logging directory is provided (with c.log = 'path-to-log-dir') then
|
46
|
+
If no additional parameters are set, the Selenium Server will be run in the background with logging disabled. If a logging directory is provided (with c.log = 'path-to-log-dir') then 2 output files will be generated:
|
29
47
|
+ Selenium Server JSON Wire Protocol output (server.log)
|
30
48
|
+ Browser output (browser.log) -- currently only available for Firefox
|
31
|
-
+ Test output (SPEC-testname.xml)
|
32
49
|
|
33
50
|
This localhost functionality is driven using the [Selenium Rake Server Task](http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/Rake/ServerTask.html).
|
34
51
|
|
@@ -42,7 +59,71 @@ The finish command issues a quit command to the driver and stops the local serve
|
|
42
59
|
- [PhantomJS](https://github.com/arrgyle/selenium-connect/blob/develop/spec/acceptance/headless_spec.rb)
|
43
60
|
- [SauceLabs](https://github.com/arrgyle/selenium-connect/blob/develop/spec/acceptance/sauce_spec.rb)
|
44
61
|
|
45
|
-
##
|
62
|
+
## Configuration
|
63
|
+
Configuration of Selenium Connect is SUPER SIMPLE if you want it to be:
|
64
|
+
|
65
|
+
config = SeleniumConnect::Configuration.new
|
66
|
+
|
67
|
+
By default it will run a local instance of selenium server on port 4444 and launch firefox. Get going without a whole bunch of shenanigans.
|
68
|
+
|
69
|
+
If however you want to install custom settings you can use any of the following:
|
70
|
+
|
71
|
+
```YAML
|
72
|
+
# Setup & Debugging
|
73
|
+
jar: # this is where my selenium server jar is
|
74
|
+
log: # the logs go to this folder
|
75
|
+
|
76
|
+
# Where to run your tests
|
77
|
+
host: 'localhost' # local, a grid ip or "saucelabs"
|
78
|
+
port:
|
79
|
+
|
80
|
+
# Browser
|
81
|
+
browser: 'firefox'
|
82
|
+
browser_path:
|
83
|
+
profile_path:
|
84
|
+
profile_name:
|
85
|
+
|
86
|
+
# Saucelabs
|
87
|
+
os:
|
88
|
+
sauce_username: 'test_user_name'
|
89
|
+
sauce_api_key:
|
90
|
+
browser_version:
|
91
|
+
description: #sauce job/test description
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
You can pass parameters into the new config object like:
|
96
|
+
|
97
|
+
config = SeleniumConnect::Configuration.new host: 'sauce labs', log: 'build'
|
98
|
+
|
99
|
+
Or you can load them up from a YAML file:
|
100
|
+
|
101
|
+
config = SeleniumConnect::Configuration.new.populate_with_yaml '/my/config.yaml'
|
102
|
+
|
103
|
+
|
104
|
+
###Additional Configuration
|
105
|
+
When you create your job you can pass in parameters, right now just `:name` that lets you configure a job at runtime. This is helpful for using Sauce Labs where you'd want to update the description to whatever test job you are running:
|
106
|
+
|
107
|
+
|
108
|
+
```Ruby
|
109
|
+
#…
|
110
|
+
job.start name: 'website should load'
|
111
|
+
#…
|
112
|
+
```
|
113
|
+
|
114
|
+
Similarly, when you finish your job you can pass in parameters. Right now this is limited to sauce labs jobs, as it lets you mark the tests as passed, failed, and turn on downloading the failure screenshot:
|
115
|
+
|
116
|
+
```Ruby
|
117
|
+
# sweet your test passed!
|
118
|
+
report = job.finish passed: true
|
119
|
+
|
120
|
+
# shucks your test failed :(
|
121
|
+
report = job.finish failed: true, failshot: true
|
122
|
+
```
|
123
|
+
|
124
|
+
The `report` is simply a container for arbitrary data. Right now we are passing back the sauce details.
|
125
|
+
|
126
|
+
## Contribution Guidelines
|
46
127
|
|
47
128
|
This project conforms to the [neverstopbuilding/craftsmanship](https://github.com/neverstopbuilding/craftsmanship) guidelines. Specifically related to the branching model and versioning. Please see the guidelines for details.
|
48
129
|
|
@@ -50,6 +131,30 @@ This project conforms to the [neverstopbuilding/craftsmanship](https://github.co
|
|
50
131
|
|
51
132
|
bundle install
|
52
133
|
|
53
|
-
### Run the Tests
|
134
|
+
### Run the Tests!
|
135
|
+
|
136
|
+
```
|
137
|
+
rake # defaults to 'build' task, code quality, unit, and integration tests
|
138
|
+
rake unit # unit tests
|
139
|
+
rake integration # integration tests
|
140
|
+
rake system # system tests
|
141
|
+
```
|
142
|
+
|
143
|
+
### Or get your Guard On!
|
144
|
+
|
145
|
+
Running:
|
146
|
+
|
147
|
+
guard
|
148
|
+
|
149
|
+
Will start watching the code and run the unit tests on save. Cool.
|
150
|
+
|
151
|
+
## Deployment
|
152
|
+
The release process is rather automated, just use one rake task with the new version number:
|
153
|
+
|
154
|
+
rake release_start['2.1.0']
|
155
|
+
|
156
|
+
And another to finish the release:
|
157
|
+
|
158
|
+
rake release_finish['A helpful tag message that will be included in the gemspec.']
|
54
159
|
|
55
|
-
|
160
|
+
This handles updating the change log, committing, and tagging the release.
|
data/Rakefile
CHANGED
@@ -1,27 +1,43 @@
|
|
1
1
|
# Encoding: utf-8
|
2
2
|
|
3
|
-
require 'bundler/gem_tasks'
|
4
3
|
require 'rspec/core/rake_task'
|
5
4
|
|
6
|
-
task default: :
|
5
|
+
task default: :build
|
7
6
|
|
8
|
-
task
|
7
|
+
task build: [:clean, :prepare, :rubocop, :unit, :integration]
|
9
8
|
|
10
9
|
desc 'Runs standard build activities.'
|
11
|
-
task
|
10
|
+
task build_full: [:clean, :prepare, :rubocop, :unit, :integration, :system]
|
12
11
|
|
13
12
|
desc 'Removes the build directory.'
|
14
13
|
task :clean do
|
15
|
-
FileUtils.rm_rf
|
14
|
+
FileUtils.rm_rf 'build'
|
15
|
+
FileUtils.rm 'chromedriver.log' if File.exist? 'chromedriver.log'
|
16
|
+
FileUtils.rm 'libpeerconnection.log' if File.exist? 'libpeerconnection.log'
|
16
17
|
end
|
17
18
|
desc 'Adds the build tmp directory for test kit creation.'
|
18
19
|
task :prepare do
|
19
20
|
FileUtils.mkdir_p('build/tmp')
|
21
|
+
FileUtils.mkdir_p('build/spec')
|
20
22
|
end
|
21
|
-
RSpec::Core::RakeTask.new(:spec_full)
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def get_rspec_flags(log_name, others = nil)
|
25
|
+
"--format documentation --out build/spec/#{log_name}.log --format html --out build/spec/#{log_name}.html --format progress #{others}"
|
26
|
+
end
|
27
|
+
|
28
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
29
|
+
t.pattern = FileList['spec/unit/**/*_spec.rb']
|
30
|
+
t.rspec_opts = get_rspec_flags('unit')
|
31
|
+
end
|
32
|
+
|
33
|
+
RSpec::Core::RakeTask.new(:integration) do |t|
|
34
|
+
t.pattern = FileList['spec/integration/**/*_spec.rb']
|
35
|
+
t.rspec_opts = get_rspec_flags('integration', '--tag=~selenium')
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:system) do |t|
|
39
|
+
t.pattern = FileList['spec/integration/**/*_spec.rb']
|
40
|
+
t.rspec_opts = get_rspec_flags('system', '--tag selenium')
|
25
41
|
end
|
26
42
|
|
27
43
|
desc 'Runs code quality check'
|
@@ -46,7 +62,7 @@ task :release_start, :version do |t, args|
|
|
46
62
|
system 'git pull --no-edit origin develop'
|
47
63
|
|
48
64
|
# next assure all the tests run
|
49
|
-
task(:
|
65
|
+
task(:build_full).invoke
|
50
66
|
|
51
67
|
# start the release process
|
52
68
|
system "git flow release start #{version}"
|
@@ -73,6 +89,8 @@ task :release_finish, :update_message do |t, args|
|
|
73
89
|
gemspec = File.join(Dir.getwd, 'selenium-connect.gemspec')
|
74
90
|
changelog = File.join(Dir.getwd, 'CHANGELOG.md')
|
75
91
|
version = File.read(gemspec).match(/s.version\s+=\s?["|'](.+)["|']/)[1]
|
92
|
+
readme = File.join(Dir.getwd, 'README.md')
|
93
|
+
date = Time.new.strftime('%Y-%m-%d')
|
76
94
|
|
77
95
|
### Changelog
|
78
96
|
# get the latest tag
|
@@ -85,7 +103,6 @@ task :release_finish, :update_message do |t, args|
|
|
85
103
|
log = `git log --format="- %s" --no-merges #{hash.chomp}..HEAD`
|
86
104
|
|
87
105
|
changelog_contents = File.read(changelog)
|
88
|
-
date = Time.new.strftime('%Y-%m-%d')
|
89
106
|
# create the new heading
|
90
107
|
updated_changelog = "##{version} (#{date})\n" + log + "\n" + changelog_contents
|
91
108
|
# update the contents
|
@@ -99,8 +116,15 @@ task :release_finish, :update_message do |t, args|
|
|
99
116
|
)
|
100
117
|
File.open(gemspec, 'w') { |f| f.write(updated_gemspec) }
|
101
118
|
|
102
|
-
|
103
|
-
|
119
|
+
### Update the readme heading
|
120
|
+
updated = File.read(readme).gsub(
|
121
|
+
/^#selenium-connect \d+\.\d+.\d+ \(.+\)/,
|
122
|
+
"#selenium-connect #{version} (#{date})"
|
123
|
+
)
|
124
|
+
File.open(readme, 'w') { |f| f.write(updated) }
|
125
|
+
|
126
|
+
# Commit the updated change log and gemspec and readme
|
127
|
+
system "git commit -am 'Updated CHANGELOG.md gemspec and readme heading for #{version} release.'"
|
104
128
|
|
105
129
|
# build the gem
|
106
130
|
system 'gem build selenium-connect.gemspec'
|
data/lib/selenium-connect.rb
CHANGED
@@ -1,84 +1,5 @@
|
|
1
1
|
# Encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require '
|
6
|
-
require 'selenium-connect/server'
|
7
|
-
require 'sauce/client'
|
8
|
-
require 'rest_client'
|
9
|
-
|
10
|
-
# Selenium Connect main module
|
11
|
-
module SeleniumConnect
|
12
|
-
|
13
|
-
extend self
|
14
|
-
attr_reader :config, :config_file, :location, :server, :driver
|
15
|
-
|
16
|
-
def configure
|
17
|
-
yield configuration
|
18
|
-
end
|
19
|
-
|
20
|
-
def configuration
|
21
|
-
@config = Configuration.new
|
22
|
-
end
|
23
|
-
|
24
|
-
def localhost?
|
25
|
-
config.host == 'localhost'
|
26
|
-
end
|
27
|
-
|
28
|
-
def debug_config
|
29
|
-
config
|
30
|
-
end
|
31
|
-
|
32
|
-
def run
|
33
|
-
if localhost?
|
34
|
-
@server = Server.new(config)
|
35
|
-
server.start
|
36
|
-
end
|
37
|
-
@driver = Runner.new(config).driver
|
38
|
-
end
|
39
|
-
|
40
|
-
def finish
|
41
|
-
# TODO this should grow into a standardized artifact returned
|
42
|
-
# by the driver
|
43
|
-
return_data = {}
|
44
|
-
begin
|
45
|
-
driver.quit
|
46
|
-
return_data = fetch_logs if config.host == 'saucelabs'
|
47
|
-
# rubocop:disable HandleExceptions
|
48
|
-
rescue Selenium::WebDriver::Error::WebDriverError
|
49
|
-
# rubocop:enable HandleExceptions
|
50
|
-
# no-op
|
51
|
-
end
|
52
|
-
server.stop if localhost?
|
53
|
-
|
54
|
-
return_data
|
55
|
-
end
|
56
|
-
|
57
|
-
def fetch_logs
|
58
|
-
# this could be pulled out into the specific sauce runner
|
59
|
-
job_id = driver.session_id
|
60
|
-
sauce_client = Sauce::Client.new
|
61
|
-
sauce_job = Sauce::Job.find(job_id)
|
62
|
-
# poll while job is in progress
|
63
|
-
while sauce_job.status == 'in progress'
|
64
|
-
sleep 5
|
65
|
-
sauce_job.refresh!
|
66
|
-
end
|
67
|
-
|
68
|
-
url = "#{sauce_client.api_url}jobs/#{job_id}/assets/selenium-server.log"
|
69
|
-
response = RestClient::Request.new(
|
70
|
-
method: :get,
|
71
|
-
url: url
|
72
|
-
).execute
|
73
|
-
|
74
|
-
log_file = File.join(Dir.getwd, config.log, "sauce_job_#{job_id}.log") if config.log
|
75
|
-
|
76
|
-
File.open(log_file, 'w') do |log|
|
77
|
-
log.write response
|
78
|
-
end
|
79
|
-
{ sauce_job: sauce_job }
|
80
|
-
end
|
81
|
-
|
82
|
-
alias_method :start, :run
|
83
|
-
alias_method :stop, :finish
|
84
|
-
end
|
3
|
+
# simple wrapper to join the dash oriented gem name with the _
|
4
|
+
# convention for file names.
|
5
|
+
require 'selenium_connect'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
require 'selenium_connect/job'
|
4
|
+
require 'selenium_connect/server'
|
5
|
+
require 'selenium_connect/configuration'
|
6
|
+
require 'selenium_connect/report/report_factory'
|
7
|
+
|
8
|
+
# Selenium Connect main module
|
9
|
+
class SeleniumConnect
|
10
|
+
|
11
|
+
attr_reader :config
|
12
|
+
|
13
|
+
# initializes and returns a new SeleniumConnect object
|
14
|
+
def self.start(config)
|
15
|
+
report_factory = SeleniumConnect::Report::ReportFactory.new
|
16
|
+
new config, report_factory
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(config, report_factory)
|
20
|
+
raise ArgumentError, 'Instance of SeleniumConnect::Configuration expected.' unless config.is_a? SeleniumConnect::Configuration
|
21
|
+
@config = config
|
22
|
+
@report_factory = report_factory
|
23
|
+
server_start
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_job(opts = {})
|
27
|
+
SeleniumConnect::Job.new @config, @report_factory
|
28
|
+
end
|
29
|
+
|
30
|
+
def finish
|
31
|
+
@server.stop unless @server.nil?
|
32
|
+
# returning empty report for now
|
33
|
+
@report_factory.build :main, {}
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def server_start
|
39
|
+
if @config.host == 'localhost'
|
40
|
+
# TODO this is just temp,
|
41
|
+
# in the next iteration we will inject this in by default in start
|
42
|
+
# to a required argument in initialize
|
43
|
+
@server = Server.new(config)
|
44
|
+
@server.start
|
45
|
+
else
|
46
|
+
@server = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|