Skip to content

Commit

Permalink
chore: fail test
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep committed Sep 1, 2024
1 parent 958dc6a commit 5fafad7
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"pactum"
]
}
6 changes: 5 additions & 1 deletion features/sample.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Feature: Regres

Scenario: Create a new user
Given I create a new user
Then I fetch users
Then I fetch user by id

Scenario: Fetch All Users
Given I fetch all users



27 changes: 25 additions & 2 deletions features/support/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
const { request, settings } = require('pactum');
const { Before } = require('@cucumber/cucumber');
const { request, settings, events } = require('pactum');
const { Before, AfterStep } = require('@cucumber/cucumber');


Before(() => {
request.setBaseUrl('https://reqres.in');
settings.setReporterAutoRun(false);
});

let req = {};
let res = {};

AfterStep(function(ctx) {
this.attach(JSON.stringify({req, res}), { mediaType: 'application/json' });
});

events.pactumEvents.on(events.EVENT_TYPES.AFTER_RESPONSE, (ctx) => {

req = {};
req.url = ctx.request.url;
req.method = ctx.request.method;
req.body = ctx.request.body;
req.headers = ctx.request.headers;

res = {};
res.status = ctx.response.statusCode;
res.body = ctx.response.body;
res.headers = ctx.response.headers;

});
17 changes: 16 additions & 1 deletion features/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Given('I create a new user', async () => {
});
});

