In the area of software testing and experimenting the use of a mock-up web server can be regarded as a normal standard. So I asked myself if these procedure could be used within Aria Automation without having to use additional tools or libraries. This blog post describes how exactly this can be achieved in Aria Automation.
How to Mock a Web Server
Node.js - Mock Web Server
A web server can be easily created with the Node.js runtime environment, which is also available in Aria Automation. An easy
example of a web server is available at the Node.js documentation. We use the same approach here, but with a few additions and changes:
- The IP address is detected automatically.
- If /end is specified as the path, the execution of the Mock Web Server is terminated.
Hello World is returned with every request. The web server is simply created as an action of the Node.js runtime environment.
When the web server is started, the IP address is displayed in the log window.
And when a request is executed, this is also displayed in the log window.
Once the web server has been started, it is available to the entire Aria Automation environment. Requests can be executed against it and the programmed response is delivered.
Node.js - Web Client
The following code is a web client, also based on Node.js. It can be used to execute a request, so that Hello World is returned and displayed. Also the web server can be terminated, via the Action parameter by specifying end. The IP address is also detected automatically here. The web client is simply created as another action of the Node.js runtime environment.
If the Web Client is executed without action parameter, only specifying the port, Hello World is returned.
This example already shows that different instances of Node.js actions can communicate with each other via http.
PowerShell - Web Client
The following code is the same web client as above, but in PowerShell.
This example shows that different instances of different runtime environments, in this case a PowerShell action, can communicate with each other via http.
Python - WebClient - Terminate Mock Web Server
The following Python code is also a web client. This example shows how the web server can be terminated with a call to the Python runtime environment.
Here the log window of the Node.js mock web server. It is terminated after it has received the request from the Python action.
JavaScript - isHostReachable and getContent
Last but not least two examples of calling the web server from the JavaScript runtime environment.
The isHostReachable method of the System object can be used to check whether the web server can be reached.
A GET request is executed with the getContent method of the URL object. Invoking this method returns Hello World as expected.
Conclusion
As we can see, a web server can be created and used within the Aria Automation environment very easily using on-board resources. Communication and control between the different runtime environments is possible without any problems. As shown in this example, Node.js can "talk" to the Python, PowerShell and JavaScript runtime environment, and this is of course also possible vice-versa. This approach allows us to combine the features of the different runtime environments of Aria Automation with their different programming languages and their specific possibilities.