Você está na página 1de 9

import java.util.Date; import java.io.File; import java.util.*; import java.lang.*; import groovy.sql.Sql; import jxl.*; import jxl.write.

*; import java.sql.*; import java.sql.Time; import java.io.IOException;

def testIterationCountQry = "Some Query " def testIterationCount,TC_Status,TC_StatusExp,RemarkExp, Remark def respReturnCode // DB connection try{

String jdbcURL=testRunner.testCase.testSuite.project.getPropertyValue('jdbcURL')

String userName =testRunner.testCase.testSuite.project.getPropertyValue('userName')

String password =testRunner.testCase.testSuite.project.getPropertyValue('password')

String dbDriverName =testRunner.testCase.testSuite.project.getPropertyValue('dbDriverName')

com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(dbDriverName)

def sqlConnection = Sql.newInstance(jdbcURL, userName, password, dbDriverName)

sqlConnection.eachRow(testIterationCountQry){row->

testIterationCount=row[0] }

//################### Before SOAP call Test datas ############################################### def testTestDataQry = "Some Query " List testDataBefore = new ArrayList() sqlConnection.eachRow(testTestDataQry){row ->

testDataBefore.add(row.FirstColumn) testDataBefore.add(row.SecondColumn) } //################### Invoke the SOAP call here ################################################# respReturnCode = invokeSoapCall()

//################### Compare Both the datas ###################################################### if (respReturnCode=='0'){

if(testIterationCount>0){

def i =0 def j = 1 TC_Status="Pass" while (testIterationCount){

value1= testDataBefore[i]

log.info value1

valueBeforeNotificationStatus=testDataBefore[j] log.info valueBeforeNotificationStatus def retriveNotiStatusAfter = "select ColumnName from TableName where id='"+valueOfID+"'" def valueAfterNotificationStatus

sqlConnection.eachRow(retriveNotiStatusAfter){ rownew->

valueAfterNotificationStatus=rownew[0] } log.info valueAfterNotificationStatus

if (valueAfterNotificationStatus=='Y'){

///TC_Status="Pass"

Remark= "Notify Indicator become Y "

} else{ TC_Status="Fail" Remark= "Notify Indicator not set to Y"

i=j+1 j=i+1

testIterationCount-} } else{ TC_Status="Fail" Remark= "No test data / Pre-condition mismatch!" testRunner.fail("No Test data in Database") log.info Remark } } else {

TC_Status="Fail" Remark = "Return code=" + returncode

} catch(SQLException e) { e.printStackTrace() TC_StatusExp="Failure" RemarkExp = "Exception occurred on DB Connection or query Execution" testRunner.fail("Database exception") } catch(Exception error) { error.printStackTrace() TC_StatusExp="Failure" if(testIterationCount == 0) {

RemarkExp = "No test data / Pre-condition mismatch!" testRunner.fail("No Test data in Database")

} else{ RemarkExp = "Exception occured while processing DB values"

testRunner.fail("Exception occured while processing DB values") }

/*Test Result*/ def project = testRunner.testCase.testSuite.project; def testSuiteName = testRunner.testCase.testSuite.name def testCaseName = testRunner.testCase.name def testCase = project.testSuites[testSuiteName].testCases[testCaseName];

def target = "C:\\AutomationReport\\"+testSuiteName+".html" File wf = new File(target) def projectPath = "C:\\" def reportsPath = projectPath+"\\AutomationReport" new File(reportsPath).mkdir() def fileName_temp = reportsPath+"\\"+testSuiteName+".html" def writeToFile1

if (wf.exists()) { log.info("P212121") writeToFile1 = new FileWriter(fileName_temp,true) }

else { //Create html page with title only log.info('Test case report') writeToFile1 = new FileWriter(fileName_temp,false) //def writeToFile = new eFileWriter(fileName_temp,false) writeToFile1.write("<table border=1 width='90%' align='center' cellpadding=0 cellspacing=2 BGCOLOR=#C0C0C0 >") writeToFile1.write(" <tr bgcolor='#00BFFF' style='color:black;text-align:center;fontsize:20'><th>TestCaseName</th>" + "<th>Input</th><th>Output</th> <th> Result </th> <th> Remark </th>")

} if(TC_StatusExp=="Failure"){ writeToFile1.write("<tr bgcolor='white' style='text-align:center;'>" +"<td>"+ testCaseName + "</td><td>" + "No input tag for the request" +"</td><td>"+"returnCode: "+respReturnCode + "&nbsp;</td><td>"+TC_StatusExp+"&nbsp;</td><td>"+RemarkExp+"</td>") } else{ writeToFile1.write("<tr bgcolor='white' style='text-align:center;'>" +"<td>"+ testCaseName + "</td><td>" + "No input tag for the request" +"</td><td>"+"returnCode: "+respReturnCode + "&nbsp;</td><td>"+TC_Status+"&nbsp;</td><td>"+Remark+"</td>") }

//Closing the html write file

writeToFile1.close() //Update pass or fail count in main html page if (TC_Status == "Pass") { passcount = context.expand('${#Global#Pass}') passcount = passcount.toInteger() + 1 passcount = passcount.toString() com.eviware.soapui.SoapUI.globalProperties.setPropertyValue('Pass',passcount)} else { failcount= context.expand('${#Global#Fail}') failcount = failcount.toInteger() + 1 failcount = failcount.toString() com.eviware.soapui.SoapUI.globalProperties.setPropertyValue('Fail',failcount)}

//################################ Holder Starts ######################################### //Method invoking soap request public String invokeSoapCall(){

def project = testRunner.testCase.testSuite.project def testSuiteName= testRunner.testCase.testSuite.name def testCaseName= testRunner.testCase.name def testCase= project.testSuites[testSuiteName].testCases[testCaseName] def testStepName= testCase.getTestStepAt(0).name def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) holder = groovyUtils.getXmlHolder(testStepName+"#request" )

def testStep = testCase.getTestStepAt(0); /*Run the soapui*/ testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null); testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep); testStep.run(testRunner, testStepContext);

/*reading the response*/ def groovyUtils1 = new com.eviware.soapui.support.GroovyUtils( context ) holder1 = groovyUtils1.getXmlHolder( testStepName+"#response" ) def value = holder1.getNodeValue("//returnCode") log.info("Response is :" + value); return value } //################## Holdder Ends #############################################################

Você também pode gostar