Skip to content

Commit

Permalink
Merge pull request #9 from ErikDahlinghaus/issue-8/capture-tags-on-co…
Browse files Browse the repository at this point in the history
…ntext-blocks

Issue-8: Allows labeling context blocks
  • Loading branch information
prashanth-sams authored Feb 19, 2020
2 parents fdc5ec9 + 08bce63 commit 31ce325
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 32 deletions.
86 changes: 58 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [x] Create dynamic test run and update test results in it
- [x] Update multi-testrail cases from a single automation scenario
- [x] Static status comments on all the scenarios
- [x] Support for RSpec `shared examples`

## Installation

Expand All @@ -30,7 +31,7 @@ $ gem install testrail-rspec
require 'testrail-rspec'
```

## #Usage outline
## Usage outline

#### Update one case at a time
Prefix TestRail Case ID on start of your rspec scenario; say, `C845`
Expand All @@ -54,8 +55,7 @@ Prefix TestRail Case ID on start of your rspec scenario; say, `C845`
```

#### Update multi-cases at a time

Prefix multiple TestRail Case IDs on start of your rspec scenario; say, `C845 C845 your scenario description`
Prefix multiple testrail case id(s) on start of your rspec scenario; say, `C845 C845 your scenario description`

```ruby
describe 'Verify Google Home Page' do
Expand All @@ -75,38 +75,68 @@ Prefix multiple TestRail Case IDs on start of your rspec scenario; say, `C845 C8
end
```

#### TestRail details

Provide TestRail details by creating a config file, `testrail_config.yml` in the project parent folder
#### Use context blocks to update cases
`Context blocks` with testrail case id(s) to make use of `Shared Examples`

> With existing `Test Run`
```ruby
shared_examples 'log in' do
it 'logs in'
end

- Add testrail details (`url`, `user`, `password`, and `run_id`)
- `run_id` is the dynamically generated id from your testrail account (say, `run_id: 111`)
shared_examples 'log out' do
it 'logs out'
end

```yaml
testrail:
url: https://your_url.testrail.io/
user: [email protected]
password: ******
run_id: 111
```
describe 'User login' do
context 'Regular user' do
let(:user) { create(:regular_user) }
context 'C845 single case' do
include_examples 'log in'
end

> Create dynamic `Test Run` and update results
context 'C847' do
include_examples 'log out'
end
end

- 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
context 'Admin user' do
let(:user) { create(:admin_user) }
context 'C850 C853 multi cases' do
include_examples 'log in'
end

```yaml
testrail:
url: https://your_url.testrail.io/
user: [email protected]
password: ******
project_id: 10
suite_id: 110
context 'nothing to update in test-rail' do
include_examples 'log out'
end
end
end
```

#### Configuration

1. Create a config file, `testrail_config.yml` in the project's parent folder
2. Enter the testrail details based on demand
3. To execute tests against the existing `Test Run`,
```yaml
testrail:
url: https://your_url.testrail.io/
user: [email protected]
password: ******
run_id: 111
```
Here, `run_id` is the dynamically generated id from your testrail account (say, `run_id: 111`)

4. To create a dynamic `Test Run` and to update results,
```yaml
testrail:
url: https://your_url.testrail.io/
user: [email protected]
password: ******
project_id: 10
suite_id: 110
```
Here, `project_id` and `suite_id` are the dynamically generated id from your testrail account; `run_id` is optional in this case.

#### Hooks

Update the results through `Hooks` on end of each test
Expand All @@ -116,7 +146,7 @@ config.after(:each) do |scenario|
end
```
**Is there a demo available for this gem?**
**Is there any demo available for this gem?**
Yes, you can use this `capybara` demo as an example, https://github.com/prashanth-sams/testrail-rspec
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
task :test do |_task|
system "rspec spec/features/*_spec.rb"
system "rspec spec/features/google_search_spec.rb"
end
2 changes: 2 additions & 0 deletions lib/testrail-rspec/api-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def _send_request(method, uri, data)
end
response = conn.request(request)

return if response.code == "400"

if response.body && !response.body.empty?
result = JSON.parse(response.body)
return result['id'] if @add_test
Expand Down
2 changes: 1 addition & 1 deletion lib/testrail-rspec/update-testrails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def upload_result
response = {}

case_list = []
@scenario.metadata[:description].split(' ').map do |e|
@scenario.full_description.split(' ').map do |e|
val = e.scan(/\d+/).first
next if val.nil?
case_list << val
Expand Down
2 changes: 0 additions & 2 deletions spec/features/google_search_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'spec_helper'

feature 'Verify Google Home Page' do
before do
@app.google_home.load
Expand Down
33 changes: 33 additions & 0 deletions spec/features/shared_examples_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
shared_examples 'pass' do
it 'pass' do
expect(true).to be true
end
end

shared_examples 'fail' do
it 'fail' do
expect(false).to be true
end
end

describe 'Generic scenarios' do
context 'A regular user can' do
context 'C845' do
include_examples 'pass'
end

context 'C847' do
include_examples 'fail'
end
end

context 'Complex scenarios' do
context 'C850 C853 multi cases' do
include_examples 'pass'
end

context 'Not going to update in test-rail' do
include_examples 'fail'
end
end
end

0 comments on commit 31ce325

Please sign in to comment.