Groovy ALM HpQC - Groovy exception - How to fill ST_ACTUAL design step field - groovy

I am trying to update HpQC result from SOAP-UI groovy script
but I'm currently unable to modify ST_ACTUAL field of design step,
only to read the current value.
each try conduct to groovy exception ("designStep.item(c).Field(ST_ACTUAL)" is a method call expression, but it should be a variable expression" for exemple)
For my try, I have two steps under a test. Could you help to solve my issue and tell me where I'm wrong? In advance, thanks a lot for your help and answers.
//############# Connexion a HpQC ###############
def tdc = new ActiveXObject ('TDApiOle80.TDConnection')
tdc.InitConnectionEx(addresse_qc)
tdc.Login(login_qc, psw_qc)
tdc.Connect(domain_qc, project_qc)
log.info "*** connected to QC ***"
//Catch the testSet campain in the Test Lab
oTestSetFolder = tdc.TestSetTreeManager.NodeByPath(chemin_dans_qc)
list_TestSetList = oTestSetFolder.FindTestSets(testSet_name_qc)
oTestSet = list_TestSetList.Item(1)
//catch the test list in the Test Lab
oTestSetFactory = oTestSet.TSTestFactory
testList = oTestSetFactory.NewList("")
def nb_test = testList.Count()
// select first test (item(1) -- Current status test Run - should be "No Run"
selected_test = testList.Item(1)
log.info("OnGoing test : " + "ID="+ selected_test.ID +" - "+ selected_test.name + " - status= "+selected_test.Status)
// Create a new Test Run and modified final status for try
OnGoing_RunTest= selected_test.RunFactory.AddItem('Comment 1')
OnGoing_RunTest.Status = 'Blocked'
def b=OnGoing_RunTest.ID
OnGoing_RunTest.Post()
OnGoing_RunTest.CopyDesignSteps()
OnGoing_RunTest.Post()
Stepslist_of_OnGoing_RunTest = OnGoing_RunTest.StepFactory.NewList("")
//def nbsteps= Stepslist_of_OnGoing_RunTest.count()
def c=1
for(designStep in Stepslist_of_OnGoing_RunTest)
{
// lecture designStep
def a=designStep.ID
// checking previous information : ok
//log.info("DesignStep_ID="+designStep.ID)
//log.info("ST_STEP_NAME = "+ designStep.field("ST_STEP_NAME"))
//log.info("ST_STATUS = "+ designStep.field("ST_STATUS"))
//log.info("ST_DESCRIPTION = "+ designStep.field("ST_DESCRIPTION"))
//log.info("ST_EXPECTED = "+ designStep.field("ST_EXPECTED"))
// updating Status and ST_ACTUAL field
designStep.Status="Not Completed" // : OK
// Updating ST_ACTUAL field
// designStep.Field("ST_ACTUAL")="123" // => KO
//designStep.item(c).Field("ST_ACTUAL")="123" // ==> KO
// designStep.item(designStep.ID).Field("ST_ACTUAL")="123" // ==> KO
// designStep.item(designStep.ID).Field("ST_ACTUAL")="123" // ==> KO
c++
log.info("ST_ACTUAL = "+ designStep.field("ST_ACTUAL"))
designStep.post()
}
//Updating Run QC
selected_test.Post()
log.info("*** ---- END Test --- ***")
//######### déconnection de QC ############
tdc.Disconnect()
//On écrit dans le log
log.info("### -- QC disconnect -- ### -- END -- ###")

I never tried in Groovy but in Ruby I had to use something like this (untested for this exemplary code):
designStep["ST_ACTUAL"]="123"

Related

OMNotebook Error: Class dev not found in scope (looking for a function or record)

I have modified the van der Pol example from DrModelica with the following changes:
model FPStirling "Free Piston Stirling engine model"
Real x(start = 1,fixed = true);
Real v(start = 1,fixed = true);
Real T(start = 1,fixed = true);
equation
der(x) = v;
dev(v) = T/x-1;
dev(T) = 1 - x;
end FPStirling;
It evaluates and returns: {FPStirling}
Then I run: simulate(FPStirling, startTime=0, stopTime=25 )
But I get the output:
record SimulationResult
resultFile = "",
messages = "Failed to build model: FPStirling"
end SimulationResult;
OMC-ERROR:
"[7:3-7:17] Error: Class dev not found in scope FPStirling (looking for a function or record).
Error: Error occurred while flattening model FPStirling
"
Could it be a path problem?
Do you really have a function dev defined somewhere? Or maybe its a typo for der.
Adeel.

Groovy script for hitting the same request with different value for multiple times

I am new to SOAP UI (using SOAP UI free version). I have a SOAP request XML and I need to run the same request multiple times passing different value for one tag each time. Can anyone please help me with the Groovy script that can be used here.
You can use the below sample to do the same. place all your test condition on local and fetch and run one-by-one
import com.eviware.soapui.support.XmlHolder;
import groovy.io.FileType;
import java.nio.file.Files;
import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
// Folder location , where input files are present, can be change or replace with new location. but same location has to be given here.
def sInputXMLpath = "C:\\TestFilesFolder\\RequestFiles\\"
// Test suites name : can be change or replace with new name. but same location has to be given here.
def sTestSet = testRunner.testCase.testSuite.project.testSuites["Demo"]
//if you have mutliple test cases, please change the index..... it will start with 0..( being first test case )
def sTestCase = sTestSet.getTestCaseAt(0)
log.info "TestCase.name : " + sTestCase.name
def iCountTestSteps = sTestCase.getTestStepCount()
log.info "Total Test Count of Test Steps in your TestSuite : " + iCountTestSteps
def i = 1
new File(sInputXMLpath).eachFile
{
def sInputFileName = it.name[0..-1]
log.info "Processing the file " + sInputFileName
log.info "**********************************************************************"
log.info "Test Number_"+ i +"_is Executing"
log.info "**********************************************************************"
log.info "Request of InputFileName : " + sInputFileName + " Is Executing "
def sTrimName = sInputFileName
sInputFileName = sTrimName.replaceAll(".xml","")
sInputFileContent = it.getText('UTF-8')
sTestCase.getTestStepAt(0).getProperty("Request").setValue(sInputFileContent);
//log.info "Request content : " + sTestCase.getTestStepAt(0).getProperty("Request").getValue()
testRunner.runTestStepByName("TestStepforRequest")
log.info "Info :TestStepforRequest get Called "
i++
}
In SoapUI speak, this is a data-driven test. SoapUI Pro version has really good support for this, but it is not enabled in the free version.
This is a rather common question on Stack Overflow, see this post which also includes a link to a page which describes how you can 'bend' the free version to run data-driven tests.
If you're not tied to SopaUI, you might want to try Postman. The free version of Postman has data-driven tests out of the box. See this link from the Postman site about using data files for testing.

How to use Groovy script in soapUi to loop multiple time

I am new to SoapUi. I am exploring on how multiple request in soapUi is done using groovy script.
below is the example that im trying to do, based on example that i found through "googling"
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.model.testsuite.*;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
import java.util.Random
import com.eviware.soapui.model.testsuite.TestRunner.Status
// Define your testCase pointer
//def testcase = testRunner.testCase.testSuite.project.testSuites["TestSuite - User Management REST API"].getTestCaseByName ("Authenticate User")
def counterUser = testRunner.testCase.testSuite.getPropertyValue( "counter" )
int value = counterUser.toInteger()
String tester = ""
30.times {
value = value + 1
tester = "tester " + value.toString()
testRunner.testCase.testSuite.setPropertyValue( "userName", tester )
testRunner.runTestStepByName("POST - createUser - Create a User")
}
testRunner.testCase.testSuite.setPropertyValue( "counter", value.toString() )
I want to create a 30 users which start from Tester1...tester2.....tester30.
Is it possible to do this way? I keep getting an error such as NullPointerException at this line
int value = counterUser.toInteger()
I got what you say.
That is because, initially there is no value for counter which results to null and you are applying toInteger() over it.
Just change:
From:
int value = counterUser.toInteger()
To:
int value = counterUser?.toInteger() ?: 0

Using Groovy Script, How to access the dynamic soap request which is stored in MessageExchange in a Data-Driven Approach?

I am trying a data driven approach in soap ui using groovy script and I wanted to export each of the dynamic request and response from MessageExchange to an Excel sheet. I am using the input data Excel file "dataFile.xls" for a simple "Login" operation. It consists of 2 fields Username and Password with 4 records. My script is doing a data driven approach and executing all the records from the excel file. But I wanted to export all the four dynamic request and response into an Excel file "Output.xls". My soap pack is having 2 groovy test request(one for data driver and the other for looping), one property test step to hold the input element properties and temporary variables, one soap test request "login". Below is the code snippet I am using in the "data driver" groovy test step.
// IMPORT THE LIBRARIES WE NEED
import com.eviware.soapui.support.XmlHolder
import jxl.*
import jxl.write.*
import com.eviware.soapui.model.iface.MessageExchange
// DECLARE THE VARIABLES
def myTestCase = context.testCase //myTestCase contains the test case
log.info(myTestCase)
def counter,next,previous,size //Variables used to handle the loop and to move inside the file
Workbook workbook1 = Workbook.getWorkbook(new File("d:\\Groovy videos\\dataFile.xls")) //file containing the data
Sheet sheet1 = workbook1.getSheet(0) //save the first sheet in sheet1
size = sheet1.getRows().toInteger() //get the number of rows, each row is a data set
log.info(size)
propTestStep = myTestCase.getTestStepByName("Property - Looper") // get the Property TestStep object
log.info(propTestStep)
req = myTestCase.getTestStepByName("login").getProperty("Request").getValue()
//log.info(req)
propTestStep.setPropertyValue("Total", size.toString())
counter = propTestStep.getPropertyValue("Count").toString() //counter variable contains iteration number
counter = counter.toInteger() //
next = (counter > size-2? 0: counter+1) //set the next value
// OBTAINING THE DATA YOU NEED
Cell u = sheet1.getCell(0,counter) // getCell(column,row) //obtains user
Cell p = sheet1.getCell(1,counter) // obtains password
workbook1.close() //close the file
////////////////////////////////////
usr = u.getContents()
pass = p.getContents()
propTestStep.setPropertyValue("user", usr) //the value is saved in the property
propTestStep.setPropertyValue("pass", pass) //the value is saved in the property
propTestStep.setPropertyValue("Count", next.toString()) //increase Count value
next++ //increase next value
propTestStep.setPropertyValue("Next", next.toString()) //set Next value on the properties step
WritableWorkbook workbook2 = Workbook.createWorkbook(new File("d:\\output.xls"))
WritableSheet sheet2 = workbook2.createSheet("Request", 0)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def temp=testRunner.testCase.testSteps["login"]
def testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(temp)
def reqq = testStepContext.getRequestContent()
log.info(reqq)
//def temp=testRunner.testCase.testSteps.testRequest.getRequestContent()
//holder = groovyUtils.getXmlHolder(messageExchange.requestContent)
log.info("request : "+temp)
Label label1 = new Label(0, 6, temp);
sheet2.addCell(label1);
workbook2.write()
workbook2.close()
//Decide if the test has to be run again or not
if (counter == size-1)
{
propTestStep.setPropertyValue("StopLoop", "T")
log.info "Setting the stoploop property now..."
}
else if (counter==0)
{
def runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null)
propTestStep.setPropertyValue("StopLoop", "F")
}
else
{
propTestStep.setPropertyValue("StopLoop", "F")
}
I am getting the fault
"groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext.getRequestContent() is applicable for argument types: () values: [] error at line: 50"
Could some one please help me in this.
The main objective is to get all the dynamic request and response from the MessageExchange and export all the data into the excel sheet.
Your program throws the exception there:
def testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(temp)
def reqq = testStepContext.getRequestContent()
log.info(reqq)
The exception is pretty clear MissingMethodException so the problem is that com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext doesn't have getRequestContent() method.
Anyway in your code you only use reqq on log.info(reqq)... then without analyzing the whole code the easy solution to solve the problem is simply remove this lines due they are useless.
You better make use of project level event "TestRunListener.afterStep" to accomplish your task.
In this event you'll have access to testRunner, context & testStepResult Objects. The following code snippet can help you.
For Soap Services:
if (context.getCurrentStep() instanceof WsdlTestRequestStep) {
WsdlTestStepResult soapResult= (WsdlTestStepResult) testStepResult;
log.info "Request: "+soapResult.getRequestContent();
log.info "Response: "+soapResult.getResponseContent();
}
For Rest Services:
if (context.getCurrentStep() instanceof RestTestRequestStep) {
RestRequestStepResult restResult= (RestRequestStepResult) testStepResult;
log.info "Request: "+restResult.getRequestContent();
log.info "Response: "+restResult.getResponseContent();
}

