August 25, 2019

Python Tutorial 1 | Introduction

This is the first of Python Tutorials for Beginners. Let us learn about the Python programming language, how to download and install Python, using the Python interpreter, variables in Python and how to write a program in Python and run it. Please view my Python video tutorial 1 or read on...

Python is an open source programming language. It is easy to use. In many cases, Python needs fewer lines of code than other programming languages to accomplish the same task. Python is understandable because it uses English keywords. Python is an interpreted programming language. This means that there is no need to compile a Python program before running it.

Let us see how to download and install Python. You can get Python 3 from the Python official website. I have shown the steps in the Python Setup in my Python 1 tutorial video.
Next, you should add the path to the Path system variable. This ensures that you can run Python from any drive or any folder on your computer.
You can launch Python from the Python IDLE, which is the interactive Python interpreter. For this, click Start > All Programs > Python 3.x > IDLE. Alternately, you can launch Python from the command prompt. Either way, you should get the Python prompt, which is >>>

Next, you can type Python functions in the Python interpreter. Note that comments begin with # in Python.
>>> help(print) #see the documentation of any Python command
>>> quit()         #quit the Python interpreter

You can create variables in Python to store your data. A variable is a name or reference to your data. Now, Python is a case-sensitive programming language. This means that  v and V are two different variable names. You can continue with Python commands. You can view the Python video tutorial 1 to see such commands in action.
>>> 10 + 20    #this statement computes the expression and displays it 
>>> i = 1         #i is a variable. It is assigned the value 1.
>>> i               #this statement prints the value of i
>>>I                #NameError because variable I is not defined (Python is case-sensitive)
>>>type(i)      #this statement displays the type of data in the variable
>>>i + 5         #this statement computes the expression with the value of i and displays the expression value
>>>del i         #this statement deletes the variable

Next, let us see a small Python program based on the programming logic shown in the following flowchart:


>>> x = 1
>>> y = 2
>>> z = x + y
>>> print(z)

You can type in this Python code directly in the Python interpreter or save it in a Python file (Python scripts have .py file extension). You can see these details in my Python video tutorial 1. Thank you.

August 01, 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...

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. Thank you.