Wednesday, July 31, 2019

SoapUI Plugins

This is the last of my SoapUI testing tutorials. This SoapUI tutorial for beginners is on SoapUI Plugins in SoapUI tool. There is SoapUI Eclipse plugin. It gives you the SoapUI features in the Eclipse IDE (Integrated Development Environment). The Soap UI Eclipse plugin supports inspection, invoking, mocking, development and functional and other types of software testing of SOAP web services and REST web services over HTTP. It is useful for software testers who do SoapUI testing of web services. View my tutorial on SoapUI plugins to see SoapUI Eclipse plugin download, install and SoapUI Eclipse plug in working. Or read on...

Sunday, July 28, 2019

SoapUI Data Driven Testing Groovy

Let us continue with SoapUI testing tutorials. This SoapUI tutorial for beginners is on SoapUI data driven testing with Groovy script. What is data driven testing? It means that you store the test data in some format e.g. in an XML file, an Excel sheet or a database and then use that test data in your tests. The advantage of data driven testing using SoapUI is that you can run your tests with multiple test data values. First view this SoapUI Data Driven Testing Groovy tutorial. Then continue reading.

SoapUI free version does not give the  user interface to create data driven tests. However, SoapUI Pro provides a DataSource test step to get test data from sources like XML files, Excel sheets, files, directories and databases. This test data can be put into SoapUI properties and used in test steps. Also, a DataSource Loop test step is available to loop the previous test steps for each row of test data in the data source.

Note: You can see how to do data driven testing in SoapUI free version in my tutorial on SoapUI Data Driven Testing Groovy.

We can write a Groovy script in Soap UI tool to get the test data and run our test steps. This is how I implemented data-driven testing using Groovy.
  1. There is a library to handle Excel files using Java code, called JExcelApi. I downloaded it from SourceForge. Then I unzipped it. After unzip, the jxl.jar should be copied to the SoapUI lib folder (alternately, it can be copied to the SoapUI bin/ext folder). Then, I re-started Soap UI.
  2. Next, I put my test data in an Excel file. In my case, there were two columns, one for Numbers and the other for the same number in words. I used each Number as a parameter of my test request. SoapUI load test data from file in Excel.
  3. Then, I added a Properties test step. I clicked on the + icon to add properties. There were 5 properties. Number stored the parameter value. Word tested the assertion. Counter, Total and End properties were used in the Groovy script logic. Counter has to have an initial value of 0. End has to have an initial value of False.
  4. Next, I added a Groovy script test step because we have to do data driven testing in SoapUI using groovy script.
    import jxl.* // import Java Excel API library
    def TestCase = context.testCase
    def FilePath = "E:\\Training\\SoapUI\\Files\\NumbersWords.xls"
    def count

    Workbook WorkBook1 = Workbook.getWorkbook(new File(FilePath))
    Sheet Sheet1 = WorkBook1.getSheet(0)
    PropertiesTestStep = TestCase.getTestStepByName("Properties")
    count = PropertiesTestStep.getPropertyValue("Counter").toInteger()

    //If Total records is unknown (at start), get the rowcount from Excel
    if (PropertiesTestStep.getPropertyValue("Total").toString() == "")
        PropertiesTestStep.setPropertyValue("Total", Sheet1.getRows().toString())
    count++

    //Read the Excel test data
    Cell Field1 = Sheet1.getCell(0, count)
    Cell Field2 = Sheet1.getCell(1, count)
    log.info ("Count is " + count.toString() + " Number : " + Field1.getContents() + " Word : " + Field2.getContents())
    WorkBook1.close()

    //Copy the Excel test data to properties in Properties test step
    PropertiesTestStep.setPropertyValue("Number", Field1.getContents())
    PropertiesTestStep.setPropertyValue("Word", Field2.getContents())
    PropertiesTestStep.setPropertyValue("Counter", count.toString())
    if (count == PropertiesTestStep.getPropertyValue("Total").toInteger() - 1)
        PropertiesTestStep.setPropertyValue("End", "True")

  5. Also, I added a Groovy script test step to implement the data loop.
    def TestCase = context.testCase
    PropertiesTestStep = TestCase.getTestStepByName("Properties")
    Stop = PropertiesTestStep.getPropertyValue("End").toString()
    if (Stop=="True")
        log.info("Exit Groovy Script - DataLoop")
    else
        testRunner.gotoStepByName("Groovy Script")
  6. One thing to keep in mind is that the test steps in the test case should have the Groovy script as the first step and Groovy script with data loop as the last step. 
  7. In the request, I put a property expansion as the parameter value. This means that the request read the Number parameter value from the property, Number. In order to test the response, I put an assertion. This assertion also used a property expansion The assertion wa tested against the property, Word.
  8. Ensured that the properties are initialized correctly. Then, I ran the test case. 
  9. After the test case is run, in the Properties test step, Number and Word should have the last row data. Also, in the script log, each Number and Word should have been used.
  10. I also had a cleanup step (disabled in the Step 6 image above) to reset the property values after each run of the test case.
    def TestCase = context.testCase
    PropertiesTestStep = TestCase.getTestStepByName("Properties")
    PropertiesTestStep.setPropertyValue("Number","")
    PropertiesTestStep.setPropertyValue("Word", "")
    PropertiesTestStep.setPropertyValue("Counter", "0")
    PropertiesTestStep.setPropertyValue("Total", "")
    PropertiesTestStep.setPropertyValue("End", "False")
