Skip to main content

SoapUI - Part 3: Automation

SoapUI can be used as well for automated testing purposes. All the test suites developed through this tool can be executed any way without its user interface, for example using an automated build tool.
The SoapUI test cases can be triggered from a command prompt in several ways: a batch file, a shell script, Maven, etc. This post will focus on Apache Maven (http://maven.apache.org/). I will refer to the release 3.1.1. I suggest the readers to have the basics of Maven and Jenkins (http://jenkins-ci.org/) for a better understanding of this post.
First of all create the pom.xml file for your Maven project. Add the Maven repository from which to download the soapui plugin:

<pluginRepositories>
        <pluginRepository>
            <id>eviwarePluginRepository</id>
            <url>http://www.soapui.org/repository/maven2/</url>
        </pluginRepository>

</pluginRepositories>

Then setup the SoapUI plugin for Maven. We are going to use the SoapUI project created in the previous post (http://googlielmo.blogspot.ie/2014/02/soapui-part-2-testing-soap-web-services.html):

<plugins>
            <plugin>
                <groupId>eviware</groupId>
                <artifactId>maven-soapui-plugin</artifactId>
                <version>4.5.1</version>
                <configuration>
                    <projectFile>WheaterForecastTest-soapui-project.xml</projectFile>
                </configuration>
            </plugin>

</plugins>


The XML file WheaterForecastTest-soapui-project.xml is the SoapUI project contaning the test case(s) you want to execute through Maven (have a look at the previous post for it). The final pom.xml should be something like this:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.blogspot.googlielmo</groupId>
    <artifactId>soapui-example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <pluginRepositories>
        <pluginRepository>
            <id>eviwarePluginRepository</id>
            <url>http://www.soapui.org/repository/maven2/</url>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <plugins>
            <plugin>
                <groupId>eviware</groupId>
                <artifactId>maven-soapui-plugin</artifactId>
                <version>4.5.1</version>
                <configuration>
                    <projectFile>WheaterForecastTest-soapui-project.xml</projectFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


You can run it by a shell command through the following Maven command:

mvn eviware:maven-soapui-plugin:test

If everthing goes fine you should see an output like this:

2014-03-09 20:11:39,111 INFO  [DefaultSoapUICore] initialized soapui-settings from [C:\Users\chief\soapui-settings.xml]
2014-03-09 20:11:40,231 INFO  [WsdlProject] Loaded project from [file:/C:/Guglielmo/Code/Maven/SoapUI/WheaterForecastTest-soapui-project.xml]
2014-03-09 20:11:40,977 INFO  [SoapUITestCaseRunner] Running soapUI tests in project [WheaterForecastTest]
2014-03-09 20:11:40,979 INFO  [SoapUITestCaseRunner] Running Project [WheaterForecastTest], runType = SEQUENTIAL
2014-03-09 20:11:40,999 INFO  [SoapUITestCaseRunner] Running soapUI testcase [GetCitiesByCountry TestCase]
2014-03-09 20:11:41,012 INFO  [SoapUITestCaseRunner] running step [GetCitiesByCountry]
2014-03-09 20:11:41,977 INFO  [SoapUITestCaseRunner] Assertion [Contains] has status VALID

2014-03-09 20:11:41,978 INFO  [SoapUITestCaseRunner] Finished running soapUI testcase [GetCitiesByCountry TestCase], time taken: 945ms, status: FINISHED
2014-03-09 20:11:41,982 INFO  [SoapUITestCaseRunner] Running soapUI testcase [GetWeather TestCase]
2014-03-09 20:11:41,983 INFO  [SoapUITestCaseRunner] running step [GetWeather]
2014-03-09 20:11:42,216 INFO  [SoapUITestCaseRunner] Finished running soapUI testcase [GetWeather TestCase], time taken: 232ms, status: FINISHED
2014-03-09 20:11:42,217 INFO  [SoapUITestCaseRunner] Project [WheaterForecastTest] finished with status [FINISHED] in 1231ms


If you look at the lines in bold, you can notice that the test case GetCitiesByCountry defined in the last post was successfully executed the same way as using the tool UI.
This same action could be automated through a build server like Jenkins. Connect to the Jenkins dashboard and create a new job. The type of this job has to be Build a Maven 2/3 project. The name chosen for this job is SoapUI-WheaterForecast. In order for Jenkins to execute this job you need to have Maven configured for it. Check for it in the Maven section of the Configure Jenkins -> Manage System area. In order to configure the job you need to set the Build section this way:




You need to add the full path of the pom.xml file in your Jenkins server and the same Maven command and params used to run the TestCase from a command line. Save the changes and run manually the job. At the end of the execution go to the jobs console output for this build and you should see the same output as for the run from a command line:



This job can then scheduled the usual way for any Jenkins job.

This is what you should have learned from this example: it's possible to automate the verification and test of APIs using SoapUI. The chances of securing the delivery of high quality APIs will be drastically improved, compared to when testing services using homegrown API clients. This helps to save a lot of time and allows to focus on the real problem, testing, instead of the problem nested creating custom test tools.

Comments

Popular posts from this blog

Streamsets Data Collector log shipping and analysis using ElasticSearch, Kibana and... the Streamsets Data Collector

One common use case scenario for the Streamsets Data Collector (SDC) is the log shipping to some system, like ElasticSearch, for real-time analysis. To build a pipeline for this particular purpose in SDC is really simple and fast and doesn't require coding at all. For this quick tutorial I will use the SDC logs as example. The log data will be shipped to Elasticsearch and then visualized through a Kibana dashboard. Basic knowledge of SDC, Elasticsearch and Kibana is required for a better understanding of this post. These are the releases I am referring to for each system involved in this tutorial: JDK 8 Streamsets Data Collector 1.4.0 ElasticSearch 2.3.3 Kibana 4.5.1 Elasticsearch and Kibana installation You should have your Elasticsearch cluster installed and configured and a Kibana instance pointing to that cluster in order to go on with this tutorial. Please refer to the official documentation for these two products in order to complete their installation (if you do

Exporting InfluxDB data to a CVS file

Sometimes you would need to export a sample of the data from an InfluxDB table to a CSV file (for example to allow a data scientist to do some offline analysis using a tool like Jupyter, Zeppelin or Spark Notebook). It is possible to perform this operation through the influx command line client. This is the general syntax: sudo /usr/bin/influx -database '<database_name>' -host '<hostname>' -username '<username>'  -password '<password>' -execute 'select_statement' -format '<format>' > <file_path>/<file_name>.csv where the format could be csv , json or column . Example: sudo /usr/bin/influx -database 'telegraf' -host 'localhost' -username 'admin'  -password '123456789' -execute 'select * from mem' -format 'csv' > /home/googlielmo/influxdb-export/mem-export.csv

Using Rapids cuDF in a Colab notebook

During last Spark+AI Summit Europe 2019 I had a chance to attend a talk from Miguel Martinez  who was presenting Rapids , the new Open Source framework from NVIDIA for GPU accelerated end-to-end Data Science and Analytics. Fig. 1 - Overview of the Rapids eco-system Rapids is a suite of Open Source libraries: cuDF cuML cuGraph cuXFilter I enjoied the presentation and liked the idea of this initiative, so I wanted to start playing with the Rapids libraries in Python on Colab , starting from cuDF, but the first attempt came with an issue that I eventually solved. So in this post I am going to share how I fixed it, with the hope it would be useful to someone else running into the same blocker. I am assuming here you are already familiar with Google Colab. I am using Python 3.x as Python 2 isn't supported by Rapids. Once you have created a new notebook in Colab, you need to check if the runtime for it is set to use Python 3 and uses a GPU as hardware accelerator. You