This api can be tested from a live server online or from a docker container.
- Import api definition
- Explore and analyze the api endpoints, site and documentation
- Business case analysis - How could users interact with this api?
- Create test scenarios in plain English
- Find api endpoints that match up with each scenario
- Build the test in SoapUI
- Look at ways to make it more automation-friendly
Download OpenAPI file ("openapi":"3.0.2", json format)
Unfortunately SoapUI has a bug where it cannot directly consume this version of OpenAPI from Json. however it does work for Yaml format.
Open Swagger online editor https://editor.swagger.io/#/
Copy paste the open API json into editor and “convert to yaml”
- this also provides a human readable view
In soapUI, open an EMPTY Project type. REST project type currently does not work
Right-click and use “import openAPI spec file” > Soapui creates an interface with all the endpoints (currently there are 8 )
In SoapUI, open Interface editor. Check Endpoints > empty That means we will need to define a baseURL to use this api
If the Interface was created correctly, open Interface Editor and generate a TestSuite
- Since we do not yet have an end-to-end test, defer creation of a Load test
- Return to docs and open the REST tutorial https://bankground.eu/tutorial/accounts/
- Note the options available in menu Authorization Accounts Transactions API Definition
- baseUrl = https://bankground.apimate.eu
- Add this baseURL to your SoapUI Project in the Interface Editor > Endpoints tab
- Peruse the site for this api to get familiar with the content
- Try out requests (using SoapUI, cURL, Swagger-UI page, etc)
- In soapui, this can be done with the Endpoint Explorer or TestStep Editor
- If there are errors, lean on SoapUI docs, alternate tools (ex. cURL), Smartbear Community and web searches to find root causes
Take inventory of the endopints and resources available. Make sure you understand the order in which things can be done.
ex.
- To use any of these endpoints, you need a User
- The User must login in order to do anything
- All requests sent by the User must have a Bearer token
ex.
1. Create user account. Save your password so you can use it later
2. Login to the site (authenticate). Save the token for later.
3. verify your User details
4. Create an Account
5. Verify Account details are correct
6. Add money to the account
7. Check the balance
- Create user =>
POST /users
- provide a payload as per the openapi doc
- Login =>
POST /token
- watch out for the Media Type in your payload
-
Verify User =>
GET /user -
Create an Account =>
POST /accounts -
Verify Account details =>
GET /accounts/{account_id} -
Fund the account =>
POST /accounts/{account_id}
- pay special attention to the request and response schema values for this request
- Check Account balance =>
GET /accounts/{account_id}
- Create a new TestSuite named "End-to-End-Test".
- Name it after this business scenario
- In the TestCase, add a REST request TestStep for each step from the business process
- Get the test working with hard-coded values
- Identify where the values are located and how they are used. This will determine which SoapUI component is most appropriate.
- Property Transfer
- Property Expansion
- Groovy Script
Each page is well linked to point out the appropriate action you need to take. ex. Transactions -> Accounts -> Authorization
- by creating a user, we establish our identify with the system (the authentication)
/users operation
-
POST http method is used to create a record
-
the payload is empty, so we'll need to send a Json formatted payload. See the swagger doc for examples.
-
use the SoapUI Endpoint Explorer or Interface Request Editor to submit a request to the server
-
example response (new User)
HTTP/1.1 201 Created
Date: Fri, 10 May 2024 19:02:08 GMT
Server: Apache
content-length: 139
content-type: application/json
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
{"first_name":"Martha","last_name":"Marsalis","email":"[email protected]","company":"APImate","last_login":"2024-05-10T19:02:09.234351+00:00"}
A specific header and format is needed for the payload of this request.
header -Content-Type:application/x-www-form-urlencoded
payload/body - Media Type -> application/x-www-form-urlencoded
-
this is an adHoc value that you can type into the Dropdown list
-
for more details on this format, see this article
-
encoded format will look like this:
[email protected]&password=hello_goodbye -
sample request using cURL
curl -X 'POST' \
'https://bankground.apimate.eu/token' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'username=mm%40example.net&password=hello_goodbye'
Server returns a token that can be sent with any subsequent requests of the API
todo: try these out on your own. Use the Swagger-UI doc and website as references.
This is a less common request. please do try it out
-
Tutorial
-
swagger online editor https://editor.swagger.io/#/
https://www.soapui.org/docs/rest-testing/working-with-rest-requests/?sbsearch=http%20POST%20form