Forum Discussion

ricardo_moura's avatar
ricardo_moura
Occasional Contributor
7 years ago

how to get MockResponse "Name" property value?

Hello

 

to help my testers to analise results of automation, i need to get and log the value of the "Name" property from mockResponse

 

 

on each resource script i have a simple SwitchCase to determine wich MockResponse should be sent according specific values on the JSON request:

switch (keyField){

//Bradesco Padrão
	case 'acme':
		return "409607_302001_T0"

how to get MockResponse's "Name" property value to put into script log?

5 Replies

  • Nastya_Khovrina's avatar
    Nastya_Khovrina
    SmartBear Alumni (Retired)

    Hi Ricardo,

     

    Thank you for your post! You can try the following script:

    log.info "Name = " + context.mockService.name

    And, to get a value of a custom property, you can use the following:

    // REST Virt
    log.info "getPropertyName = " + context.modelItem.project.getRestMockServiceByName("Name of your Virt").getPropertyValue("Name of your property")
    // SOAP Virt log.info "getPropertyName = " + context.modelItem.project.getMockServiceByName("Name of your Virt").getPropertyValue("Name of your property")
    • ricardo_moura's avatar
      ricardo_moura
      Occasional Contributor

      thanks for fast reply Anastasia

       

      in both scripts, the aplication only can get MockService properties value, i need obtain mockResponse's name, 2 levels below on the project tree:

       

       

      I created in the MockService a custom property called "resultName" for the following script, insert an "hard coded" value and, with your second script, to get the property value and log it.

       

       

       

      def resultName = context.mockService.setPropertyValue("resultName","Response1")

       

      It works fine, but I have many mock responses and does this for each is unviable.

       

      thanks again