This is how you can also do SoapUI data driven testing with Groovy script. If you want to see this complete Soap UI data driven testing example, it is available in my SoapUI data driven testing tutorial.


Reference : https://www.anilvij.com/how-to-read-data-from-excel-using-groovy-soapui/

Sunday, July 21, 2019

Web service mocking SoapUI

This next SoapUI tutorial for beginners is on web service mocking in Soap UI tool. Web service mocking is a useful feature in SoapUI automation testing. 

What is web service mocking? When a web service is being developed, you have to wait for it to be complete before you can test its' clients. In SoapUI tool, you can start software testing even before the web service is live. How? You can simulate a web service using a mock service. This mock service can be run by SoapUI. You can send requests and get predefined responses from the web service. If you want to see examples of mocking service SoapUI, view my tutorial on Web service mocking Soap UI or read on...

Sunday, July 14, 2019

SoapUI properties

Let us continue with SoapUI testing tutorials. A property in Soap UI tool is a setting of an item. The item can be a SoapUI workspace, a SoapUI project, a SoapUI testsuite, a SoapUI test case, a SoapUI test step or a SoapUI request. The property holds a text value. You can use properties in SoapUI to specify your item. This way, the existing item can work with the settings that you specify. View my SoapUI beginner tutorial on SoapUI properties to see many examples or read on...

Sunday, July 7, 2019

SoapUI workspace

Let us continue with SoapUI testing tutorials. Before you can do SoapUI automation testing, you need to create a project in SoapUI. In SoapUI tool, a project needs to exist within a workspace. Soap UI saves a workspace as an XML file on the computer. The workspace's File property value tells Soap UI tool the location of the workspace directory. View my SoapUI beginner tutorial on Soap UI workspace or read on...

Let us learn how workspace works in SoapUI. By design, you can open only one workspace at a time. SoapUI can only see the projects in your open workspace (also called current workspace or active workspace). A single soapui work space can have multiple projects in it. Figure 1 has WORKSPACE1 open and WORKSPACE2 closed. This means that SoapUI can only see Project1, Project2 and Project3. SoapUI tool cannot see Project4 or Project5. Figure 2 has the reverse situation.
Figure 1 SoapUI Workspaces
Figure 2 SoapUI Workspaces
You may want to have multiple soap ui workspaces e.g. one workspace for each system under test or one workspace for each client. SoapUI workspaces help you to organize your Soap UI automation.

SoapUI provides the following workspace commands:
  • File > New Workspace
  • File > Rename workspace
  • SoapUI change workspace : File > Switch Workspace or  File > Recent > Workspaces
Want to learn more? You can see workspaces demonstrated in SoapUI tool in my Soap UI Beginner Tutorial on SoapUI workspaces.