Wednesday, June 29, 2016

SOAP Get Value from Project Level Groovy

Get Property value from Project Level


testRunner.testCase.testSuite.project.getPropertyValue('PropertyName')


Get Property value from Test Suite Level

testRunner.testCase.testSuite.getPropertyValue('PropertyName')

Get Property value from Test Case Level

testRunner.testCase.getPropertyValue('PropertyName')

Add Field Values in Soap Test Http Step Groovy Rest Services

Add Field Values in Soap UI Test Step

testRunner.testCase.getTestStepByName('HttpRequestStepName').httpRequest.setPropertyValue(Field,valueParameter)



Read Excel using Groovy

import groovy.xml.*
import jxl.*
import jxl.write.*

//def Temp_Array_Length = 0
//********************* Excel Sheet Path *******************************

def projectDir = context.expand('${projectDir}');
Path= projectDir +"\\TestData"+ "\\Update.xls" // Excel Sheet Location

log.info "Project Path" + Path
Workbook workbook1 = Workbook.getWorkbook(new File(Path)) // Read Excel Sheet
Sheet sheet1 = workbook1.getSheet('CreateUpdate') // Sheet Number

def GET_REQUEST_XML = testRunner.getTestCase()
int rows = 0;
int cols = 0;
rows = sheet1.getRows(); // Rows Count
cols = sheet1.getColumns();// Columns Count
//log.info "Row Count--------------" + rows
//log.info "Cols Count--------------" + cols
def data_array = new String[cols]



for(i=0;i<rows;i++)
{
                for(j=0;j<cols;j++)
                {
                                if(i==0)// Reading First Line from Excel Sheet
                                {
                                  Cell a1 = sheet1.getCell(j,0)
                            def data1 = a1.getContents()
                          //log.info data1
                               if(!GET_REQUEST_XML.hasProperty(data1)){
                                GET_REQUEST_XML.addProperty(data1)
                               }
                                data_array[j] = data1
                                }
                                else{
                        Cell a2 = sheet1.getCell(j,i)
                          def data2 = a2.getContents()
                          value1 = data_array[j]
                          testRunner.testCase.setPropertyValue( value1 , data2 )
                         
                                }
                }


           
                if(i!=0)
                {
                def RunStatus = testRunner.testCase.getPropertyValue('RunStatus')
                if(RunStatus=='true')
                {
               
testRunner.testCase.setPropertyValue( 'email' , testRunner.testCase.testSuite.project.getPropertyValue('email') )
testRunner.runTestStepByName('Authentication') // Running Auth Services
try{
Thread.currentThread().sleep(1000)
}
catch(Exception e){}
def str = testRunner.testCase.getPropertyValue('Parameter')// Reading Prameter from Excel Sheet
def values = str.split(',')
int charCount = str.replaceAll("[^,]", "").length(); // finding lenget of parameter
log.info (charCount);
for( x=0;x<=charCount;x++)
{
//${#TestCase#Name}
valueParameter= '${#TestCase#' + values[x] + '}'// find  Value
//log.info "Parameters :  " + values[x]
testRunner.testCase.getTestStepByName('Service').httpRequest.setPropertyValue(values[x],valueParameter) // Adding Value and Name for Services

}
if(testRunner.testCase.getPropertyValue('scope')=='groups')
{
testRunner.testCase.setPropertyValue( 'actorList' , testRunner.testCase.testSuite.project.getPropertyValue('groupId') )
}
if(testRunner.testCase.getPropertyValue('scope')=='private')
{
testRunner.testCase.setPropertyValue( 'actorList' , testRunner.testCase.testSuite.project.getPropertyValue('ActorId') )
}

// Fetching URL form Project Level for Different Environment
ServiceURL=testRunner.testCase.testSuite.project.getPropertyValue('url')+ testRunner.testCase.getPropertyValue('EndPoint')
testRunner.testCase.setPropertyValue( 'Service URL' , ServiceURL )

testRunner.runTestStepByName('Service') // Running Service

//*****************************************************************************************
testRunner.runTestStepByName('ActivityDetails')
testRunner.runTestStepByName('Database')
testRunner.runTestStepByName('GroovyAssertion')



//*****************************************************************************************

for( y=0;y<=charCount;y++)
{
testRunner.testCase.getTestStepByName('Service').httpRequest.removeProperty(values[y])
//log.info "Parameters :  " + values[y]
}
//*****************************************************************************************
                }

}
}

Property Transfer Step Soap UI

Source :

declare namespace soap='http://www.w3.org/2003/05/soap-envelope';
declare namespace ns1='http://www.webserviceX.NET/';
//ns1:ConversionRateResponse/ns1:ConversionRateResult

Target :

declare namespace soap='http://www.w3.org/2003/05/soap-envelope';
declare namespace ns1='http://www.webserviceX.NET/';
//ns1:ConversionRate/ns1:FromCurrency



Monday, June 27, 2016

Get Test Steps Name + Groovy

This Line Returns Steps name in a Test Case

stepList = testRunner.testCase.getTestStepList()
for(x in stepList){

if(!x.getName()=="Steprun")
testRunner.runTestStepByName(x.getName())
log.info("          " + x.getName())


}

Get Test Case Name Groovy

def TestCase = testRunner.getTestCase()

Get Property using groovy

def RunStatus = testRunner.testCase.getPropertyValue('RunStatus')

Remove Test Case Property + Groovy

testRunner.testCase.removeProperty( "Testcase Property Name") 

Date in Groovy

import java.text.DateFormat
def today = new Date()
log.info today.format("dd-MM-yyyy H:mm a")
def endDate=today+1
log.info endDate.format("dd-MM-yyyy H:mm a")

Test Case name in Groovy

def testCases = context.testCase.testSuite.getTestCaseList()
testCases.each
{
    log.info "Test Case:" + testCases.name
  for(testSteps in it.testStepList)
    {
        log.info "Test Step:" + testSteps.name
   }
}

Remove Multiple Test Case Properties using loop in Groovy

testRunner.testCase.properties.each
{
testProperty=it.value.name
 log.info testProperty
 testRunner.testCase.removeProperty(testProperty);
}

Saturday, June 18, 2016

Groovy Print Sting log.info or log.error

class HelloWorld {

    HelloWorld() {
  
      log.info 'Hello World'
log.error 'Hello World    
}

    static main(args) {
        new HelloWorld()
    }
}