Skip to content

Commit

Permalink
Merge pull request #2 from prashanth-sams/update
Browse files Browse the repository at this point in the history
without run id
  • Loading branch information
prashanth-sams authored Dec 16, 2019
2 parents 6a875a5 + 391011e commit db30838
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 34 deletions.
8 changes: 1 addition & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
source 'https://rubygems.org'

gem 'rspec'
gem 'capybara'
gem 'selenium-webdriver'
gem 'site_prism'
gem "rake"
gem 'byebug'
gem 'testrail-rspec'
gemspec
63 changes: 49 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,39 @@
[![Gem Version](https://badge.fury.io/rb/testrail-rspec.svg)](http://badge.fury.io/rb/testrail-rspec)
> Sync `Rspec` test results with your `testrail` suite. Discover an example with Capybara in this gem source.
**Install gem file**
```
### Features
- [x] Update test results in the existing test run
- [x] Create dynamic test run and update test results in it

## Installation

Add this line to your application's Gemfile:
```ruby
gem 'testrail-rspec'
```

And then execute:
```bash
$ bundle
```

Or install it yourself as:
```bash
$ gem install testrail-rspec
```

**Import the library in your `spec_helper.rb` file**
```
require 'testrail-rspec'
```

**Sync Case ID in your RSpec scenario**
## #Usage outline

Prefix TestRail Case ID on start of your rspec scenario; say, `C860`
#### Sync Case ID

```
Prefix TestRail Case ID on start of your rspec scenario; say, `C845`

```ruby
describe 'Verify Google Home Page' do

scenario 'C845 verify the Google home page' do
Expand All @@ -27,31 +45,48 @@ Prefix TestRail Case ID on start of your rspec scenario; say, `C860`
expect(page).to have_content('Goo gle')
end

scenario 'C850 verify the Google home page to be pending' do
pending
end
scenario 'C853 verify the Google home page to skip' do
skip "skipping this test"
end

end
```

**Config TestRail details**
#### TestRail details

- Create a testrail config file, `testrail_config.yml` in the project parent folder
- Fill up the testrail details on right hand side of the fields (`url`, `user`, `password`, and `run_id`); `run_id` is the dynamically generated id from your testrail account (say, `run_id: 111`)
Provide TestRail details by creating a config file, `testrail_config.yml` in the project parent folder

```
> With existing `Test Run`
- Add testrail details (`url`, `user`, `password`, and `run_id`)
- `run_id` is the dynamically generated id from your testrail account (say, `run_id: 111`)

```yaml
testrail:
url: https://your_url.testrail.io/
user: [email protected]
password: ******
run_id: 111
```
**Update the results through `Hooks` on end of each test**
> Create dynamic `Test Run` and update results

- Add testrail details following `project_id` and `suite_id`
- `project_id` and `suite_id` are the dynamically generated id from your testrail account
- `run_id` is optional here; you may (or) may not have it in this case

```yaml
testrail:
url: https://your_url.testrail.io/
user: [email protected]
password: ******
project_id: 10
suite_id: 110
```

#### Hooks

Update the results through `Hooks` on end of each test
```
config.after(:each) do |scenario|
TestrailRSpec::UpdateTestRails.new(scenario).upload_result
Expand Down
6 changes: 6 additions & 0 deletions lib/testrail-rspec/api-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def send_post(uri, data)
_send_request('POST', uri, data)
end

def create_test_run(uri, data)
@add_test = true
_send_request('POST', uri, data)
end

private
def _send_request(method, uri, data)
url = URI.parse(@url + uri)
Expand All @@ -83,6 +88,7 @@ def _send_request(method, uri, data)

if response.body && !response.body.empty?
result = JSON.parse(response.body)
return result['id'] if @add_test
else
result = {}
end
Expand Down
8 changes: 5 additions & 3 deletions lib/testrail-rspec/update-testrails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ def upload_result
message = "This test scenario was automated and passed successfully"
end

run_id = @config['run_id']
@run_id ||= @config['run_id']
@run_id = @@run_id rescue @@run_id = nil unless @config['run_id']
@run_id = @@run_id = client.create_test_run("add_run/#{@config['project_id']}", { "suite_id": @config['suite_id']}) if @run_id.nil?

if case_id && run_id
if case_id && @run_id
response = client.send_post(
"add_result_for_case/#{run_id}/#{case_id}",
"add_result_for_case/#{@run_id}/#{case_id}",
{ status_id: status_id, comment: message }
)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/testrail-rspec/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TestrailRspec
VERSION = '0.1.2'.freeze
VERSION = '0.1.3'.freeze
end
6 changes: 1 addition & 5 deletions spec/features/google_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
expect(page).to have_content('Goo gle')
end

scenario 'C850 verify the Google home page to be pending' do
pending
end

scenario 'C853 verify the Google home page to skip' do
scenario 'C850 verify the Google home page to skip' do
skip "skipping this test"
end

Expand Down
19 changes: 16 additions & 3 deletions testrail-rspec.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "testrail-rspec/version"

Gem::Specification.new do |s|
s.name = "testrail-rspec"
s.version = "0.1.2"
s.licenses = ['MIT']
s.author = ["Prashanth Sams"]
s.version = TestrailRspec::VERSION
s.authors = ["Prashanth Sams"]
s.email = ['[email protected]']
s.summary = "Sync Rspec test results with your testrail suite. Discover an example with Capybara in this gem source"
s.homepage = "https://github.com/prashanth-sams/testrail-rspec"
s.licenses = ['MIT']
s.files = ["lib/testrail-rspec.rb", "lib/testrail-rspec/api-client.rb", "lib/testrail-rspec/update-testrails.rb", "lib/testrail-rspec/version.rb"]
s.require_paths = ["lib"]
s.metadata = { "documentation_uri" => "https://www.rubydoc.info/github/prashanth-sams/testrail-rspec/master", "source_code_uri" => "https://github.com/prashanth-sams/testrail-rspec", "bug_tracker_uri" => "https://github.com/prashanth-sams/testrail-rspec/issues" }

s.add_development_dependency "bundler"
s.add_development_dependency "rake"
s.add_development_dependency "rspec", "~> 3.0"
s.add_development_dependency "capybara", "~> 3.0"
s.add_development_dependency "selenium-webdriver", "~> 3.0"
s.add_development_dependency "site_prism", "~> 3.0"
s.add_development_dependency "byebug", "~> 11.0"
end
4 changes: 3 additions & 1 deletion testrail_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ testrail:
url: https://your_url.testrail.io/
user: your_username
password: your_password
run_id: your_run_id
run_id: <run_id>
project_id: <project_id>
suite_id: <suite_id>

0 comments on commit db30838

Please sign in to comment.