Skip to content

Commit

Permalink
update on shared examples
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanth-sams committed Feb 19, 2020
1 parent bce7b92 commit 08bce63
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 44 deletions.
76 changes: 35 additions & 41 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 Down Expand Up @@ -54,7 +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,7 +76,7 @@ Prefix multiple TestRail Case IDs on start of your rspec scenario; say, `C845 C8
```

#### Use context blocks to update cases
Prefix context blocks with TestRail Case IDs to make use of Shared Examples
`Context blocks` with testrail case id(s) to make use of `Shared Examples`

```ruby
shared_examples 'log in' do
Expand All @@ -86,62 +87,55 @@ shared_examples 'log out' do
it 'logs out'
end

describe 'basic user stuff' do
context 'A regular user can' do
describe 'User login' do
context 'Regular user' do
let(:user) { create(:regular_user) }
context 'C1232' do
context 'C845 single case' do
include_examples 'log in'
end

context 'C1233' do
context 'C847' do
include_examples 'log out'
end
end

context 'An admin user can' do
context 'Admin user' do
let(:user) { create(:admin_user) }
context 'C1234' do
context 'C850 C853 multi cases' do
include_examples 'log in'
end

context 'C1235' do
context 'nothing to update in test-rail' do
include_examples 'log out'
end
end
end
```

## TestRail Configuration

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
```
> 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
```
#### 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

Expand All @@ -152,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: 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 08bce63

Please sign in to comment.