From ea45e4e73e3ad6e086f8372bed78eae3549a2df9 Mon Sep 17 00:00:00 2001 From: depa panjie purnama Date: Wed, 27 Jul 2022 15:32:15 +0700 Subject: [PATCH] :bookmark: improvement (#16) * :heavy_minus_sign: remove register feature * :books: update README content * :books: add korean localisation * :lipstick: npx cli --- README.md | 40 +++++++++++++++++-- src/cli.js | 2 +- .../features/example-authentication.feature | 37 ----------------- .../features/contoh-autentikasi.feature | 37 ----------------- templates/korean/config/cucumber.json | 6 +++ templates/korean/features/support/defaults.js | 6 +++ templates/korean/features/support/steps.js | 24 +++++++++++ .../\354\230\210\354\213\234.feature" | 6 +++ templates/korean/package.json | 26 ++++++++++++ 9 files changed, 105 insertions(+), 79 deletions(-) create mode 100644 templates/korean/config/cucumber.json create mode 100644 templates/korean/features/support/defaults.js create mode 100644 templates/korean/features/support/steps.js create mode 100644 "templates/korean/features/\354\230\210\354\213\234.feature" create mode 100644 templates/korean/package.json diff --git a/README.md b/README.md index 5efe1cd..900ada6 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,50 @@ # pusakatest -image +[![asciicast](https://asciinema.org/a/511165.svg)](https://asciinema.org/a/511165) -## :bulb: how to use -you can simply run this command +## :gear: setup +- make sure `nodejs` and `npm` is already installed. you can verify it using these commands +```bash +node -v +``` +```bash +npm -v +``` +- you can create new folder/directory to setup `pusakatest` and don't forget to change the folder/directory location. for example +```bash +mkdir hello-pusakatest && cd hello-pusakatest +``` +- to setup `pusakatest`, you can simply run this command (and follow the instructions) ```bash npx pusakatest ``` -nothing else after that, just run it! +- nothing else after that, just run it! +```bash +npm run test +``` +- if you want to publish the file report to [Cucumber Reports](https://reports.cucumber.io), just use +```bash +npm run test-publish +``` + +## :bulb: writing feature script +- to create new feature script, just add `.feature` file under `/features` folder/directory +- after that, just re-run it ```bash npm run test ``` +- example: +```gherkin +Feature: API REQRES.IN + + Scenario: Get all users list on REQRES.IN API + Given I make a "POST" request to "https://reqres.in/api/users" + When I receive a response + Then I expect response should have a status "200" +``` ## :bookmark: credits - [pactum-cucumber-boilerplate](https://github.com/pactumjs/pactum-cucumber-boilerplate) - [Dominik Kundel](https://www.twilio.com/blog/how-to-build-a-cli-with-node-js) +- [old-README](https://github.com/depapp/pusakatest/tree/0af4d1c0a0ce712fd2380f8de50b1562134468e4#readme) \ No newline at end of file diff --git a/src/cli.js b/src/cli.js index 27816d1..e7e654f 100644 --- a/src/cli.js +++ b/src/cli.js @@ -36,7 +36,7 @@ async function promptForMissingOptions(options) { type: 'list', name: 'template', message: 'what language/localisation do you want to use?', - choices: ['indonesian', 'english'], + choices: ['indonesian', 'english', 'korean'], default: defaultTemplate, }); } diff --git a/templates/english/features/example-authentication.feature b/templates/english/features/example-authentication.feature index 1913aa3..722f4a9 100644 --- a/templates/english/features/example-authentication.feature +++ b/templates/english/features/example-authentication.feature @@ -2,43 +2,6 @@ Feature: Authentication on ADEQUATESHOP API API Automation with Authentication example - Scenario: User Registration using Valid Data - Given I make a "POST" request to "http://restapi.adequateshop.com/api/authaccount/registration" - And I use random test data to create an account - When I receive a response - Then I expect response should have a status "200" - And I expect response should have a json schema - """ - { - "type": "object", - "properties": { - "code": { - "type": "integer" - }, - "message": { - "type": "string" - }, - "data": { - "type": "object", - "properties": { - "Id": { - "type": "integer" - }, - "Name": { - "type": "string" - }, - "Email": { - "type": "string" - }, - "Token": { - "type": "string" - } - } - } - } - } - """ - Scenario: User Registration using Registered Data Given I make a "POST" request to "http://restapi.adequateshop.com/api/authaccount/registration" And I set body to diff --git a/templates/indonesian/features/contoh-autentikasi.feature b/templates/indonesian/features/contoh-autentikasi.feature index cc84a04..be1d763 100644 --- a/templates/indonesian/features/contoh-autentikasi.feature +++ b/templates/indonesian/features/contoh-autentikasi.feature @@ -2,43 +2,6 @@ Fitur: Autentikasi pada ADEQUATESHOP API Contoh Automation API untuk fitur Autentikasi - Skenario: Registrasi Pengguna Baru Menggunakan Data Yang Sah (Valid) - Dengan Saya melakukan metode "POST" request pada "http://restapi.adequateshop.com/api/authaccount/registration" - Dan Saya menggunakan data test acak - Ketika Saya menerima sebuah response API - Maka Saya mengharapkan status code response API nya "200" - Dan Saya mengharapkan response API nya memiliki schema json - """ - { - "type": "object", - "properties": { - "code": { - "type": "integer" - }, - "message": { - "type": "string" - }, - "data": { - "type": "object", - "properties": { - "Id": { - "type": "integer" - }, - "Name": { - "type": "string" - }, - "Email": { - "type": "string" - }, - "Token": { - "type": "string" - } - } - } - } - } - """ - Skenario: Registrasi Pengguna Baru Menggunakan Data Yang Sudah Ada Dengan Saya melakukan metode "POST" request pada "http://restapi.adequateshop.com/api/authaccount/registration" Dan Saya set data untuk body menggunakan diff --git a/templates/korean/config/cucumber.json b/templates/korean/config/cucumber.json new file mode 100644 index 0000000..63cb194 --- /dev/null +++ b/templates/korean/config/cucumber.json @@ -0,0 +1,6 @@ +{ + "default": { + "language": "ko", + "format": ["summary", "html:cucumber-report.html"] + } +} \ No newline at end of file diff --git a/templates/korean/features/support/defaults.js b/templates/korean/features/support/defaults.js new file mode 100644 index 0000000..4ed7d99 --- /dev/null +++ b/templates/korean/features/support/defaults.js @@ -0,0 +1,6 @@ +const { request, settings } = require('pactum') +const { Before } = require('@cucumber/cucumber') + +Before(() => { + settings.setReporterAutoRun(false) +}) diff --git a/templates/korean/features/support/steps.js b/templates/korean/features/support/steps.js new file mode 100644 index 0000000..ae78cb4 --- /dev/null +++ b/templates/korean/features/support/steps.js @@ -0,0 +1,24 @@ +const pactum = require('pactum') +const { Given, When, Then, Before, After } = require('@cucumber/cucumber') + +let spec = pactum.spec() + +Before(() => { + spec = pactum.spec() +}) + +Given(/^나는 만든다 "(.*)" 요청하다 "(.*)"$/, function (method, endpoint) { + spec[method.toLowerCase()](endpoint) +}) + +When('나는 응답을 받는다', async function () { + await spec.toss() +}) + +Then('응답에 상태가 있어야 합니다. "{int}"', function (code) { + spec.response().should.have.status(code) +}) + +After(() => { + spec.end() +}) diff --git "a/templates/korean/features/\354\230\210\354\213\234.feature" "b/templates/korean/features/\354\230\210\354\213\234.feature" new file mode 100644 index 0000000..73f5a32 --- /dev/null +++ "b/templates/korean/features/\354\230\210\354\213\234.feature" @@ -0,0 +1,6 @@ +기능: API REQRES.IN + + 시나리오: 모든 사용자 목록 가져오기 API REQRES.IN + 조건 나는 만든다 "GET" 요청하다 "https://reqres.in/api/users" + 만일 나는 응답을 받는다 + 그러면 응답에 상태가 있어야 합니다. "200" \ No newline at end of file diff --git a/templates/korean/package.json b/templates/korean/package.json new file mode 100644 index 0000000..58eab61 --- /dev/null +++ b/templates/korean/package.json @@ -0,0 +1,26 @@ +{ + "name": "pusakatest", + "version": "2.0.1", + "description": "pusakatest is an automation testing tool based on pactum using bdd (cucumber) style", + "main": "index.js", + "scripts": { + "test": "cucumber-js --config config/cucumber.json", + "test-publish": "cucumber-js --config config/cucumber.json --publish" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/depapp/pusakatest.git" + }, + "author": "@depapp", + "license": "ISC", + "bugs": { + "url": "https://github.com/depapp/pusakatest/issues" + }, + "homepage": "https://github.com/depapp/pusakatest#readme", + "devDependencies": { + "@cucumber/cucumber": "^8.5.0", + "@faker-js/faker": "^7.3.0", + "mocha": "^10.0.0", + "pactum": "^3.1.13" + } + } \ No newline at end of file