Test Tool
Webswing Test Tool allows you to create test cases for you Swing or JavaFX application running in Webswing. The test tool is a web application and allows you to automate tests using Selenium and other test tools.
Setup
You need to prepare following items to be able to run Webswing Test Tool:
- running instance of Webswing with the application you want to test - e.g. running on http://localhost:8080
- running instance of Webswing Test Tool - e.g. running on http://localhost:8888
- make sure your Webswing application allows connections from the test tool server, see CORS Origins in the Webswing application configuration
- make sure you have following configuration of your Webswing application - Session Mode = ALWAYS_NEW_SESSION, Max. Connections = 100, Auto Logout = OFF, Enable Test Mode = ON
- it is recommended to create and test in a fullscreen window with the same resolution
How to use it?
Start the Test Tool application by running testtool.bat
or testtool.sh
. You can configure server port in application.properties
. You can also define the URL of Selenium Grid Hub and Test Tool for automated testing. Note that config.hubUrl
must be accessible from Test Tool server and config.testToolUrl
must be accessible from Selenium Node. Webswing application must be accessible from both Test Tool and Selenium Node.
Open the Test Tool on http://localhost:8888. You can either create a new test case (or manually test a previously created test case) or automate your saved test cases.
To create a new test case or test manually, enter the URL of application you want to test in the dialog prompt.
Following image link will bring you to our youtube video tutorial:
Manual testing
Following image link will bring you to our youtube video tutorial:
Setup
If your application uses custom startup arguments, you can configure these using the cog button before you start creating your test case.
Create test case
To create a new test case simply click Create Test Case button in the toolbox. Once you click the button the tool starts recording your actions with the Webswing application. Every time you click in the application a new assertion is created. An assertion is a set of properties that will be validated in the test case, like component type, value, path, etc. Path is especially important to be able to find and exactly identify the component while running the test later. These properties are coming from a component tree that is each time requested directly from the application, depending on the application size and structure, connection latency and performance of the environment setup this may take from a few milliseconds up to a few seconds, so please be patient after each click you make when creating a test case.
Create assertion
After you have done some actions and you want to create a custom assertion, use the Create Assertion button. Now hover over the application with your mouse to pick a component in the application view. Click the component which you want to make an assertion for. Now check component properties in the toolbox which you want to be validated by the assertion. Click Add to save the assertion. The recording of test case now continues.
When typing text during test creation, it is recommended to first click on the input or text area component to make sure there is an assertion created for the input component, even if the input component is already focused when it appears in UI. This way you make sure the test tool runner first waits for the input component to appear in the UI and then starts typing the text.
There is a 20 seconds implicit wait period by default. This is a time period that applies to all future created assertions and represents maximum wait time for the assertion to become valid. During this period, (while running a test case) test tool will try to validate the assertion multiple times until it passes. If the assertion fails to validate, the whole test case fails. You can adjust the implicit wait time at the beginning or during the test creation, or you can adjust explicit wait time for each assertion. You can also set a default implicit wait period in application.properties
file test.implicitWaitSec = 20
.
Insert
In addition to assertions you can also insert text, delay or a parameter using the Insert dialog. You can insert text and parameter only at the current position in test case. The inserted value will be immediately applied. Delays can be inserted at any position at any time.
Finish
When you are done with creating the test case click the Finish button. It will save your current recording to the file. You should be able to replay the tests you just recorded, download the test case or clear and record test case again.
Open and replay test case
Open the test case for validation by clicking Open Test Case button and selecting a test case file. To run the test click Run Test. You will now see a playback of your recorded test case. Assertions are validated in the toolbox.
When the test finishes you can see and download the test results in the toolbox.
Automating test cases
Following image link will bring you to our youtube video tutorial:
Open the Test Tool on http://localhost:8888 and click on Automated Testing.
Selenium Grid
First configure your Selenium Grid. Just enter the URL of the Selenium Hub, e.g. http://localhost:4444. The connection will be validated, wait until you see Status: Running. Test Tool also tries to retrieve information about running nodes.
Test suite
To automate Webswing test cases you have created, you need to define a test suite. A test suite is a simple configuration file where you define which test cases to run and other options. The json file has a simple structure. You define multiple tests, for each test you define a set of options:
- name [string] : name to identify the test (optional)
- webswingAppUrl [string] : the URL to your Webswing app you want to test, must be accessible from Selenium node and Test Tool server
- testCaseAbsolutefilePathWithName [string] : full path with file name of the test case file
- csvParamFilePath [string] : full path to CSV file that contains parameters (optional); the parameter names should be in the first row of the file; each row is used for a single run; you need to specify as many rows in the file as many runs of the test you are going to run
- csvParamFileSeparatorChar [string] : character that separates values in the CSV file (optional)
- webswingUsername [string] : username for login (if needed)
- webswingPassword [string] : password for login (if needed)
- platform [string] : the target platform to run the test on, note that this platform must be available in your Selenium Grid (values "WINDOWS", "LINUX", etc.)
- browser [string] : the target browser to run the test in, note that this browser must be available in your Selenium Grid (values "firefox", "chrome", etc.)
- headless [boolean] : if true the browser will start in headless mode (without UI), please check the support of headless mode in the browser you use in Selenium
- enabled [boolean] : enable the test case in test tool runner by default
{
"tests": [{
"name": "Test Firefox",
"webswingAppUrl": "http://localhost:8080/webswing-server/webswing-demo",
"testCaseAbsolutefilePathWithName": "C:\\work\\recorded.json",
"csvParamFilePath": "C:\\work\\params.csv",
"csvParamFileSeparatorChar": ",",
"webswingUsername": "admin",
"webswingPassword": "pwd",
"platform": "WINDOWS",
"browser": "firefox",
"headless": false,
"enabled": true
},
{
"name": "Test Chrome",
"webswingAppUrl": "http://localhost:8080/webswing-server/webswing-demo",
"testCaseAbsolutefilePathWithName": "C:\\work\\recorded.json",
"csvParamFilePath": "C:\\work\\params.csv",
"csvParamFileSeparatorChar": ",",
"webswingUsername": "admin",
"webswingPassword": "pwd",
"platform": "WINDOWS",
"browser": "chrome",
"headless": false,
"enabled": true
}
]
}
You can create or edit a test suite in the Automated testing view.
Now load your test suite file. You should see the test case definitions from the test suite loaded in a table below.
Test runner
Finally, configure the test case runner. Enter the URL of test tool server instance (this can be the same instance, i.e. http://localhost:8888 or some other instance). This URL must be accessible from the Selenium node.
You can choose between a single run-through or a parallel run. Single run-through will simply execute test cases one-by-one, one instance at a time.
With parallel you can set how many instances you want to run at the same time (Max running parallel). Use Ramp-up period to define how long should it take to start the Max running parallel instances. For example if you want 10 instances in parallel and start them in 100 seconds, there will be 1 instance started every 10 seconds. After 100 seconds the next instances start ad-hoc after a previous test finishes. To control how many test will run in total, set Run count. This value is per test, so if you have 3 tests in your test suite and run count set to 10, the runner will run 30 instances total, 10 per each test.
Start automation
Press Start to start the runner. You can see the progress in the test suite table. If the test case is successful the row turns green, otherwise red. For a failed test case you can take a look at a screenshot from the browser from the time the assertion failed or exception occurred. You can can also see exception stack trace from test case and optionally also browser console logs (Chrome).
You can also stop the runner from execution, but please note that the runner is based on thread execution of test cases and it is not possible to stop the tests right away. Stopping the test runner sends a signal to stop running tests and to not run new tests. Currently running tests will eventually end. Some tests may fail due to stopping the runner, so make sure you do not take these into account when evaluating the results.
To see assertion times click Details button which opens a new window with results timings.
For monitoring CPU and memory usage, please do not rely on Webswing Admin Console as it only shows data of currently running sessions. Use resource monitoring tools provided by the operating system or cloud provider.
Selenium Grid Setup
You can setup a Selenium Grid either in your local environment or use a 3rd party service.
For a 3rd party service just search for "Selenium Grid in cloud" or use one of these - https://www.gridlastic.com/, https://saucelabs.com/, https://testingbot.com/, https://seleniumbox.com/.
To setup Selenium Grid yourself, you can also use a great Docker image project Zalenium (https://opensource.zalando.com/zalenium/), which also allows on-demand node scaling.
To create a completely own setup, please refer to https://www.seleniumhq.org/docs/07_selenium_grid.jsp. The setup is really simple. Download Selenium Standalone Server selenium-server-standalone-(version).jar (https://www.seleniumhq.org/download/) and run this to start a hub:
java -jar selenium-server-standalone-(version).jar -role hub
Then for each node you want to start run the same jar as:
java -jar selenium-server-standalone-(version).jar -role node -hub http://localhost:4444/grid/register -port 5556 -nodeConfig nodeConfig.json
Make sure that you pick a different port for every node.
Node configuration file is a simple file with browser capabilities configuration:
{
"capabilities": [
{
"browserName": "firefox",
"platform": "WIN10",
"maxInstances": 5,
"webdriver.gecko.driver": "C:\\work\\selenium\\geckodriver.exe"
},
{
"browserName": "chrome",
"platform": "WIN10",
"maxInstances": 5,
"webdriver.chrome.driver": "C:\\work\\selenium\\chromedriver.exe"
}],
"hub": "http://localhost:4444",
"maxSession": 50
}
Make sure you have your browser drivers installed. You can download them from https://www.seleniumhq.org/download/#thirdPartyDrivers.
Automated test REST API
There is a simple REST API in case you want to execute a test suite with one or more tests from an external application, e.g. for a Webswing server health check.
Send a POST request to http://localhost:8888/rest/runTest, set Content-Type header to application/json with following body:
{
"parallel": false,
"maxRunningParallel": 1,
"rampUpPeriod": 1,
"runCount": 1,
"testCaseParameters": [{
"name": "Test",
"webswingAppUrl": "http://localhost:8080/webswing-server/webswing-demo",
"testCaseAbsolutefilePathWithName": "C:\\work\\recorded.json",
"csvParamFilePath": "C:\\work\\params.csv",
"csvParamFileSeparatorChar": ",",
"webswingUsername": "admin",
"webswingPassword": "pwd",
"platform": "WINDOWS",
"browser": "firefox",
"headless": false,
"enabled": true
}
]
}
Adjust the parameters to your needs, you can also let the tests run in parallel, similar to the automated testing web UI.
Keep in mind that you get response after all the tests you specified finish, so make sure to watch the timeout. If all tests finish successfully you get a 200 OK response, otherwise you get 500 Internal Server Error.
QF Test
For more complex testing of GUI functionality you can use a 3rd party solution QF-Test. QF-Test fully supports Webswing and even combination of Webswing Embedded in a custom JavaScript application. For more information visit: https://www.qfs.de/