gridium 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b91d81fa156a7dc96a667a0b561606460278b3ac
4
- data.tar.gz: 465307a7f3ba4a61058b6ae975a8e810a6a60b32
3
+ metadata.gz: fa53796b32752f73131f570064f809f00b36a88e
4
+ data.tar.gz: 34520a57779e259536f90e1e3b24ada51300d910
5
5
  SHA512:
6
- metadata.gz: 909233a4baf760f869e58f250d722f71a23f2fbe43aef707b863a3cef0b1acb45c659362b12470a0c970679345b158e265059a0a4633aca5837f4b4548cb4b10
7
- data.tar.gz: 2fb66af2f69fd101d132670d9b0c8e6c627aed212ab03283f7acdd7ad43f05a8d2993a54c9e65e241c1341bad3a193a9624121d84fc56eb37696cd934174fe89
6
+ metadata.gz: 4930494ce2ef104a66f3d7db02ec1c4fe71c7af813a8c9302a9b4c421a9e48209bc07755b9950f26147a901625739446d357dd3835d810b573980e86942894ad
7
+ data.tar.gz: e2a3a6dcc023cfb15a0492696f33af1b5a02be824c4e1eba2b7e19fee54c86e24d18fd387deccfbde5317f463d6f6443cbb1a7162c7a48e3e4ab14481f301e5e
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  Gridium is built to support the Page Object Design pattern for automated User Interface tests. Gridium works best when page objects are abstracted from the test files. While Rspec is preferred, you should still be able to use Gridium with other test runners.
23
23
 
24
- In order to use Gridium, you will first need to need to add it to your automtion suite. Gridium comes with Selenium and is currently configured to run tests on Firefox only. Future updates will be available to run tests on other browsers and Selenium Grid.
24
+ In order to use Gridium, you will first need to need to add it to your automation suite. Gridium comes with Selenium and is currently configured to run tests on Firefox only. Future updates will be available to run tests on other browsers and Selenium Grid.
25
25
 
26
26
  #### Spec Helper
27
27
  To get started using Gridium add the Gem to your automated test library. Include the following section in your `spec_helper.rb` file:
@@ -40,6 +40,10 @@ Gridium.configure do |config|
40
40
  config.highlight_verifications = true
41
41
  config.highlight_duration = 0.100
42
42
  config.screenshot_on_failure = false
43
+ config.screenshots_to_s3 = false
44
+ config.project_name_for_s3 = 'gridium'
45
+ config.subdirectory_name_for_s3 = '' #rely on GridiumS3 default
46
+ config.testrail = false
43
47
  end
44
48
  ```
45
49
 
@@ -48,7 +52,10 @@ Additionally, there are some options that should be configured in the `Rspec.con
48
52
  ```ruby
49
53
  RSpec.configure do |config|
50
54
  include Gridium
55
+ tr = Gridium::TestRail.new #this would only work if Gridium.config.testrail is set to true
51
56
  config.before :all do
57
+ # Set up new testrail run
58
+ tr.add_run("Test Run Name", "Test Run description")
52
59
  # Create the test report root directory
53
60
  report_root_dir = File.expand_path(File.join(Gridium.config.report_dir, 'spec_reports'))
54
61
  Dir.mkdir(report_root_dir) if not File.exist?(report_root_dir)
@@ -70,6 +77,15 @@ include Gridium
70
77
  Spec_data.load_suite_state
71
78
  Spec_data.load_spec_state
72
79
  end #end before:all
80
+
81
+ config.after :example, testrail_id: proc { |value| !value.nil? } do |example|
82
+ tr.add_case(example) #Add the results of the case to TestRail
83
+ end
84
+
85
+ config.after :all do
86
+ tr.close_run #closes out the TestRun
87
+ end
88
+
73
89
  end #end Rspec.config
74
90
  ```
75
91
 
@@ -86,14 +102,40 @@ You may be saying to yourself - 'Holy Crap that's a lot of settings!'. Yeah. I
86
102
  `config.visible_elements_only = true`: With this enabled Gridium will only find VISIBLE elements on the page. Hidden elements or non-enabled elements will not be matched.
87
103
  `config.log_level = :debug`: There are a few levels here `:debug` `:info` `:warn` `:error` and `:fatal`. Your Gridium tests objects can have different levels of logging. Adjusting this setting will turn those log levels on or off depending on your needs at the time.
88
104
  `config.highlight_verifications = true`: Will highlight the element Gridium finds in the browser. This makes watching tests run easier to follow, although it does slow the test execution time down. Recommend this is turned off for automated tests running in Jenkins or headless mode.
