-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13ac985
commit 7b81026
Showing
12 changed files
with
5,647 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Build | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
push: | ||
branches: | ||
- master | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [windows-latest, ubuntu-latest, macos-latest] | ||
node-version: [8.x, 10.x, 12.x, 14.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm run test | ||
env: | ||
CI: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Anudeep | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# pactum-cucumber-boilerplate | ||
|
||
Boilerplate project to run REST API tests with [Cucumber](https://cucumber.io) and [PactumJS](https://pactumjs.github.io) | ||
|
||
## Sample Test Case | ||
|
||
```gherkin | ||
Feature: Regres | ||
In order to keep Regres api stable | ||
As a tester | ||
I want to make sure that everything works as expected | ||
Scenario: Get A User With Id | ||
Given I make a GET request to /api/users/{id} | ||
And I set path param id to $S{UserId} | ||
When I receive a response | ||
Then I expect response should have a status 200 | ||
And I expect response should have a json like | ||
""" | ||
{ | ||
"data": { | ||
"id": 7 | ||
} | ||
} | ||
""" | ||
``` | ||
|
||
## Running Tests | ||
|
||
```sh | ||
npm run test | ||
``` | ||
|
||
## Gherkin Expressions | ||
|
||
Sample Step Definitions | ||
|
||
```gherkin | ||
Given | ||
I make a (.*) request to (.*) | ||
I set path param (.*) to (.*) | ||
I set query param (.*) to (.*) | ||
I set header (.*) to (.*) | ||
I set basic authentication credentials (.*) and (.*) | ||
I set body to | ||
I set multipart form data (.*) to (.*) | ||
I upload file at (.*) | ||
When | ||
I receive a response | ||
Then | ||
I expect response should have a status {int} | ||
I expect response header (.*) should be (.*) | ||
I expect response header (.*) should have (.*) | ||
I expect response should have a json | ||
I expect response should have a json at (.*) | ||
I expect response should have a json like | ||
I expect response should have a json like at (.*) | ||
I expect response should have a json schema | ||
I expect response should have a json schema at (.*) | ||
I expect response should have a body | ||
I expect response should have {string} | ||
I store response at (.*) as (.*) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Feature: Regres | ||
|
||
In order to keep Regres api stable | ||
As a tester | ||
I want to make sure that everything works as expected | ||
|
||
Scenario: Get A User With Id | ||
Given I make a GET request to /api/v1/employees/1 | ||
And I set path param id to $S{UserId} | ||
When I receive a response | ||
Then I expect response should have a status 200 | ||
And I expect response should have a json like | ||
""" | ||
{ | ||
"id": 1, | ||
"firstName": "Razvan", | ||
"lastName": "Smith", | ||
"dob": "1994-05-06", | ||
"email": "[email protected]" | ||
} | ||
""" | ||
|
||
Scenario: Create A User | ||
Given I make a POST request to /api/v1/employees | ||
And I set body to | ||
""" | ||
{ | ||
"dob": "1967-06-06", | ||
"email": "[email protected]", | ||
"firstName": "John", | ||
"lastName": "Bravo" | ||
} | ||
""" | ||
When I receive a response | ||
Then I expect response should have a status 201 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { request, settings } = require('pactum'); | ||
const { Before } = require('@cucumber/cucumber'); | ||
|
||
Before(() => { | ||
request.setBaseUrl('https://qa-practice.herokuapp.com'); | ||
settings.setReporterAutoRun(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
const pactum = require('pactum'); | ||
const { Given, When, Then, Before, After } = require('@cucumber/cucumber'); | ||
|
||
let spec = pactum.spec(); | ||
|
||
Before(() => { | ||
spec = pactum.spec(); | ||
}); | ||
|
||
Given(/^I make a (.*) request to (.*)$/, function (method, endpoint) { | ||
spec[method.toLowerCase()](endpoint); | ||
}); | ||
|
||
Given(/^I set path param (.*) to (.*)$/, function (key, value) { | ||
spec.withPathParams(key, value); | ||
}); | ||
|
||
Given(/^I set query param (.*) to (.*)$/, function (key, value) { | ||
spec.withQueryParams(key, value); | ||
}); | ||
|
||
Given(/^I set basic authentication credentials (.*) and (.*)$/, function (username, password) { | ||
spec.withAuth(username, password); | ||
}); | ||
|
||
Given(/^I set header (.*) to (.*)$/, function (key, value) { | ||
spec.withHeaders(key, value); | ||
}); | ||
|
||
Given(/I set body to/, function (body) { | ||
try { | ||
spec.withJson(JSON.parse(body)); | ||
} catch(error) { | ||
spec.withBody(body); | ||
} | ||
}); | ||
|
||
Given(/^I upload file at (.*)$/, function (filePath) { | ||
spec.withFile(filePath); | ||
}); | ||
|
||
Given(/^I set multi-part form param (.*) to (.*)$/, function (key, value) { | ||
spec.withMultiPartFormData(key, value); | ||
}); | ||
|
||
When('I receive a response', async function () { | ||
await spec.toss(); | ||
}); | ||
|
||
Then('I expect response should have a status {int}', function (code) { | ||
spec.response().should.have.status(code); | ||
}); | ||
|
||
Then(/^I expect response header (.*) should be (.*)$/, function (key, value) { | ||
spec.response().should.have.header(key, value) | ||
}); | ||
|
||
Then(/^I expect response header (.*) should have (.*)$/, function (key, value) { | ||
spec.response().should.have.headerContains(key, value) | ||
}); | ||
|
||
Then(/^I expect response should have a json$/, function (json) { | ||
spec.response().should.have.json(JSON.parse(json)); | ||
}); | ||
|
||
Then(/^I expect response should have a json at (.*)$/, function (path, value) { | ||
spec.response().should.have.json(path, JSON.parse(value)); | ||
}); | ||
|
||
Then(/^I expect response should have a json like$/, function (json) { | ||
spec.response().should.have.jsonLike(JSON.parse(json)); | ||
}); | ||
|
||
Then(/^I expect response should have a json like at (.*)$/, function (path, value) { | ||
spec.response().should.have.jsonLike(path, JSON.parse(value)); | ||
}); | ||
|
||
Then(/^I expect response should have a json schema$/, function (json) { | ||
spec.response().should.have.jsonSchema(JSON.parse(json)); | ||
}); | ||
|
||
Then(/^I expect response should have a json schema at (.*)$/, function (path, value) { | ||
spec.response().should.have.jsonSchema(path, JSON.parse(value)); | ||
}); | ||
|
||
Then(/^I expect response should have a body$/, function (body) { | ||
spec.response().should.have.body(body); | ||
}); | ||
|
||
Then('I expect response should have {string}', function (handler) { | ||
spec.response().should.have._(handler); | ||
}); | ||
|
||
Then(/^I store response at (.*) as (.*)$/, function (path, name) { | ||
spec.stores(name, path); | ||
}); | ||
|
||
After(() => { | ||
spec.end(); | ||
}); |
Oops, something went wrong.