Forum Discussion

HristowSt's avatar
HristowSt
New Contributor
9 years ago

How to start mock service and use the response in test case using script

Hello,

 

Here is my problem:

 

I have test case where with test step I send request to the server. The server returns synchronus response.

Then the server returns an async response to mock wich is started by test step in the same test case.

 

Here is the sequence:

1. Send request test step.

2. Receive sync response.

3. Start mock test step.

4. Receive async response to the mock.

 

The problem is that SoapUI doesn't start the mock fast enough and then it fills the log file with ERROR: javax.xml.ws.WebServiceException: org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found html

 

So I need to start the mock service before the async response is send from the server. I have the following idea:

To start the Mock service manualy and then with groovy script to store the response in variable and then get the response to test step

in my test case. Where assertions will make sure the test case passed.

 

Can someone tell me what script should I use? Or give me better idea.

 

Thanks in advance!

6 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    If I understood you right i.e. during the same TestCase the service responds quicker than the Soap Mock Response TestStep is able to start & recieve the async response from your service?

     

    If so, then how about using 2 TestCases within the TestSuite:

    1) TestCase 1 - starts Soap Mock Response (to wait for async reply)

    2) TestCase 2 - fires sync Test Request

     

    How does that sound?

     

    Cheers,

    Rup

  • HristowSt's avatar
    HristowSt
    New Contributor

    Thanks for the fast answer!

     

    However this is not an option. Because when I want to run the whole test suite My test cases and test steps need to pass so the next one to trigger. If I run test cases with mock it will wait until response and then the next test case will start. But also I need to assert the async response.

    • rupert_anderson's avatar
      rupert_anderson
      Valued Contributor

      Hi,

       

      Ok, sorry if I'm missing something, but you could still assert the async response was successful in TestCase 1 (adding an assertion to the Mock Response TestStep), which may run before TestCase 2 but will pass after TestCase 2 is successful? Its just that the order of running the test cases is not what you ideally wanted.

       

      In your your case it seems the service is very fast to respond. In the cases I have tested before, the async response actually took a few seconds allowing the Mock Response TestStep time to start up and listen.

       

      Other than starting the Mock Response TestStep first (in another TestCase to avoid stopping the first one), I an struggling to see another easy OOTB alterntive. You could also consider calling another TestCase containing the Mock Responsse TestStep using the Run TestCase TestStep before you call your service, but I don't know if this is that different to the first option?

       

      Hope this helps (at least a bit),

      Cheers,

      Rup 

  • HristowSt's avatar
    HristowSt
    New Contributor

    Thanks, Rup

     

     

    it pointed me to some direction. However in this case I need to start both test cases manually, because the mock test step in the Test Case 1 will not pass until async response is returned. Which will not automatically trigger Test Case 2 where the request is placed.

     

    Correct me if I am wrong.

     

     

    Thanks again.

  • Don't know which version you use, but in the version I'm using 5.2.1 there's an option in the TestSteps MockResponseProperties setting. Set Start step to the TestStep that triggers your async response. Then the mock get's started before the response is triggered:

     

    Step1 SOAP-Call

    Step2 SOAP-Call

    Step3 SOAP-Call (ultimatively triggers reverse call from your server to the Mock in the next step)

    Step4 Mock (set StartStep Property to Step3)

     

    Hope this helps anyone...

     

    Holger