89
- `config.highlight_duration = 0.100`: How long should the element be highlighted (in miliseconds) before the action is performed on the element.
105
+ `config.highlight_duration = 0.100`: How long should the element be highlighted (in milliseconds) before the action is performed on the element.
90
106
  `config.screenshot_on_failure = false`: Take a screenshot on failure. On or off. Obviously.
107
+ `config.screenshots_to_s3 = false`: This option allows users to save screenshots to an s3 bucket. AWS S3 buckets need to be setup and configured in AWS. Environment variables needs to be set for S3. See environment variables section.
108
+ `config.project_name_for_s3 = 'GRIDIUM'`: This will be appended to the filename in the front of the file. Should not contain spaces.
109
+ `config.subdirectory_name_for_s3 = 'TEST NAME'`: This will be the directory in S3 root to store the files. Used primarily to differentiate between project artifacts in the same s3 bucket.
110
+ `config.testrail = true`: This to enable TestRail integration. With this turned on, test results will be updated in your TestRail instance.
111
+
112
+ ##### Environment variables
113
+
114
+ S3 Features require the following Environment variables be set on the machine running the Gridium Test:
115
+
116
+ ```
117
+ S3_ACCESS_KEY_ID
118
+ S3_SECRET_ACCESS_KEY
119
+ S3_DEFAULT_REGION
120
+ S3_ROOT_BUCKET
121
+ ```
122
+
123
+ For TestRail Integration the following Environment variables are required:
124
+
125
+ ```
126
+ GRIDIUM_TR_URL
127
+ GRIDIUM_TR_USER
128
+ GRIDIUM_TR_PW
129
+ GRIDIUM_TR_PID
130
+ ```
131
+
91
132
 
92
133
  ##### Rspec Configuration Options:
93
- The first bit of the Rspec configuration section is used to set up a log file directory. I like to have log files kept in seperate dated directories. However, that may not be needed depending on your preference. If you choose to use a single directory for your log files, you will need to make sure that the log file name is unique, as screenshots are saved into the same directory. Whichever method you prefer, you will need to setup the Gridium Log Device.
94
- `Log.add_device(File.open(File.join(current_run_report_dir, "spec_logging_output.log"), File::WRONLY | File::APPEND | File::CREAT))`: This tells Gridium where to write the logs to for any paticular test run.
134
+ The first bit of the Rspec configuration section is used to set up a log file directory. I like to have log files kept in separate dated directories. However, that may not be needed depending on your preference. If you choose to use a single directory for your log files, you will need to make sure that the log file name is unique, as screenshots are saved into the same directory. Whichever method you prefer, you will need to setup the Gridium Log Device.
135
+ `Log.add_device(File.open(File.join(current_run_report_dir, "spec_logging_output.log"), File::WRONLY | File::APPEND | File::CREAT))`: This tells Gridium where to write the logs to for any particular test run.
136
+
137
+ The following is used for throughout the test execution and displayed in the logs to quickly access how many of each particular failure your tests are discovering. This can be used for quick metrics and climate checks of your application under test.
95
138
 
96
- The following is used for throughout the test execution and displayed in the logs to quickly access how many of each paticular failure your tests are discovering. This can be used for quick metrics and climate checks of your aplication under test.
97
139
  ```ruby
98
140
  # Reset Suite statistics
99
141
  $verifications_total = 0
@@ -105,11 +147,11 @@ Spec_data.load_suite_state
105
147
  Spec_data.load_spec_state
106
148
  ```
107
149
 
108
- ##Page Objects
150
+ ## Page Objects
109
151
 
110
152
  Page objects are required for Gridium. Page objects abstract the functionality of the page away from the test. There's a million reasons why page objects are the way to go. Not the least of all is that it helps you maintain your tests.
111
153
 
112
- ####Sample Page Object
154
+ #### Sample Page Object
113
155
  ```ruby
114
156
  include Gridium
115
157
  class LoginPage < Page
@@ -129,22 +171,22 @@ class LoginPage < Page
129
171
  end
130
172
  ```
131
173
 
132
- Notice that to use Gridium functionality, Gridium needs to be included at the top of the page object definition. Also notice that the LoginPage inherits from the Gridium `Page`. The `Page` object in gridium provides methods that emulate some of Capybara's API. For more information checkout the `lib/page.rb`.
174
+ Notice that to use Gridium functionality, Gridium needs to be included at the top of the page object definition. Also notice that the LoginPage inherits from the Gridium `Page`. The `Page` object in Gridium provides methods that emulate some of Capybara's API. For more information checkout the `lib/page.rb`.
133
175
 