Given('I fetch users', async () => {
Given('I fetch user by id', async () => {
await spec()
.get('/api/users/2')
.expectStatus(200)
Expand All @@ -32,4 +32,19 @@ Given('I fetch users', async () => {
"avatar": "https://reqres.in/img/faces/2-image.jpg"
}
});
});

Given('I fetch all users', async () => {
await spec()
.get('/api/users')
.expectStatus(200)
.expectJsonLike({
"data": {
"id": 2,
"email": "[email protected]",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-image.jpg"
}
});
});
36 changes: 24 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@cucumber/cucumber": "^10.8.0",
"pactum": "^3.7.0"
"@cucumber/cucumber": "^10.9.0",
"pactum": "^3.7.1"
}
}
61 changes: 56 additions & 5 deletions reports/cucumber-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"hidden": true,
"result": {
"status": "passed",
"duration": 521791
"duration": 364415
}
},
{
Expand All @@ -27,21 +27,72 @@
},
"result": {
"status": "passed",
"duration": 385459290
}
"duration": 465891833
},
"embeddings": [
{
"data": "eyJyZXEiOnsidXJsIjoiaHR0cHM6Ly9yZXFyZXMuaW4vYXBpL3VzZXJzIiwibWV0aG9kIjoiUE9TVCIsImJvZHkiOnsibmFtZSI6Im1vcnBoZXVzIiwiam9iIjoibGVhZGVyIn19LCJyZXMiOnsic3RhdHVzIjoyMDEsImJvZHkiOnsibmFtZSI6Im1vcnBoZXVzIiwiam9iIjoibGVhZGVyIiwiaWQiOiIxMCIsImNyZWF0ZWRBdCI6IjIwMjQtMDktMDFUMTI6NTg6MDcuMDExWiJ9LCJoZWFkZXJzIjp7ImRhdGUiOiJTdW4sIDAxIFNlcCAyMDI0IDEyOjU4OjA3IEdNVCIsImNvbnRlbnQtdHlwZSI6ImFwcGxpY2F0aW9uL2pzb247IGNoYXJzZXQ9dXRmLTgiLCJjb250ZW50LWxlbmd0aCI6IjgzIiwiY29ubmVjdGlvbiI6ImtlZXAtYWxpdmUiLCJyZXBvcnQtdG8iOiJ7XCJncm91cFwiOlwiaGVyb2t1LW5lbFwiLFwibWF4X2FnZVwiOjM2MDAsXCJlbmRwb2ludHNcIjpbe1widXJsXCI6XCJodHRwczovL25lbC5oZXJva3UuY29tL3JlcG9ydHM/dHM9MTcyNTE5NTQ4NyZzaWQ9YzRjOTcyNWYtMWFiMC00NGQ4LTgyMGYtNDMwZGYyNzE4ZTExJnM9ZTBaRXp0TktVR0VwaHpGbzJtZjJ1Y250eE1hbGttNmU3aDZNdmZHQiUyRm1JJTNEXCJ9XX0iLCJyZXBvcnRpbmctZW5kcG9pbnRzIjoiaGVyb2t1LW5lbD1odHRwczovL25lbC5oZXJva3UuY29tL3JlcG9ydHM/dHM9MTcyNTE5NTQ4NyZzaWQ9YzRjOTcyNWYtMWFiMC00NGQ4LTgyMGYtNDMwZGYyNzE4ZTExJnM9ZTBaRXp0TktVR0VwaHpGbzJtZjJ1Y250eE1hbGttNmU3aDZNdmZHQiUyRm1JJTNEIiwibmVsIjoie1wicmVwb3J0X3RvXCI6XCJoZXJva3UtbmVsXCIsXCJtYXhfYWdlXCI6MzYwMCxcInN1Y2Nlc3NfZnJhY3Rpb25cIjowLjAwNSxcImZhaWx1cmVfZnJhY3Rpb25cIjowLjA1LFwicmVzcG9uc2VfaGVhZGVyc1wiOltcIlZpYVwiXX0iLCJ4LXBvd2VyZWQtYnkiOiJFeHByZXNzIiwiYWNjZXNzLWNvbnRyb2wtYWxsb3ctb3JpZ2luIjoiKiIsImV0YWciOiJXL1wiNTMtWnh0aWpzSUJ4eEtLUTU5ZVIvaFJoZGNlZDRNXCIiLCJ2aWEiOiIxLjEgdmVndXIiLCJjZi1jYWNoZS1zdGF0dXMiOiJEWU5BTUlDIiwic2VydmVyIjoiY2xvdWRmbGFyZSIsImNmLXJheSI6IjhiYzU2ZTBmYmNmNzJlODUtSFlEIn19fQ==",
"mime_type": "application/json"
}
]
},
{
"arguments": [],
"keyword": "Then ",
"line": 9,
"name": "I fetch users",
"name": "I fetch user by id",
"match": {
"location": "features/support/steps.js:22"
},
"result": {
"status": "passed",
"duration": 11984208
"duration": 11961207
},
"embeddings": [
{
"data": "eyJyZXEiOnsidXJsIjoiaHR0cHM6Ly9yZXFyZXMuaW4vYXBp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cyNWYtMWFiMC00NGQ4LTgyMGYtNDMwZGYyNzE4ZTExJnM9ZUloUmxISlhQem9qNHpxS3AwdkdLayUyQksyM1dHbEhGdHp6JTJGQThKUDIzbzglM0QiLCJuZWwiOiJ7XCJyZXBvcnRfdG9cIjpcImhlcm9rdS1uZWxcIixcIm1heF9hZ2VcIjozNjAwLFwic3VjY2Vzc19mcmFjdGlvblwiOjAuMDA1LFwiZmFpbHVyZV9mcmFjdGlvblwiOjAuMDUsXCJyZXNwb25zZV9oZWFkZXJzXCI6W1wiVmlhXCJdfSIsIngtcG93ZXJlZC1ieSI6IkV4cHJlc3MiLCJhY2Nlc3MtY29udHJvbC1hbGxvdy1vcmlnaW4iOiIqIiwiZXRhZyI6IlcvXCIxMTgtcGJkd3dGbzlTS05oRDNMeDVpSEp5bmdwcTAwXCIiLCJ2aWEiOiIxLjEgdmVndXIiLCJjYWNoZS1jb250cm9sIjoibWF4LWFnZT0xNDQwMCIsImNmLWNhY2hlLXN0YXR1cyI6IkhJVCIsImFnZSI6IjEwMDQiLCJhY2NlcHQtcmFuZ2VzIjoiYnl0ZXMiLCJzZXJ2ZXIiOiJjbG91ZGZsYXJlIiwiY2YtcmF5IjoiOGJjNTZlMTI2ZTVlMmU4NS1IWUQifX19",
"mime_type": "application/json"
}
]
}
],
"tags": [],
"type": "scenario"
},
{
"description": "",
"id": "regres;fetch-all-users",
"keyword": "Scenario",
"line": 11,
"name": "Fetch All Users",
"steps": [
{
"keyword": "Before",
"hidden": true,
"result": {
"status": "passed",
"duration": 52290
}
},
{
"arguments": [],
"keyword": "Given ",
"line": 12,
"name": "I fetch all users",
"match": {
"location": "features/support/steps.js:37"
},
"result": {
"status": "failed",
"duration": 436505083,
"error_message": "AssertionError [ERR_ASSERTION]: Json doesn't have type 'object' at '$.data' but found 'array'\n at Expect.fail (/Users/anudeep/Documents/my/repos/test-results-reporter/example-pactum-cucumber-testbeats/node_modules/pactum/src/models/expect.js:461:12)\n at Expect._validateJsonLike (/Users/anudeep/Documents/my/repos/test-results-reporter/example-pactum-cucumber-testbeats/node_modules/pactum/src/models/expect.js:229:21)\n at Expect.validate (/Users/anudeep/Documents/my/repos/test-results-reporter/example-pactum-cucumber-testbeats/node_modules/pactum/src/models/expect.js:55:10)\n at Tosser.validateResponse (/Users/anudeep/Documents/my/repos/test-results-reporter/example-pactum-cucumber-testbeats/node_modules/pactum/src/models/Tosser.js:243:23)\n at Tosser.validate (/Users/anudeep/Documents/my/repos/test-results-reporter/example-pactum-cucumber-testbeats/node_modules/pactum/src/models/Tosser.js:210:18)\n at Tosser.toss (/Users/anudeep/Documents/my/repos/test-results-reporter/example-pactum-cucumber-testbeats/node_modules/pactum/src/models/Tosser.js:46:18)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
},
"embeddings": [
{
"data": "eyJyZXEiOnsidXJsIjoiaHR0cHM6Ly9yZXFyZXMuaW4vYXBpL3VzZXJzIiwibWV0aG9kIjoiR0VUIn0sInJlcyI6eyJzdGF0dXMiOjIwMCwiYm9keSI6eyJwYWdlIjoxLCJwZXJfcGFnZSI6NiwidG90YWwiOjEyLCJ0b3RhbF9wYWdlcyI6MiwiZGF0YSI6W3siaWQiOjEsImVtYWlsIjoiZ2VvcmdlLmJsdXRoQHJlcXJlcy5pbiIsImZpcnN0X25hbWUiOiJHZW9yZ2UiLCJsYXN0X25hbWUiOiJCbHV0aCIsImF2YXRhciI6Imh0dHBzOi8vcmVxcmVzLmluL2ltZy9mYWNlcy8xLWltYWdlLmpwZyJ9LHsiaWQiOjIsImVtYWlsIjoiamFuZXQud2VhdmVyQHJlcXJlcy5pbiIsImZpcnN0X25hbWUiOiJKYW5ldCIsImxhc3RfbmFtZSI6IldlYXZlciIsImF2YXRhciI6Imh0dHBzOi8vcmVxcmVzLmluL2ltZy9mYWNlcy8yLWltYWdlLmpwZyJ9LHsiaWQiOjMsImVtYWlsIjoiZW1tYS53b25nQHJlcXJlcy5pbiIsImZpcnN0X25hbWUiOiJFbW1hIiwibGF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