Forum Discussion

PERSIN's avatar
PERSIN
Contributor
6 years ago

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

Hi,

 

Can any one please help me in configuring SOAPUI in VSTS, I am getting error while configuring it. I want to know the parameters we need to define/set while integrating it.

12 Replies

  • richie's avatar
    richie
    Community Hero
    hi,

    i was trying to do this several weeks ago. i got sidetracked by some other work.

    ive got some step by step instructions for VSTS/Git. if youre happy to use VSTS/Git combo i will post them tomorrow. like i say i never finished cos of other work, but i do have some good instructions to do this. before you start i would consider all the directory structures for you projects and supporting test evidence etc. as once you convert your project to composite and add the project into your vsts/git repo you quickly use up the allowed 260 characters in the full path length.

    cheers,

    richie
    • PERSIN's avatar
      PERSIN
      Contributor

      Hi Richie,

       

      Thank you for reverting back.

       

      Yes, i will be using GIT/VSTS combo,please let me know the steps and method.

       

      Regards.

       

      • richie's avatar
        richie
        Community Hero

        Hi,

         

        I've attached the instructions

         

        the instructions are just for getting it into a VSTS/Git repo - so don't forget any of the soapui project preamble you need to do (shorten all the foldernames, project names, testsuite names, testcase names, teststep names, convert to composite project etc.) needs to be done BEFORE you start using the instructions.

         

        As I said in my previous post - I hit a character limit (I think its about 265) because I have so many different projects with lots of sequential versions of testdata that were making the full path very long - so make sure you seriously consider this before hand.

         

        If you're paths are  too long, when you try and convert to composite, you'll get a warning it doesnt work if you hit the limit.

         

        HOWEVER - adding into a VSTS/Git Repo adds additional chars to the full path length - so make sure you well UNDER the character limit - you don't know what will happen in the future and future project work could add to the path length quite a bit if you don't organise your stuff properly

  • JoostDG's avatar
    JoostDG
    Frequent Contributor

    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#M36362

     

     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-event/m-p/160713).

     

    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.")

     

     

     

  • srirajms's avatar
    srirajms
    New Contributor

    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