134
176
  Page object are made up of Elements. The methods on the page object tells the test how interact with the elements. For example, the Login method shown in the example sets the Username field, the password field and then clicks the login button.
135
177
 
136
178
  This action will return a new page, that our test is setup to handle.
137
179
 
138
- ##Elements
180
+ ## Elements
139
181
 
140
182
  Elements are the building blocks of page objects. Elements are anything that a user, or a test would care about on the page. To create a new Element, you will need three things:
141
- *Element Name - A human readable string used to identify the element to the tester. Used primarily in the log file.
142
- *Locator Type - `:css` `:xpath` `:link` `:link_text` `:id` `:class` `:class_name` `:name` `:tag_name` are all valid.
143
- *Locator - This is the chosen locator Type string to find the element.
183
+ * Element Name - A human readable string used to identify the element to the tester. Used primarily in the log file.
184
+ * Locator Type - `:css` `:xpath` `:link` `:link_text` `:id` `:class` `:class_name` `:name` `:tag_name` are all valid.
185
+ * Locator - This is the chosen locator Type string to find the element.
144
186
 
145
187
  It's important to remember that Elements are not actually found on the page, until an action is attempted. Only then will the element be attempted to be located.
146
188
 
147
- ##Helper Blog Posts:
189
+ ## Helper Blog Posts:
148
190
  [Beginner's Guide to Automated Testing](http://www.electricsheepdreams.com/2014/12/4/a-beginners-guide-to-automated-test-design)
149
191
  [How to build Xpath locators](http://www.electricsheepdreams.com/2014/12/4/1wq9pbds8m9vktez0qc2w0r0xxlhp6)
150
192
  [Browser Tools and Plugins](http://www.electricsheepdreams.com/2014/12/4/su5lssyi84k4ycrmuaceuswbf9ojwr)
@@ -159,4 +201,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sethus
159
201
  ## License
160
202
 
161
203
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
162
-
data/gridium.gemspec CHANGED
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "bundler", "~> 1.10"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "webmock", "~>2.3"
34
+ spec.add_development_dependency "dotenv", "~>2.1"
33
35
 
34
36
  spec.add_runtime_dependency "selenium-webdriver", ">= 2.50.0", "< 3"
35
37
  spec.add_runtime_dependency "oily_png", "~> 1.2"
@@ -1,3 +1,3 @@
1
1
  module Gridium
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/gridium.rb CHANGED
@@ -8,6 +8,7 @@ require 'element_extensions'
8
8
  require 'element_verification'
9
9
  require 'page'
10
10
  require 's3'
11
+ require 'testrail'
11
12
 
12
13
  module Gridium
13
14
  class << self
@@ -22,6 +23,7 @@ module Gridium
22
23
  class Config
23
24
  attr_accessor :report_dir, :browser_source, :target_environment, :browser, :url, :page_load_timeout, :element_timeout, :visible_elements_only, :log_level
24
25
  attr_accessor :highlight_verifications, :highlight_duration, :screenshot_on_failure, :screenshots_to_s3, :project_name_for_s3, :subdirectory_name_for_s3
26
+ attr_accessor :testrail
25
27
 
26
28
  def initialize
27
29
  @report_dir = Dir.home
@@ -39,6 +41,8 @@ module Gridium
39
41
  @screenshots_to_s3 = false
40
42
  @project_name_for_s3 = 'gridium'
41
43
  @subdirectory_name_for_s3 = '' #rely on GridiumS3 default
44
+ @testrail = false
42
45
  end
43
46
  end
47
+
44
48
  end
data/lib/testrail.rb ADDED
@@ -0,0 +1,116 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ module Gridium
7
+ class TestRail
8
+ ENV_ERROR = "Environment Variable not set!"
9
+
10
+ #TestRail Statuses
11
+ PASSED = 1
12
+ BLOCKED = 2
13
+ UNTESTED = 3
14
+ RETEST = 4
15
+ FAILED = 5
16
+
17
+ def initialize
18
+ if Gridium.config.testrail
19
+ @url = ENV['GRIDIUM_TR_URL'].empty? || ENV['GRIDIUM_TR_URL'].nil? ? ENV_ERROR : ENV['GRIDIUM_TR_URL'] + '/index.php?/api/v2/'
20
+ @user = ENV['GRIDIUM_TR_USER'].empty? || ENV['GRIDIUM_TR_USER'].nil? ? ENV_ERROR : ENV['GRIDIUM_TR_USER']
21
+ @password = ENV['GRIDIUM_TR_PW'].empty? || ENV['GRIDIUM_TR_PW'].nil? ? ENV_ERROR : ENV['GRIDIUM_TR_PW']
22
+ @pid = ENV['GRIDIUM_TR_PID'].empty? || ENV['GRIDIUM_TR_PID'].nil? ? ENV_ERROR : ENV['GRIDIUM_TR_PID']
23
+ end
24
+ end
25
+
26
+ def add_run(name, desc)
27
+ if Gridium.config.testrail
28
+ Log.debug("[GRIDIUM::TestRail] Creating Test Run: name: #{name} desc: #{desc}")
29
+ if name.nil? || name.empty? then
30
+ raise(ArgumentError, "Empty Run Name - Run name is required")
31
+ end
32
+ r = _send_request('POST', "add_run/#{@pid}", {:name => name, :description => desc, :include_all => false})
33
+ Log.debug("Result: #{r}")
34
+ unless r["id"].nil?
35
+ @runid = r["id"]
36
+ end
37
+ end
38
+ end
39
+
40
+ def close_run
41
+ if Gridium.config.testrail
42
+ Log.debug("[GRIDIUM::TestRail] Closing RunID: #{@runid}")
43
+ unless @runid.nil?
44
+ r = _send_request('POST', "close_run/#{@runid}", nil)
45
+ end
46
+ end
47
+ end
48
+
49
+ def add_case(rspec_test)
50
+ if Gridium.config.testrail
51
+ Log.debug("[GRIDIUM::TestRail] Adding case: #{rspec_test} for RunID: #{@runid}")
52
+ if rspec_test.nil? then
53
+ raise(ArgumentError, "No test data was passed in.")
54
+ end
55
+ unless @runid.nil?
56
+ r = _send_request('POST', "update_run/#{@runid}", {:case_ids => [rspec_test.metadata[:testrail_id]]})
57
+ if rspec_test.exception
58
+ status = FAILED
59
+ message = rspec_test.exception.message
60
+ else
61
+ status = PASSED
62
+ message = ''
63
+ end
64
+ r = _send_request(
65
+ 'POST',
66
+ "add_result_for_case/#{@runid}/#{rspec_test.metadata[:testrail_id]}",
67
+ status_id: status,
68
+ comment: message
69
+ )
70
+ end
71
+ end
72
+ end
73
+
74
+
75
+ private
76
+ def _send_request(method, uri, data)
77
+ url = URI.parse(@url + uri)
78
+ if method == 'POST'
79
+ request = Net::HTTP::Post.new(url.path + '?' + url.query)
80
+ request.body = JSON.dump(data)
81
+ else
82
+ request = Net::HTTP::Get.new(url.path + '?' + url.query)
83
+ end
84
+ request.basic_auth(@user, @password)
85
+ request.add_field('Content-Type', 'application/json')
86
+
87
+ conn = Net::HTTP.new(url.host, url.port)
88
+ if url.scheme == 'https'
89
+ conn.use_ssl = true
90
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
91
+ end
92
+ response = conn.request(request)
93
+
94
+ if response.body && !response.body.empty?
95
+ result = JSON.parse(response.body)
96
+ else
97
+ result = {}
98
+ end
99
+
100
+ if response.code != '200'
101
+ if result && result.key?('error')
102
+ error = '"' + result['error'] + '"'
103
+ else
104
+ error = 'No additional error message received'
105
+ end
106
+ raise APIError.new('TestRail API returned HTTP %s (%s)' %
107
+ [response.code, error])
108
+ end
109
+
110
+ result
111
+ end
112
+ end
113
+
114
+ class APIError < StandardError
115
+ end
116
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Urban
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-30 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: selenium-webdriver
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +160,7 @@ files:
132
160
  - lib/page.rb
133
161
  - lib/s3.rb
134
162
  - lib/spec_data.rb
163
+ - lib/testrail.rb
135
164
  homepage: http://github.com/sethuster/gridium
136
165
  licenses:
137
166
  - MIT
@@ -153,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
182
  version: '0'
154
183
  requirements: []
155
184
  rubyforge_project:
156
- rubygems_version: 2.6.6
185
+ rubygems_version: 2.5.1
157
186
  signing_key:
158
187
  specification_version: 4
159
188
  summary: This Gem is used to make building Selenium Tests without Capybara Easier.