Package com.shaft.api
Class RestActions
java.lang.Object
com.shaft.api.RestActions
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enumstatic enum -
Constructor Summary
ConstructorsConstructorDescriptionRestActions(String serviceURI) RestActions(String serviceURI, SHAFT.API driver) -
Method Summary
Modifier and TypeMethodDescriptionaddCookieVariable(String key, String value) addHeaderVariable(String key, String value) Append a header to the current session to be used in all the following requests.buildNewRequest(String serviceName, RestActions.RequestType requestType) static RequestBuilderbuildNewRequest(String serviceURI, String serviceName, RestActions.RequestType requestType) static booleancompareJSON(io.restassured.response.Response response, String referenceJsonFilePath, RestActions.ComparisonType comparisonType) Compares the Response object against the content of the referenceJsonFilePathstatic booleancompareJSON(io.restassured.response.Response response, String referenceJsonFilePath, RestActions.ComparisonType comparisonType, String jsonPathToTargetArray) Compares the Response object against the content of the referenceJsonFilePathstatic Stringio.restassured.response.Responsestatic StringgetResponseBody(io.restassured.response.Response response) Extracts the response body and returns it as a plain stringstatic StringgetResponseJSONValue(io.restassured.response.Response response, String jsonPath) Extracts a string value from the response body by parsing the target jsonpathstatic StringgetResponseJSONValue(Object response, String jsonPath) getResponseJSONValueAsList(io.restassured.response.Response response, String jsonPath) static StringgetResponseJSONValueFromList(io.restassured.response.Response response, String jsonPathToList, String jsonPathToValueNeeded, String jsonPathToValueReference, String valueReference) Extracts a string value from an object of a list by reference of another attribute inside the same objectstatic intgetResponseStatusCode(io.restassured.response.Response response) static longgetResponseTime(io.restassured.response.Response response) static StringgetResponseXMLValue(io.restassured.response.Response response, String xmlPath) static StringgetResponseXMLValue(Object response, String xmlPath) getResponseXMLValueAsList(io.restassured.response.Response response, String xmlPath) static InputStreamparseBodyToJson(io.restassured.response.Response response) static InputStreamparseBodyToJson(Object body) static io.restassured.response.ResponsesendGraphQlRequest(String base_URI, String query) Perform Graphql Request using Query - WITHOUT Header.static io.restassured.response.ResponsesendGraphQlRequest(String base_URI, String query, String variables) Perform Graphql Request using Query and Variables - WITHOUT Header.static io.restassured.response.ResponsesendGraphQlRequest(String base_URI, String query, String variables, String fragment) Perform Graphql Request using Query, Variables, and Fragments - WITHOUT Header.static io.restassured.response.ResponsesendGraphQlRequestWithHeader(String base_URI, String query, String header_key, String header_value) Perform Graphql Request using Query - WITH Header.static io.restassured.response.ResponsesendGraphQlRequestWithHeader(String base_URI, String query, String variables, String header_key, String header_value) Perform Graphql Request using Query and Variables - WITH Header.static io.restassured.response.ResponsesendGraphQlRequestWithHeader(String base_URI, String query, String variables, String fragment, String header_key, String header_value) Perform Graphql Request using Query, Variables, and Fragments - WITH Header.
-
Constructor Details
-
RestActions
-
RestActions
-
-
Method Details
-
buildNewRequest
public static RequestBuilder buildNewRequest(String serviceURI, String serviceName, RestActions.RequestType requestType) -
parseBodyToJson
-
parseBodyToJson
-
getResponseBody
Extracts the response body and returns it as a plain string- Parameters:
response- the target API response object- Returns:
- a string value that represents the response body
-
getResponseJSONValue
public static String getResponseJSONValue(io.restassured.response.Response response, String jsonPath) Extracts a string value from the response body by parsing the target jsonpath- Parameters:
response- the full response object returned by 'performRequest()' methodjsonPath- the JSONPath expression that will be evaluated in order to extract the desired value [without the trailing $.], please refer to these urls for examples: https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html http://jsonpath.com/- Returns:
- a string value that contains the extracted object
-
getResponseJSONValue
-
getResponseJSONValueAsList
-
getResponseJSONValueFromList
public static String getResponseJSONValueFromList(io.restassured.response.Response response, String jsonPathToList, String jsonPathToValueNeeded, String jsonPathToValueReference, String valueReference) Extracts a string value from an object of a list by reference of another attribute inside the same object- Parameters:
response- The target API response objectjsonPathToList- The JSON path to the list of object inside the full responsejsonPathToValueNeeded- The JSON path to the attribute value you need to extract inside an object from the list. for example: idjsonPathToValueReference- The JSON path that refers to the needed attribute value inside an object from the list. for example: usernamevalueReference- The attribute value of the reference JSON path- Returns:
- A string value from the object of the list which represents the first match of the reference attribute value
-
getResponseXMLValue
-
getResponseXMLValue
-
getResponseXMLValueAsList
-
getResponseStatusCode
public static int getResponseStatusCode(io.restassured.response.Response response) -
getResponseTime
public static long getResponseTime(io.restassured.response.Response response) -
compareJSON
public static boolean compareJSON(io.restassured.response.Response response, String referenceJsonFilePath, RestActions.ComparisonType comparisonType) Compares the Response object against the content of the referenceJsonFilePath- Parameters:
response- the full response object returned by performRequest method.referenceJsonFilePath- the full absolute path to the test data file that will be used as a reference for this comparisoncomparisonType- ComparisonType.EQUALS, CONTAINS, MATCHES, EQUALS_STRICT; Note that MATCHES ignores the content ordering inside the JSON- Returns:
- a boolean value that is TRUE in case the comparison passed, or FALSE in case it failed
-
compareJSON
public static boolean compareJSON(io.restassured.response.Response response, String referenceJsonFilePath, RestActions.ComparisonType comparisonType, String jsonPathToTargetArray) Compares the Response object against the content of the referenceJsonFilePath- Parameters:
response- the full response object returned by performRequest method.referenceJsonFilePath- the full absolute path to the test data file that will be used as a reference for this comparisoncomparisonType- ComparisonType.EQUALS, CONTAINS; Note that MATCHES ignores the content ordering inside the JSONjsonPathToTargetArray- a jsonpath that will be parsed to point to the target JSON Array- Returns:
- a boolean value that is TRUE in case the comparison passed, or FALSE in case it failed
-
formatXML
-
sendGraphQlRequest
Perform Graphql Request using Query - WITHOUT Header.- Parameters:
base_URI- The Base URI without "graphql". example:: "https://api.example.com/"query- graphql query or mutation.- Returns:
- Graphql Response
-
sendGraphQlRequest
public static io.restassured.response.Response sendGraphQlRequest(String base_URI, String query, String variables) Perform Graphql Request using Query and Variables - WITHOUT Header.- Parameters:
base_URI- The Base URI without "graphql". example:: "https://api.example.com/"query- graphql query or mutation.variables- graphql variables; dynamic values of the query. please refer to this url for examples:: https://graphql.org/learn/queries/#variables- Returns:
- Graphql Response
-
sendGraphQlRequest
public static io.restassured.response.Response sendGraphQlRequest(String base_URI, String query, String variables, String fragment) Perform Graphql Request using Query, Variables, and Fragments - WITHOUT Header.- Parameters:
base_URI- The Base URI without "graphql". example:: "https://api.example.com/"query- graphql query or mutation.variables- graphql variables; dynamic values of the query. please refer to this url for examples:: https://graphql.org/learn/queries/#variablesfragment- graphql fragment; reusable units let you construct sets of fields, and then include them in queries where you need to. please refer to this url for examples:: https://graphql.org/learn/queries/#fragments- Returns:
- Graphql Response
-
getResponse
public io.restassured.response.Response getResponse() -
sendGraphQlRequestWithHeader
public static io.restassured.response.Response sendGraphQlRequestWithHeader(String base_URI, String query, String header_key, String header_value) Perform Graphql Request using Query - WITH Header.- Parameters:
base_URI- The Base URI without "graphql". example:: "https://api.example.com/"query- graphql query or mutation.header_key- the name of the header that you want to add. example:: "Authorization"header_value- the value that will be put inside the key. example:: "bearer ${token}"- Returns:
- Graphql Response
-
sendGraphQlRequestWithHeader
public static io.restassured.response.Response sendGraphQlRequestWithHeader(String base_URI, String query, String variables, String header_key, String header_value) Perform Graphql Request using Query and Variables - WITH Header.- Parameters:
base_URI- The Base URI without "graphql". example:: "https://api.example.com/"query- graphql query or mutation.variables- graphql variables; dynamic values of the query. please refer to this url for examples:: https://graphql.org/learn/queries/#variablesheader_key- the name of the header that you want to add. example:: "Authorization"header_value- the value that will be put inside the key. example:: "bearer ${token}"- Returns:
- Graphql Response
-
sendGraphQlRequestWithHeader
public static io.restassured.response.Response sendGraphQlRequestWithHeader(String base_URI, String query, String variables, String fragment, String header_key, String header_value) Perform Graphql Request using Query, Variables, and Fragments - WITH Header.- Parameters:
base_URI- The Base URI without "graphql". example:: "https://api.example.com/"query- graphql query or mutation.variables- graphql variables; dynamic values of the query. please refer to this url for examples:: https://graphql.org/learn/queries/#variablesfragment- graphql fragment; reusable units let you construct sets of fields, and then include them in queries where you need to. please refer to this url for examples:: https://graphql.org/learn/queries/#fragmentsheader_key- the name of the header that you want to add. example:: "Authorization"header_value- the value that will be put inside the key. example:: "bearer ${token}"- Returns:
- Graphql Response
-
buildNewRequest
-
addHeaderVariable
Append a header to the current session to be used in all the following requests. Note: This feature is commonly used for authentication tokens.- Parameters:
key- the name of the header that you want to addvalue- the value that will be put inside the key- Returns:
- self-reference to be used for chaining actions
-
addCookieVariable
-