free seo tool

Capture the list of Assertions using groovy script


While doing automation testing of web services using groovy and soapUI, we might need to get the list of assertions and its status of a test request. By using groovy this can be achieved easily in soapUI. See the below example. 
def obj = context.testCase.getTestStepByName("GetCustomer");
def assertions = obj.getAssertionList()
assertions.each{
log.info(it.name +  ' --> ' + it.status)
}


The above code is creating an object for the test request named "GetCustomer" in the first line. In second line it is storing all the assertions into a variable name "assertions". The assertions.each block iterates through the list of all assertions attached to the test request "GetCustomer" and the log statement prints the name of the assertions along with it status.

Below line of code will give the total number of assertions attached to a test request. 


def obj = context.testCase.getTestStepByName("GetCustomer");

log.info(obj.getAssertionCount())
4 comments:
  • Swati says:
    May 14, 2012

    Gud 1 Sudeesh am implementing the same in my project however I was trying to customize it a bit

    This line will show the information about the assert and its status

    log.info(it.name + ' --> ' + it.status)

    I tried to call it as a alert message so that an alert would pop up and show me the information about the assert in POP UP.

    Can we perform something like diz ??

  • Swati says:
    May 14, 2012

    Its done buddy have customized it using alert.showInfoMessage

    Thanks!!!!

  • qa says:
    November 27, 2013

    Hi Friends,

    I am using Soap UI 4.5.2 free version. Please observe project structure




    My Project has only one suite
    Suite has two test scenarios here (can have many)
    Here in my project each test step is a test case
    When I run this suite, I want each test scenario should have one excel sheet
    In that excel sheet, I need to get the test case name, request xml, response xml, and status as shown below






    I have tried some groovy scripting; I am sharing the script also. Please do help


    //Author : Vasudev Reddy
    import java.text.SimpleDateFormat
    import java.io.File
    import java.io.FileInputStream
    import java.io.FileOutputStream
    import jxl.*
    import jxl.write.*

    //Get Project Name
    def ProjectName= testRunner.testCase.testSuite.project.name
    //log.info(ProjectName)

    //Get Test Case Name
    def TestCaseName= testRunner.testCase.name
    //log.info(TestCaseName)

    //Current Date
    dateFormat = new java.text.SimpleDateFormat('dd-MMM-yyyy HH-mm-ss')
    def Date = dateFormat.format(new Date())

    //Selecting a folder path
    def folderPath = "C:\\Vasu\\Test\\" + ProjectName +" Results"
    createFolder = new File(folderPath).mkdir()
    // log.info("Folderpath" + folderPath)


    def workbook = Workbook.createWorkbook(new File(folderPath +"\\"+ "Results " + "(" + Date + ")" + ".xls"));

    def soapuiRequests = testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep)
    soapuiRequests.each{

    def sheet = workbook.createSheet(TestCaseName, 0)
    Label header1 = new Label(0, 0, "Test case Name");
    sheet.addCell(header1);

    Label header2 = new Label(1, 0, "Request XML");
    sheet.addCell(header2);

    Label header3 = new Label(2, 0, "Response XML");
    sheet.addCell(header3);

    Label header4 = new Label(3, 0, "Status");
    sheet.addCell(header4);

    def testName = it.name;

    Label testcasename = new Label(0, 1, testName);
    sheet.addCell(testcasename);

    Label requestxml = new Label(1, 1, context.testCase.getTestStepByName(it.name).getProperty("request").value);
    sheet.addCell(requestxml);

    Label responsexml = new Label(2, 1, context.testCase.getTestStepByName(it.name).getProperty("response").value);
    sheet.addCell(responsexml);

    Label status = new Label(3, 1, testRunner.status.toString());
    sheet.addCell(status);

    workbook.write()
    }

    workbook.close()


    I am able to create the folder, excel file inside the folder, first test case row also,
    But iam not able to get all test case one after another.

    I know I am missing the loop somewhere please do help me

    please provide me the mail id i can send you the images also to make you clear . thanks

  • LAVANYA says:
    September 16, 2014

    Hi,

    I have added an assertion step to my test suite. I want to capture the result from the assertion step to excel.

    Can u please tell me how do i achieve that?

Post a Comment

This is a new website mainly for SOA Testers using soapUI. Let me know your thoughts/ suggestions.