cancel
Showing results for 
Search instead for 
Did you mean: 

How to Integrate SOAPUI in VSTS(Visual Studio Team Services)

Highlighted
Contributor

Re: How to Integrate SOAPUI in VSTS(Visual Studio Team Services)

Hi pervindrap,

 

Indeed, more detailing your use case could be helpful. 

Perhaps this posts that could guide you in the right direction concerning using SOAPui in build pipeline of VS:

- https://community.smartbear.com/t5/SoapUI-Pro/Run-SoapUI-TestCases-from-Visual-Studio/m-p/161391#M36...

 

 Concerning the expiration of your token:

I have below test case which generates a token from an openidprovider. This token remains valid for only 10 minutes. 

 

The get-set properties_openId & expiration groovy step = 

 

 


import groovy.time.TimeCategory TimeZone.setDefault(TimeZone.getTimeZone('CET')) def expires_in = context.expand( '${Token#Response#$[\'expires_in\']}' ) int expires_in_seconds = expires_in as Integer //log.info expires_in_seconds currentDate = new Date() //log.info "currentdate" + currentDate use( TimeCategory )  { expirydate = currentDate + expires_in_seconds.seconds } //log.info "expirydate" + expirydate String expirydate_string = expirydate as String testRunner.testCase.testSuite.project.setPropertyValue ("openid_expirydate", expirydate_string) def id= context.expand( '${DataSource_OpenId#id}' ) def firstname = context.expand( '${DataSource_OpenId#first name}' ) def lastname = context.expand( '${DataSource_OpenId#last name}' ) def rol_claim = context.expand( '${DataSource_OpenId#rol_claim}' ) def description = context.expand( '${DataSource_OpenId#description }' ) def token_response = context.expand( '${Token#Response#$[\'id_token\']}' ) //log.info ("Forproperty "+description +" with id \""+id+"\" we generated following JWT token (valid until "+ expirydate + "): " +token_response) testRunner.testCase.testSuite.project.setPropertyValue ("authorization_"+description , token_response) def authorization = context.expand( '${#Project#authorization_'+description +'}' ) //log.info ("auhtorization in property = " + authorization) return expirydate

 

 

To check on the expiration date, so to make sure I always have a valid (not-expired) token I have to do some extra stuff. Otherwise there's a risk the automated tests (build agent level) would still be running after 10 minutes and thus getting an expired token into the authorization header (see previous post on the automation of authorization: https://community.smartbear.com/t5/SoapUI-Pro/oauth2-authorization-dynamic-test-automation-through-e...).

 

There are different ways to do this. Below script is an eventhandler TestRunListener.beforeRun.

I'd like to do this at test run level , mimicking a setup script at test case level. You could also do it at testStep level, but I feel this might be a bit overkill. Ideally, this should be somehow included in the RequestFilter.filterRequest, (so to focus only on those requests that actually use the open id ) but that script cannot invoke testRunner, which is needed to re-launch the openid-generation test case.

https://support.smartbear.com/readyapi/docs/testing/handling-events.html

 

So I will check at every start of a test case whether the token does not expire within 30 seconds. First of all: I am aware there is kind of a hole: if the expiration is reached during a test case that consumes openid tokens (so after 30 seconds that the test started) then some of the steps might fail due to expired tokens. 

But for that checking each and every step whether the time is reached seems too much. In my case the whole set of test cases would take around 15 minutes. So there would be one point where there needs to be a re-generation of tokens. Not all of my testcases use openid (and definitely not all of my test steps) + only a few test cases contain that many steps/loops that it takes more than 30 seconds to complete. So I think I'm safe with a 30 seconds margin.

  

 PS: I kept my "log.info" comments in there, just for ease of use so you can check what the code is doing in the script log tab.

 

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import groovy.time.TimeCategory

def project = testRunner.getTestCase().getTestSuite().getProject()
def testsuite = project.getTestSuiteByName("_Authentication")
def testcase = testsuite.getTestCaseByName("openid")

def tcname = testRunner.getTestCase().getName()
def tsname = testRunner.getTestCase().getTestSuite().getName()
//log.info ("tcname = " +tcname)
if (tsname != "_Authentication")
//I do not need to run the TestRunListener.beforeRun when we actually run the _Authentication test Suite, otherwise we might create an infinite loop!
{
TimeZone.setDefault(TimeZone.getTimeZone('CET'))
def expirydate_string = context.expand('${#Project#openid_expirydate}')
//log.info expirydate_string

Date now = new Date()

//log.info ("current date plus 30 seconden : "+ now_plus_30_seconds)
//expiry date is in string format. We need to convert it to a Date
DateFormat date_format = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US)
Date expirydate_convertedtodate = date_format.parse(expirydate_string)
//log.info ("expirydate converted: " + expirydate_convertedtodate)
use (TimeCategory)
{
expiry_min_30_seconds = expirydate_convertedtodate - 30.seconds
}

if (expiry_min_30_seconds > now)
{
log.info ("Event handler TestRunListener.beforeRun for test case: \"" + tcname + "\". Expiry date openid not yet reached :"+expiry_min_30_seconds+" > " +now)
}
else 
{
log.info ("!! Openid expired (or will expire in 30 seconds)!! " +expiry_min_30_seconds+" > " +now+ ". We run the Authorization openid  testcase again to get new valid tokens.")
testcase.run(new com.eviware.soapui.support.types.StringToObjectMap(),false)
}
}
else 
log.info ("No event handler testRunListener.beforeRun run for the openid requests test case! Otherwise we may end up in an infinite loop.")

 

 

 

Highlighted
Contributor

Re: How to Integrate SOAPUI in VSTS(Visual Studio Team Services)

Hi,

 

I am trying to integrate SOAPUI in VSTS and for that I am seeking help.

 

I am looking for the parameters which we need to pass when we add SOAPUI task in build definition?

 

I have the project in .xml file and when I am trying to to execute the build then I am getting errors as below:

 

1. Missing endpoint for request [XYZ]

2. 08:19:32,383 ERROR [AbstractTestRunner] Exception during Test Execution

java.lang.NullPointerException
at com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep.run(RestTestRequestStep.java:795)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:128)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
 
can you please help me on this.
Highlighted
New Contributor

Re: How to Integrate SOAPUI in VSTS(Visual Studio Team Services)

Step 1 : Create your SOap UI Projects and save the mas .xml files , the soapui projects should be inclusive of your authentication , data etc.... 

Step 2 : Assuming your pipelines etc are already there . Add Soaui as a task , provide the path to where the the projects is placed . 

Step 3 : Create build and the task picks up the project file and invokes the suite mentioned as arguments 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors