Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a 'GET' RESTful request:

    Code Block
    languagegroovy
    themeRDark
    import com.kms.katalon.core.testobject.ConditionType as ConditionType
    import com.kms.katalon.core.testobject.RestRequestObjectBuilder
    import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
    import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
    
    'Create a new GET object using builder'
    def builder = new RestRequestObjectBuilder()
    def requestObject = builder
    	.withRestRequestMethod("GET")
    	.withRestUrl("http://jsonplaceholder.typicode.com/comments")
    	.withRestParameters([
    		new TestObjectProperty("postId", ConditionType.EQUALS, "1"),
    		new TestObjectProperty("id", ConditionType.EQUALS, "1")
    	])
    	.withHttpHeaders([
    		new TestObjectProperty("Content-Type", ConditionType.EQUALS, "application/json")
    	])
    	.build()
    'Send a request'
    def response = WS.sendRequest(requestObject)
    
    'Verify if comment\'s email after sending request is correct or not'
    WS.verifyElementPropertyValue(response, '[0].email', 'Eliseo@gardner.biz')
    
    
  2. Create a 'POST' RESTful request:

    Code Block
    languagegroovy
    themeRDark
    import com.kms.katalon.core.testobject.ConditionType as ConditionType
    import com.kms.katalon.core.testobject.RestRequestObjectBuilder
    import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
    import com.kms.katalon.core.testobject.UrlEncodedBodyParameter
    import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
     
    def builder = new RestRequestObjectBuilder()
       
    'Create a new POST object using builder'
    def requestObject = builder
    	    .withRestRequestMethod("POST")
    	    .withRestUrl("https://sample-web-service-aut.herokuapp.com/api/users/urlencoded")
    	    .withHttpHeaders([
    		        new TestObjectProperty("Content-Type", ConditionType.EQUALS, "application/x-www-form-urlencoded")
    	    ])
    	    .withUrlEncodedBodyContent([
    		        new UrlEncodedBodyParameter("username", "myUsername"),
    		        new UrlEncodedBodyParameter("password", "myPassword"),
    		        new UrlEncodedBodyParameter("gender", "MALE"),
    		        new UrlEncodedBodyParameter("age", "20"),
    		new UrlEncodedBodyParameter("avatar", "AAA"),
        ])
    	    .build()
    	     
    def response = WS.sendRequest(requestObject)
       
    assert response.getStatusCode() == 200