Jenkins Build Test Case pass fail count using groovy script

I want to fetch Total TestCase PASS and FAIL count for a build using groovy script. I am using Junit test results. I am using Multiconfiguration project , so is there any way to find this information on a per configuration basis?
If you use the plugin https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin, you can access the Jenkins TestResultAction directly from the build ie.
import hudson.model.*
def build = manager.build
int total = build.getTestResultAction().getTotalCount()
int failed = build.getTestResultAction().getFailCount()
int skipped = build.getTestResultAction().getSkipCount()
// can also be accessed like build.testResultAction.failCount
manager.listener.logger.println('Total: ' + total)
manager.listener.logger.println('Failed: ' + failed)
manager.listener.logger.println('Skipped: ' + skipped)
manager.listener.logger.println('Passed: ' + (total - failed - skipped))
API for additional TestResultAction methods/properties http://javadoc.jenkins-ci.org/hudson/tasks/test/AbstractTestResultAction.html
If you want to access a matrix build from another job, you can do something like:
def job = Jenkins.instance.getItemByFullName('MyJobName/MyAxisName=MyAxisValue');
def build = job.getLastBuild()
...
For Pipeline (Workflow) Job Type, the logic is slightly different from AlexS' answer that works for most other job types:
build.getActions(hudson.tasks.junit.TestResultAction).each {action ->
action.getTotalCount()
action.getFailCount()
action.getSkipCount()
}
(See http://hudson-ci.org/javadoc/hudson/tasks/junit/TestResultAction.html)
Pipeline jobs don't have a getTestResultAction() method.
I use this logic to disambiguate:
if (build.respondsTo('getTestResultAction')) {
//normal logic, see answer by AlexS
} else {
// pipeline logic above
}
I think you might be able to do it with something like this:
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
File fXmlFile = new File("junit-tests.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
println("Total : " + doc.getDocumentElement().getAttribute("tests"))
println("Failed : " +doc.getDocumentElement().getAttribute("failures"))
println("Errors : " +doc.getDocumentElement().getAttribute("errors"))
I also harvest junit xml test results and use Groovy post-build plugin https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin to check pass/fail/skip counts. Make sure the order of your post-build actions has harvest junit xml before the groovy post-build script.
This example script shows how to get test result, set build description with result counts and also version info from a VERSION.txt file AND how to change overall build result to UNSTABLE in case all tests were skipped.
def currentBuild = Thread.currentThread().executable
// must be run groovy post-build action AFTER harvest junit xml
testResult1 = currentBuild.testResultAction
currentBuild.setDescription(currentBuild.getDescription() + "\n pass:"+testResult1.result.passCount.toString()+", fail:"+testResult1.result.failCount.toString()+", skip:"+testResult1.result.skipCount.toString())
// if no pass, no fail all skip then set result to unstable
if (testResult1.result.passCount == 0 && testResult1.result.failCount == 0 && testResult1.result.skipCount > 0) {
currentBuild.result = hudson.model.Result.UNSTABLE
}
currentBuild.setDescription(currentBuild.getDescription() + "\n" + currentBuild.result.toString())
def ws = manager.build.workspace.getRemote()
myFile = new File(ws + "/VERSION.txt")
desc = myFile.readLines()
currentBuild.setDescription(currentBuild.getDescription() + "\n" + desc)

Resources