Usually when you are deploying your app to a production environment you want to check if you have enough CPUs, memory and servers to deal with the load. In order to test this you have to do performance testing.
In case of performance testing of CUBA based web application we use the following tools:
- Apache JMeter 4.0: link to download
- Mozilla Firefox 61.0.1
This tutorials uses:
- CUBA Platform 6.9.2
- CUBA Studio 6.9.1
Configure application for testing
Add the following properties to the web-app.properties file to enable tests in your CUBA application:
- Enable cuba.testMode enables test ids for components;
- Enable cuba.performanceTestMode to disable âCSRFâ security.
JMeter scenario
Adding Elements to Test Plan
- Add âThread Groupâ to âTest Planâ:
Test Plan -> Add -> Threads (Users) -> Thread Group
- Add âHTTP(S) Test Script Recorderâ to âTest Planâ:
Test Plan -> Add -> Non-Test Elements -> HTTP(S) Test Script Recorder
Change the default port of the âHTTP(S) Test Script Recorderâ proxy to 9090 or another required one. 8080 is used for our application.
On the âRequests Filteringâ tab, specify the following code to exclude unnecessary requests (JS, CSS, etc.):
(?i).*\.(bmp|css|js|gif|ico|jpe?g|png|swf|woff|txt)
(?i).*\.(bmp|css|js|gif|ico|jpe?g|png|swf|woff|txt)[\?;].*
Or you can add it separately:
.*\.png
.*\.jpg
.*\.gif
- Also, add âView Results Treeâ to âHTTP(S) Test Script Recorderâ
HTTP(S) Test Script Recorder -> Add -> Listener -> View Results Tree
It shows data for all recorded requests.
Adding Elements to Thread Group
- Add âHTTP Cookie Managerâ to âThread Groupâ :
Thread Group -> Add -> Config Element -> HTTP Cookie Manager
Check âClear cookies each iterationâ in this manager.
- Add âUser Defined Variablesâ to âThread Groupâ:
Thread Group -> Add -> Config Element -> User Defined Variables
We will use two variables:
- host address:
${__P(host, localhost)}
- port:
${__P(port, 8080)}
- Then add âRecording Controllerâ to âThread Groupâ:
Thread Group -> Add -> Logic Controller -> Recording Controller
Requests from the application will be saved in this controller. Also, add a tree which shows info about all recorded requests when they are played.
Recording Controller -> Add -> Listener -> View Results Tree
So, the final scenario tree is the following:
Configure Firefox proxy
Configure Firefox to use localhost on port 9090 (like in HTTP(S) Test Script Recorder proxy):
- Open Firefox
- Open browser options
- Go to proxy settings
- Select the âManual proxy configurationâ
- Set HTTP Proxy to âlocalhostâ and Port to â9090â
- Check âUse this proxy server for all protocolsâ option
- Check that localhost and 127.0.0.1 NOT in âNo Proxy forâ list, otherwise remove them
- Click OK and exit from the menu
- Restart Firefox
Recording Requests
Our test will do 3 simple steps:
- Login to the application;
- Open âUsersâ screen;
- Logout.
To record request do the following steps:
-
In the âHTTP(S) Test Script Recorderâ click âStartâ button. We will see the information dialog: âRoot CA certificate ApacheJMeterTemporaryRootCA created in bin directoryâ. Click the OK button;
-
In Firefox open âhttp://localhost:8080/appâ. We can see that some requests have already saved in âRecording Controllerâ;
-
Login to the application. For the sake of convenience, rename the resulting request.
-
Open âUsersâ screen;
-
Logout;
-
Stop recording.
Now we can delete unnecessary requests, for instance, âapp/Pushâ. After that, the scenario looks as follows:
Play our recorded requests to test it. Click âStartâ button on the buttons panel above.
The warning dialog will appear. It will ask you to save the test plan. Save it with the name âcuba-app-test-scenarioâ.
In the tomcatâs log, we can see that the admin user âlogged inâ and âlogged outâ. âView result treeâ shows info about request and response.
Attached scenario:cuba-app-test-scenario.zip (3.6 KB)