Artillery Load Testing Keycloak and API
Note on load testing with artillery.
I test with my project that login via keycloak. Then use token from keycloak to call an API and logout from keycloak. After finished, the result will be pushed to artillery.io. You can ses the result there.
Artillery is quite easy to use. You can write YML or you can use your playwright script to run your test. If you need something with more detail, you might want to stick with JMeter.
Let’s start. Sign up to artillery. There is Free plan for developers. You will get your API Key to push the results to artillery.io
Then install artillery in your machine. I use node 20.15.1. You can use nvm to set your node version.
npm install -g artillery@latest
I assume you have keycloak and API server ready. Don’t forget to replace URL and Keycloak Realm.
config:
target: "https://YOUR_API_URL"
payload:
path: 'users.csv'
fields:
- 'username'
- 'password'
phases:
- duration: 10
arrivalRate: 1
rampTo: 2
before:
flow:
- log: 'Login Keycloak'
- post:
url: 'https://YOUR_KEYCLOAK_URL/realms/YOUR_REALM/protocol/openid-connect/token'
form:
grant_type: 'password'
client_id: 'account'
username: '{{ username }}'
password: '{{ password }}'
capture:
- json: $.access_token
as: access_token
- json: $.refresh_token
as: refresh_token
- log: 'Login Pass. Get Token and Refresh Token.'
scenarios:
- flow:
- log: 'Company List'
- get:
url: '/companies?keyword=&pageNo=0&sortBy=company_name&sortOrder=asc'
headers:
access_token: '{{ access_token }}'
- log: 'Company List Pass.'
after:
flow:
- log: 'Logout Keycloak'
- post:
url: 'https://YOUR_KEYCLOAK_URL/realms/YOUR_REALM/protocol/openid-connect/logout'
form:
client_id: 'account'
refresh_token: '{{ refresh_token }}'
- log: 'Logout Keycloak Done.'
users.csv to load user data.
user01,password
Run artillery
artillery run test.yml --record --key YOUR_API_KEY
You will get the result something like this.
You can go see the result at artillery.io.
You can also use playwright to do a load test from Frontend.