diff --git a/specs/data_stores/Saving And Reading Values From Data Stores.spec b/specs/data_stores/Saving And Reading Values From Data Stores.spec index ed6da1f..fe58fe0 100644 --- a/specs/data_stores/Saving And Reading Values From Data Stores.spec +++ b/specs/data_stores/Saving And Reading Values From Data Stores.spec @@ -12,7 +12,7 @@ tags: data_store, regression ## Get configurations of the testing environment -* Configurations of the testing environment +* Print configuration details of the testing environment ## Saving values to Data Store diff --git a/specs/other/GET API From Data Store 1.spec b/specs/other/GET API From Data Store 1.spec new file mode 100644 index 0000000..6485e52 --- /dev/null +++ b/specs/other/GET API From Data Store 1.spec @@ -0,0 +1,56 @@ +# Invoke GET API From Data Store With Authentication Specification + +Project Name : MaxSoft-IntelliAPI +Developer : Osanda Deshan +Version : 1.0.0 +Date : 1/20/2021 +Time : 1:58 PM +Description : This is an executable specification file + +tags: get_api, regression + + + |JSON Path|Expected Response Status Code| + |---------|-----------------------------| + |$[0].url |200 | + |$[1].url |200 | + |$[2].url |200 | + |$[3].url |200 | + + +## Invoke GET Request from a response's JSON Path value with authentication + +* Given that a user needs to invoke "Get urls" +* And the user set the request authentication configurations as follows + |Configuration |Configuration Value| + |------------------------------------------------------------------|-------------------| + |Is authentication required? |Yes | + |Do you need to retrieve the access token from the text file? |Yes | + |Provide the access token if you need to authorize the API manually|N/A | +* And the user set the request headers using data stores as follows + |Header Name |Is Data Store Used?|Data Store Type|Data Store Variable Name|Header Value | + |-------------|-------------------|---------------|------------------------|-----------------------------------| + |App-Name |no | | |IntelliAPI | + |Organization |no | | |MaxSoft | +* When the user invokes the API +* Then the status code for the request is "200" +* And the JSON Path Assertions for the response should be equal to the values inside the data stores + |JSON Path |Is Data Store Used?|Data Store Type|Data Store Variable Name|Expected Value | + |--------------|-------------------|---------------|------------------------|------------------------------------------------| + |$[0].name |no | | |First photo | + |$[1].name |no | | |Second photo | + |$[3].name |no | | |Get all tasks with auth header | +* Given that a user needs to invoke a GET API from the JSON Path value +* And the user set the request authentication configurations as follows + |Configuration |Configuration Value| + |------------------------------------------------------------------|-------------------| + |Is authentication required? |Yes | + |Do you need to retrieve the access token from the text file? |Yes | + |Provide the access token if you need to authorize the API manually|N/A | +* And the user set the request headers using data stores as follows + |Header Name |Is Data Store Used?|Data Store Type|Data Store Variable Name|Header Value | + |-------------|-------------------|---------------|------------------------|-----------------------------------| + |App-Name |no | | |IntelliAPI | + |Organization |no | | |MaxSoft | +* When the user invokes the GET API +* Then the status code for the request is \ No newline at end of file diff --git a/specs/other/GET API From Data Store 2.spec b/specs/other/GET API From Data Store 2.spec new file mode 100644 index 0000000..1d02ff3 --- /dev/null +++ b/specs/other/GET API From Data Store 2.spec @@ -0,0 +1,45 @@ +# Invoke GET API From Data Store Without Authentication Specification + +Project Name : MaxSoft-IntelliAPI +Developer : Osanda Deshan +Version : 1.0.0 +Date : 1/20/2021 +Time : 1:58 PM +Description : This is an executable specification file + +tags: get_api, regression + + + |JSON Path|Expected Response Status Code| + |---------|-----------------------------| + |$[0].url |200 | + |$[1].url |200 | + |$[2].url |200 | + |$[3].url |400 | + + +## Invoke GET Request from a response's JSON Path value without authentication + +* Given that a user needs to invoke "Get urls" +* And the user set the request authentication configurations as follows + |Configuration |Configuration Value| + |------------------------------------------------------------------|-------------------| + |Is authentication required? |Yes | + |Do you need to retrieve the access token from the text file? |Yes | + |Provide the access token if you need to authorize the API manually|N/A | +* And the user set the request headers using data stores as follows + |Header Name |Is Data Store Used?|Data Store Type|Data Store Variable Name|Header Value | + |-------------|-------------------|---------------|------------------------|-----------------------------------| + |App-Name |no | | |IntelliAPI | + |Organization |no | | |MaxSoft | +* When the user invokes the API +* Then the status code for the request is "200" +* And the JSON Path Assertions for the response should be equal to the values inside the data stores + |JSON Path |Is Data Store Used?|Data Store Type|Data Store Variable Name|Expected Value | + |--------------|-------------------|---------------|------------------------|------------------------------------------------| + |$[0].name |no | | |First photo | + |$[1].name |no | | |Second photo | + |$[3].name |no | | |Get all tasks with auth header | +* Given that a user needs to invoke a GET API from the JSON Path value +* When the user invokes the GET API +* Then the status code for the request is \ No newline at end of file diff --git a/src/main/java/com/maxsoft/intelliapi/common/BodyType.java b/src/main/java/com/maxsoft/intelliapi/BodyType.java similarity index 86% rename from src/main/java/com/maxsoft/intelliapi/common/BodyType.java rename to src/main/java/com/maxsoft/intelliapi/BodyType.java index 3023c7e..27f071d 100644 --- a/src/main/java/com/maxsoft/intelliapi/common/BodyType.java +++ b/src/main/java/com/maxsoft/intelliapi/BodyType.java @@ -1,4 +1,4 @@ -package com.maxsoft.intelliapi.common; +package com.maxsoft.intelliapi; /** * Project Name : MaxSoft-IntelliAPI diff --git a/src/main/java/com/maxsoft/intelliapi/common/Constants.java b/src/main/java/com/maxsoft/intelliapi/Constants.java similarity index 99% rename from src/main/java/com/maxsoft/intelliapi/common/Constants.java rename to src/main/java/com/maxsoft/intelliapi/Constants.java index 18d8c37..f0a4eec 100644 --- a/src/main/java/com/maxsoft/intelliapi/common/Constants.java +++ b/src/main/java/com/maxsoft/intelliapi/Constants.java @@ -1,4 +1,4 @@ -package com.maxsoft.intelliapi.common; +package com.maxsoft.intelliapi; import java.io.File; diff --git a/src/main/java/com/maxsoft/intelliapi/executionhooks/ExecutionContextHook.java b/src/main/java/com/maxsoft/intelliapi/ExecutionContextHook.java similarity index 96% rename from src/main/java/com/maxsoft/intelliapi/executionhooks/ExecutionContextHook.java rename to src/main/java/com/maxsoft/intelliapi/ExecutionContextHook.java index 8a39aad..778577a 100644 --- a/src/main/java/com/maxsoft/intelliapi/executionhooks/ExecutionContextHook.java +++ b/src/main/java/com/maxsoft/intelliapi/ExecutionContextHook.java @@ -1,4 +1,4 @@ -package com.maxsoft.intelliapi.executionhooks; +package com.maxsoft.intelliapi; import com.maxsoft.intelliapi.util.LogUtil; import com.thoughtworks.gauge.*; diff --git a/src/main/java/com/maxsoft/intelliapi/common/HttpMethod.java b/src/main/java/com/maxsoft/intelliapi/HttpMethod.java similarity index 86% rename from src/main/java/com/maxsoft/intelliapi/common/HttpMethod.java rename to src/main/java/com/maxsoft/intelliapi/HttpMethod.java index 817765c..fbc5fb4 100644 --- a/src/main/java/com/maxsoft/intelliapi/common/HttpMethod.java +++ b/src/main/java/com/maxsoft/intelliapi/HttpMethod.java @@ -1,4 +1,4 @@ -package com.maxsoft.intelliapi.common; +package com.maxsoft.intelliapi; /** * Project Name : MaxSoft-IntelliAPI diff --git a/src/main/java/com/maxsoft/intelliapi/api/ApiInvoker.java b/src/main/java/com/maxsoft/intelliapi/api/ApiInvoker.java index ca600c1..2c7e399 100644 --- a/src/main/java/com/maxsoft/intelliapi/api/ApiInvoker.java +++ b/src/main/java/com/maxsoft/intelliapi/api/ApiInvoker.java @@ -1,18 +1,18 @@ package com.maxsoft.intelliapi.api; import com.maxsoft.intelliapi.util.FrameworkUtil; -import com.maxsoft.intelliapi.common.BodyType; -import com.maxsoft.intelliapi.common.HttpMethod; +import com.maxsoft.intelliapi.BodyType; +import com.maxsoft.intelliapi.HttpMethod; import io.restassured.http.Headers; import java.security.InvalidParameterException; -import static com.maxsoft.intelliapi.api.ApiRequestPayload.getApiEndpointToBeInvoked; -import static com.maxsoft.intelliapi.api.FormDataHttpMethodsProcessor.postFormDataApiWithAuthMultipleHeaders; -import static com.maxsoft.intelliapi.api.FormDataHttpMethodsProcessor.putFormDataApiWithAuthMultipleHeaders; -import static com.maxsoft.intelliapi.api.JsonHttpMethodsProcessor.*; -import static com.maxsoft.intelliapi.common.BodyType.JSON; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.getApiEndpointToBeInvoked; +import static com.maxsoft.intelliapi.api.FormDataRequestProcessor.postFormDataApiWithAuthMultipleHeaders; +import static com.maxsoft.intelliapi.api.FormDataRequestProcessor.putFormDataApiWithAuthMultipleHeaders; +import static com.maxsoft.intelliapi.api.JsonRequestProcessor.*; +import static com.maxsoft.intelliapi.BodyType.JSON; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario; /** diff --git a/src/main/java/com/maxsoft/intelliapi/api/ApiRequestPayload.java b/src/main/java/com/maxsoft/intelliapi/api/ApiRequestPayloadProcessor.java similarity index 97% rename from src/main/java/com/maxsoft/intelliapi/api/ApiRequestPayload.java rename to src/main/java/com/maxsoft/intelliapi/api/ApiRequestPayloadProcessor.java index 3735311..8756583 100644 --- a/src/main/java/com/maxsoft/intelliapi/api/ApiRequestPayload.java +++ b/src/main/java/com/maxsoft/intelliapi/api/ApiRequestPayloadProcessor.java @@ -6,7 +6,7 @@ import java.util.*; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.LogUtil.printInfo; import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario; import static com.maxsoft.intelliapi.util.reader.ApiDocumentReader.*; @@ -20,7 +20,7 @@ * Description : **/ -public class ApiRequestPayload { +public class ApiRequestPayloadProcessor { public static void initializeApiToBeInvoked(String apiEndpointName) { setApiEndpoint(apiEndpointName); diff --git a/src/main/java/com/maxsoft/intelliapi/api/ApiResponse.java b/src/main/java/com/maxsoft/intelliapi/api/ApiResponseProcessor.java similarity index 99% rename from src/main/java/com/maxsoft/intelliapi/api/ApiResponse.java rename to src/main/java/com/maxsoft/intelliapi/api/ApiResponseProcessor.java index a6e7d99..e4a192d 100644 --- a/src/main/java/com/maxsoft/intelliapi/api/ApiResponse.java +++ b/src/main/java/com/maxsoft/intelliapi/api/ApiResponseProcessor.java @@ -16,7 +16,7 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.DataStoreProcessor.*; import static com.maxsoft.intelliapi.util.LogUtil.printError; import static com.maxsoft.intelliapi.util.LogUtil.printInfo; @@ -30,7 +30,7 @@ * Description : **/ -public class ApiResponse { +public class ApiResponseProcessor { public static void saveStatusCode(Response response) { saveValueForScenario(VAR_API_RESPONSE_STATUS_CODE, String.valueOf(response.statusCode())); diff --git a/src/main/java/com/maxsoft/intelliapi/api/FormDataHttpMethodsProcessor.java b/src/main/java/com/maxsoft/intelliapi/api/FormDataRequestProcessor.java similarity index 99% rename from src/main/java/com/maxsoft/intelliapi/api/FormDataHttpMethodsProcessor.java rename to src/main/java/com/maxsoft/intelliapi/api/FormDataRequestProcessor.java index 354208b..2ea6567 100644 --- a/src/main/java/com/maxsoft/intelliapi/api/FormDataHttpMethodsProcessor.java +++ b/src/main/java/com/maxsoft/intelliapi/api/FormDataRequestProcessor.java @@ -9,9 +9,9 @@ import java.util.Collections; import java.util.Map; -import static com.maxsoft.intelliapi.api.ApiRequestPayload.getFormData; -import static com.maxsoft.intelliapi.api.ApiResponse.*; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.getFormData; +import static com.maxsoft.intelliapi.api.ApiResponseProcessor.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario; import static io.restassured.RestAssured.given; import static io.restassured.config.EncoderConfig.encoderConfig; @@ -25,7 +25,7 @@ * Description : **/ -public class FormDataHttpMethodsProcessor { +public class FormDataRequestProcessor { public static void postFormDataApiWithAuthMultipleHeaders(String invokingEndpoint, String accessToken, Headers headers) { Response response; diff --git a/src/main/java/com/maxsoft/intelliapi/api/JsonHttpMethodsProcessor.java b/src/main/java/com/maxsoft/intelliapi/api/JsonRequestProcessor.java similarity index 96% rename from src/main/java/com/maxsoft/intelliapi/api/JsonHttpMethodsProcessor.java rename to src/main/java/com/maxsoft/intelliapi/api/JsonRequestProcessor.java index a2ada28..9bdab69 100644 --- a/src/main/java/com/maxsoft/intelliapi/api/JsonHttpMethodsProcessor.java +++ b/src/main/java/com/maxsoft/intelliapi/api/JsonRequestProcessor.java @@ -4,8 +4,8 @@ import io.restassured.http.Headers; import io.restassured.response.Response; -import static com.maxsoft.intelliapi.api.ApiResponse.*; -import static com.maxsoft.intelliapi.common.Constants.AUTHORIZATION_HEADER_NAME; +import static com.maxsoft.intelliapi.api.ApiResponseProcessor.*; +import static com.maxsoft.intelliapi.Constants.AUTHORIZATION_HEADER_NAME; import static io.restassured.RestAssured.given; /** @@ -17,7 +17,7 @@ * Description : **/ -public class JsonHttpMethodsProcessor { +public class JsonRequestProcessor { public static void getApiWithAuthMultipleHeaders(String invokingEndpoint, String accessToken, Headers headers) { Response response; diff --git a/src/main/java/com/maxsoft/intelliapi/database/MongoOperator.java b/src/main/java/com/maxsoft/intelliapi/database/MongoOperator.java index f1a72c7..2d6cef9 100644 --- a/src/main/java/com/maxsoft/intelliapi/database/MongoOperator.java +++ b/src/main/java/com/maxsoft/intelliapi/database/MongoOperator.java @@ -11,7 +11,7 @@ import java.util.Collections; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.DataStoreProcessor.saveValueForScenario; import static com.maxsoft.intelliapi.util.LogUtil.printInfo; import static com.mongodb.client.model.Filters.eq; diff --git a/src/main/java/com/maxsoft/intelliapi/database/MySqlOperator.java b/src/main/java/com/maxsoft/intelliapi/database/MySqlOperator.java index 1c7583b..7da987b 100644 --- a/src/main/java/com/maxsoft/intelliapi/database/MySqlOperator.java +++ b/src/main/java/com/maxsoft/intelliapi/database/MySqlOperator.java @@ -13,7 +13,7 @@ import java.util.Collections; import java.util.List; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario; import static com.maxsoft.intelliapi.util.DataStoreProcessor.saveValueForScenario; import static com.maxsoft.intelliapi.util.LogUtil.printError; diff --git a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestInvokerStepImpl.java b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestInvokerStepImpl.java new file mode 100644 index 0000000..0b52a5e --- /dev/null +++ b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestInvokerStepImpl.java @@ -0,0 +1,86 @@ +package com.maxsoft.intelliapi.stepimpl.api; + +import com.maxsoft.intelliapi.api.ApiInvoker; +import com.thoughtworks.gauge.Step; +import io.restassured.http.Headers; + +import static com.maxsoft.intelliapi.Constants.*; +import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.getHeaders; +import static com.maxsoft.intelliapi.api.JsonRequestProcessor.getApiWithAuthMultipleHeaders; +import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario; +import static com.maxsoft.intelliapi.util.FrameworkUtil.isTrue; +import static com.maxsoft.intelliapi.util.FrameworkUtil.readAccessToken; +import static com.maxsoft.intelliapi.util.LogUtil.printInfo; + +/** + * Project Name : MaxSoft-IntelliAPI + * Developer : Osanda Deshan + * Version : 1.0.0 + * Date : 1/20/2021 + * Time : 6:21 PM + * Description : + **/ + +public class ApiRequestInvokerStepImpl { + +/* Use this method when you need to pass the JSON request in previous step and the access token from the text file + into the GET/POST/PUT/DELETE API. The "saveRequestAuthConfigurations" must use before using this step */ + @Step("When the user invokes the API") + public void invokeApi() { + String jsonRequest = String.valueOf(getSavedValueForScenario(VAR_API_JSON_REQUEST_BODY)); + String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST); + String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST); + + if (headerNamesList == null || headerNamesList.equals("") || + headerValuesList == null || headerValuesList.equals("")) { + ApiInvoker.invoke(jsonRequest, new Headers()); + } else { + ApiInvoker.invoke(jsonRequest, new Headers(getHeaders(headerNamesList, headerValuesList))); + } + } + +/* Use this method to invoke a GET API from a request url in the response's JSON path. + The "saveApiEndpointInResponseBody" must use before using this step */ + @Step("When the user invokes the GET API") + public void doGetRequestFromDataStore() { + String invokingEndpoint = getSavedValueForScenario(VAR_API_ENDPOINT); + String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST); + String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST); + + String accessToken, isAuthenticationRequired, isAccessTokenRetrievedFromTextFile, accessTokenString; + String accessTokenInFile = readAccessToken(); + + try { + isAuthenticationRequired = getSavedValueForScenario(IS_AUTHENTICATION_REQUIRED).toLowerCase(); + isAccessTokenRetrievedFromTextFile = getSavedValueForScenario(RETRIEVE_TOKEN_FROM_TEXT_FILE).toLowerCase(); + accessTokenString = getSavedValueForScenario(MANUAL_TOKEN); + } catch (Exception ex) { + isAuthenticationRequired = ""; + isAccessTokenRetrievedFromTextFile = ""; + accessTokenString = ""; + } + + if (isTrue(isAuthenticationRequired)) { + if (isTrue(isAccessTokenRetrievedFromTextFile)) { + accessToken = accessTokenInFile; + } else { + accessToken = accessTokenString; + } + } else { + accessToken = ""; + } + + printInfo(""); + printInfo(""); + printInfo("Invoked API Endpoint:\n" + invokingEndpoint + "\n\n"); + printInfo("HTTP Method is: GET\n\n"); + + if (headerNamesList == null || headerNamesList.equals("") || + headerValuesList == null || headerValuesList.equals("")) { + getApiWithAuthMultipleHeaders(invokingEndpoint, accessToken, new Headers()); + } else { + getApiWithAuthMultipleHeaders(invokingEndpoint, accessToken, + new Headers(getHeaders(headerNamesList, headerValuesList))); + } + } +} diff --git a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestPayloadConfigStepImpl.java b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestPayloadConfigStepImpl.java index b80f573..4a9ef0a 100644 --- a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestPayloadConfigStepImpl.java +++ b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestPayloadConfigStepImpl.java @@ -8,11 +8,12 @@ import java.util.List; -import static com.maxsoft.intelliapi.api.ApiRequestPayload.*; +import static com.maxsoft.intelliapi.Constants.*; +import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.*; +import static com.maxsoft.intelliapi.api.ApiResponseProcessor.saveResponseJsonPathValue; +import static com.maxsoft.intelliapi.util.DataStoreProcessor.*; import static com.maxsoft.intelliapi.util.FrameworkUtil.*; -import static com.maxsoft.intelliapi.common.Constants.*; import static com.maxsoft.intelliapi.util.LogUtil.printInfo; -import static com.maxsoft.intelliapi.util.DataStoreProcessor.*; /** * Project Name : MaxSoft-IntelliAPI @@ -31,6 +32,12 @@ public void apiToBeInvoked(String apiEndpointName) { initializeApiToBeInvoked(apiEndpointName); } + // Use this method before invoking a GET API from a request url in the response's JSON path + @Step("Given that a user needs to invoke a GET API from the JSON Path value ") + public void saveApiEndpointInResponseBody(String jsonPath) { + saveResponseJsonPathValue(SCENARIO, VAR_API_ENDPOINT, jsonPath); + } + // Use this method to replace the placeholders inside the API Endpoint in Excel @Step("And the user set values to the API endpoint placeholders as follows ") public void setApiEndpointReplacements(Table table) { diff --git a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiResponseDataProcessorStepImpl.java b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiResponseDataProcessorStepImpl.java index 5e2c6de..17347bb 100644 --- a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiResponseDataProcessorStepImpl.java +++ b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiResponseDataProcessorStepImpl.java @@ -6,7 +6,7 @@ import java.util.List; -import static com.maxsoft.intelliapi.api.ApiResponse.*; +import static com.maxsoft.intelliapi.api.ApiResponseProcessor.*; /** * Project Name : MaxSoft-IntelliAPI diff --git a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiResponseValidatorStepImpl.java b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiResponseValidatorStepImpl.java index 3964224..f763ee7 100644 --- a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiResponseValidatorStepImpl.java +++ b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiResponseValidatorStepImpl.java @@ -1,6 +1,6 @@ package com.maxsoft.intelliapi.stepimpl.api; -import com.maxsoft.intelliapi.api.ApiResponse; +import com.maxsoft.intelliapi.api.ApiResponseProcessor; import com.maxsoft.intelliapi.util.fileoperator.TextFile; import com.thoughtworks.gauge.Step; import com.thoughtworks.gauge.Table; @@ -10,7 +10,7 @@ import java.util.List; import static com.maxsoft.intelliapi.util.FrameworkUtil.*; -import static com.maxsoft.intelliapi.common.Constants.VAR_API_RESPONSE_STATUS_CODE; +import static com.maxsoft.intelliapi.Constants.VAR_API_RESPONSE_STATUS_CODE; import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario; import static com.maxsoft.intelliapi.util.DataStoreProcessor.readFromDataStore; @@ -43,10 +43,10 @@ public void checkJsonPathValueContainsText(Table table){ String jsonPathValue = row.getCell(columnNames.get(1)); if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathValueContainsText(jsonPath, + ApiResponseProcessor.checkJsonPathValueContainsText(jsonPath, TextFile.read(getFilePathFromFileSyntax(jsonPathValue))); } else { - ApiResponse.checkJsonPathValueContainsText(jsonPath, jsonPathValue); + ApiResponseProcessor.checkJsonPathValueContainsText(jsonPath, jsonPathValue); } } } @@ -65,14 +65,14 @@ public void checkJsonPathValueFromDataStoreContainsText(Table table){ String jsonPathValue = row.getCell(columnNames.get(4)); if(isTrue(isRetrievedFromDataStore)) { - ApiResponse.checkJsonPathValueContainsText(jsonPath, + ApiResponseProcessor.checkJsonPathValueContainsText(jsonPath, readFromDataStore(dataStoreType, dataStoreVariableName)); } else { if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathValueContainsText(jsonPath, + ApiResponseProcessor.checkJsonPathValueContainsText(jsonPath, TextFile.read(getFilePathFromFileSyntax(jsonPathValue))); } else { - ApiResponse.checkJsonPathValueContainsText(jsonPath, jsonPathValue); + ApiResponseProcessor.checkJsonPathValueContainsText(jsonPath, jsonPathValue); } } } @@ -89,10 +89,10 @@ public void checkJsonPathValueNotContainsText(Table table){ String jsonPathValue = row.getCell(columnNames.get(1)); if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathValueNotContainsText(jsonPath, + ApiResponseProcessor.checkJsonPathValueNotContainsText(jsonPath, TextFile.read(getFilePathFromFileSyntax(jsonPathValue))); } else { - ApiResponse.checkJsonPathValueNotContainsText(jsonPath, jsonPathValue); + ApiResponseProcessor.checkJsonPathValueNotContainsText(jsonPath, jsonPathValue); } } } @@ -111,14 +111,14 @@ public void checkJsonPathValueFromDataStoreNotContainsText(Table table){ String jsonPathValue = row.getCell(columnNames.get(4)); if(isTrue(isRetrievedFromDataStore)) { - ApiResponse.checkJsonPathValueNotContainsText(jsonPath, + ApiResponseProcessor.checkJsonPathValueNotContainsText(jsonPath, readFromDataStore(dataStoreType, dataStoreVariableName)); } else { if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathValueNotContainsText(jsonPath, + ApiResponseProcessor.checkJsonPathValueNotContainsText(jsonPath, TextFile.read(getFilePathFromFileSyntax(jsonPathValue))); } else { - ApiResponse.checkJsonPathValueNotContainsText(jsonPath, jsonPathValue); + ApiResponseProcessor.checkJsonPathValueNotContainsText(jsonPath, jsonPathValue); } } } @@ -135,10 +135,10 @@ public void checkJsonPathAssertionEqualsText(Table table){ String jsonPathValue = row.getCell(columnNames.get(1)); if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathAssertionEqualsText(jsonPath, + ApiResponseProcessor.checkJsonPathAssertionEqualsText(jsonPath, TextFile.read(getFilePathFromFileSyntax(jsonPathValue))); } else { - ApiResponse.checkJsonPathAssertionEqualsText(jsonPath, jsonPathValue); + ApiResponseProcessor.checkJsonPathAssertionEqualsText(jsonPath, jsonPathValue); } } } @@ -157,14 +157,14 @@ public void checkJsonPathAssertionFromDataStoreEqualsText(Table table){ String jsonPathValue = row.getCell(columnNames.get(4)); if(isTrue(isRetrievedFromDataStore)) { - ApiResponse.checkJsonPathAssertionEqualsText(jsonPath, + ApiResponseProcessor.checkJsonPathAssertionEqualsText(jsonPath, readFromDataStore(dataStoreType, dataStoreVariableName)); } else { if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathAssertionEqualsText(jsonPath, + ApiResponseProcessor.checkJsonPathAssertionEqualsText(jsonPath, TextFile.read(getFilePathFromFileSyntax(jsonPathValue))); } else { - ApiResponse.checkJsonPathAssertionEqualsText(jsonPath, jsonPathValue); + ApiResponseProcessor.checkJsonPathAssertionEqualsText(jsonPath, jsonPathValue); } } } @@ -181,10 +181,10 @@ public void checkJsonPathAssertionNotEqualsText(Table table){ String jsonPathValue = row.getCell(columnNames.get(1)); if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathAssertionNotEqualsText(jsonPath, + ApiResponseProcessor.checkJsonPathAssertionNotEqualsText(jsonPath, TextFile.read(getFilePathFromFileSyntax(jsonPathValue))); } else { - ApiResponse.checkJsonPathAssertionNotEqualsText(jsonPath, jsonPathValue); + ApiResponseProcessor.checkJsonPathAssertionNotEqualsText(jsonPath, jsonPathValue); } } } @@ -203,14 +203,14 @@ public void checkJsonPathAssertionFromDataStoreNotEqualsText(Table table){ String jsonPathValue = row.getCell(columnNames.get(4)); if(isTrue(isRetrievedFromDataStore)) { - ApiResponse.checkJsonPathAssertionNotEqualsText(jsonPath, + ApiResponseProcessor.checkJsonPathAssertionNotEqualsText(jsonPath, readFromDataStore(dataStoreType, dataStoreVariableName)); } else { if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathAssertionNotEqualsText(jsonPath, + ApiResponseProcessor.checkJsonPathAssertionNotEqualsText(jsonPath, TextFile.read(getFilePathFromFileSyntax(jsonPathValue))); } else { - ApiResponse.checkJsonPathAssertionNotEqualsText(jsonPath, jsonPathValue); + ApiResponseProcessor.checkJsonPathAssertionNotEqualsText(jsonPath, jsonPathValue); } } } @@ -227,10 +227,10 @@ public void checkJsonPathExistence(Table table){ String jsonPathValue = row.getCell(columnNames.get(1)); if (hasContainedFileSyntax(jsonPathValue)) { - ApiResponse.checkJsonPathExistence(jsonPath, + ApiResponseProcessor.checkJsonPathExistence(jsonPath, Boolean.valueOf(TextFile.read(getFilePathFromFileSyntax(jsonPathValue)))); } else { - ApiResponse.checkJsonPathExistence(jsonPath, Boolean.valueOf(jsonPathValue)); + ApiResponseProcessor.checkJsonPathExistence(jsonPath, Boolean.valueOf(jsonPathValue)); } } } diff --git a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/OtherStepImpl.java b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/OtherStepImpl.java index 04e142f..c417462 100644 --- a/src/main/java/com/maxsoft/intelliapi/stepimpl/api/OtherStepImpl.java +++ b/src/main/java/com/maxsoft/intelliapi/stepimpl/api/OtherStepImpl.java @@ -1,13 +1,9 @@ package com.maxsoft.intelliapi.stepimpl.api; -import com.maxsoft.intelliapi.api.ApiInvoker; import com.maxsoft.intelliapi.util.FrameworkUtil; import com.thoughtworks.gauge.Step; -import io.restassured.http.Headers; -import static com.maxsoft.intelliapi.api.ApiRequestPayload.getHeaders; -import static com.maxsoft.intelliapi.common.Constants.*; -import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario; +import static com.maxsoft.intelliapi.Constants.CURRENT_DIRECTORY; /** * Project Name : MaxSoft-IntelliAPI @@ -21,27 +17,12 @@ public class OtherStepImpl { // Use this method to print the testing environment name in the HTML report - @Step("Configurations of the testing environment") + @Step("Print configuration details of the testing environment") public void printTestingEnvDetails() { FrameworkUtil.printTestingEnvDetails(); } - /* Use this method when you need to pass the JSON request in previous step and the access token from the text file into the GET/POST/PUT/DELETE API. - The "saveRequestAuthConfigurations" must use before using this step */ - @Step("When the user invokes the API") - public void invokeApi() { - String jsonRequest = String.valueOf(getSavedValueForScenario(VAR_API_JSON_REQUEST_BODY)); - String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST); - String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST); - - if (headerNamesList == null || headerNamesList.equals("") || - headerValuesList == null || headerValuesList.equals("")) { - ApiInvoker.invoke(jsonRequest, new Headers()); - } else { - ApiInvoker.invoke(jsonRequest, new Headers(getHeaders(headerNamesList, headerValuesList))); - } - } - + // Use this method to replace the rows of a column in a given CSV with the timestamp @Step("And replace the row values in column of the CSV into the timestamp pattern") public void replaceAllColumnValuesToCurrentTimestamp(String columnName, String filePath, String timestampPattern) { FrameworkUtil.replaceAllColumnValuesToCurrentTimestamp(CURRENT_DIRECTORY + filePath, columnName, timestampPattern); diff --git a/src/main/java/com/maxsoft/intelliapi/stepimpl/database/MongoStepImpl.java b/src/main/java/com/maxsoft/intelliapi/stepimpl/database/MongoStepImpl.java index 6dc6650..8688843 100644 --- a/src/main/java/com/maxsoft/intelliapi/stepimpl/database/MongoStepImpl.java +++ b/src/main/java/com/maxsoft/intelliapi/stepimpl/database/MongoStepImpl.java @@ -9,7 +9,7 @@ import java.util.List; import static com.maxsoft.intelliapi.util.FrameworkUtil.*; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.DataStoreProcessor.*; /** diff --git a/src/main/java/com/maxsoft/intelliapi/util/DataStoreProcessor.java b/src/main/java/com/maxsoft/intelliapi/util/DataStoreProcessor.java index 9ac691c..15fd7d7 100644 --- a/src/main/java/com/maxsoft/intelliapi/util/DataStoreProcessor.java +++ b/src/main/java/com/maxsoft/intelliapi/util/DataStoreProcessor.java @@ -5,7 +5,7 @@ import java.security.InvalidParameterException; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.LogUtil.printError; import static com.maxsoft.intelliapi.util.LogUtil.printInfo; diff --git a/src/main/java/com/maxsoft/intelliapi/util/FrameworkUtil.java b/src/main/java/com/maxsoft/intelliapi/util/FrameworkUtil.java index 5d29a35..a86136d 100644 --- a/src/main/java/com/maxsoft/intelliapi/util/FrameworkUtil.java +++ b/src/main/java/com/maxsoft/intelliapi/util/FrameworkUtil.java @@ -10,7 +10,7 @@ import java.util.Date; import java.util.Random; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.LogUtil.printInfo; import static java.time.temporal.ChronoUnit.SECONDS; @@ -47,7 +47,7 @@ public static void replaceAllColumnValuesToCurrentTimestamp(String filePath, Str } public static void printTestingEnvDetails() { - printInfo("Configurations of Test Execution Environment\n\n"); + printInfo("Configurations of test execution environment\n\n"); printInfo("Operating System: " + OS); printInfo("Environment: " + ENVIRONMENT.toUpperCase()); printInfo("Base URL: " + EnvironmentPropertyReader.getBaseUrl()); diff --git a/src/main/java/com/maxsoft/intelliapi/util/fileoperator/CsvFile.java b/src/main/java/com/maxsoft/intelliapi/util/fileoperator/CsvFile.java index a932855..a6203ff 100644 --- a/src/main/java/com/maxsoft/intelliapi/util/fileoperator/CsvFile.java +++ b/src/main/java/com/maxsoft/intelliapi/util/fileoperator/CsvFile.java @@ -6,7 +6,7 @@ import java.io.*; import java.util.List; -import static com.maxsoft.intelliapi.common.Constants.CURRENT_DIRECTORY; +import static com.maxsoft.intelliapi.Constants.CURRENT_DIRECTORY; /** * Project Name : MaxSoft-IntelliAPI diff --git a/src/main/java/com/maxsoft/intelliapi/util/fileoperator/TextFile.java b/src/main/java/com/maxsoft/intelliapi/util/fileoperator/TextFile.java index 86c0099..f06de29 100644 --- a/src/main/java/com/maxsoft/intelliapi/util/fileoperator/TextFile.java +++ b/src/main/java/com/maxsoft/intelliapi/util/fileoperator/TextFile.java @@ -7,8 +7,8 @@ import java.util.Scanner; import static com.maxsoft.intelliapi.util.FrameworkUtil.isTrue; -import static com.maxsoft.intelliapi.common.Constants.IS_AUTHENTICATION_REQUIRED; -import static com.maxsoft.intelliapi.common.Constants.RETRIEVE_TOKEN_FROM_TEXT_FILE; +import static com.maxsoft.intelliapi.Constants.IS_AUTHENTICATION_REQUIRED; +import static com.maxsoft.intelliapi.Constants.RETRIEVE_TOKEN_FROM_TEXT_FILE; import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario; import static com.maxsoft.intelliapi.util.LogUtil.printError; import static com.maxsoft.intelliapi.util.LogUtil.printInfo; diff --git a/src/main/java/com/maxsoft/intelliapi/util/reader/ApiDocumentReader.java b/src/main/java/com/maxsoft/intelliapi/util/reader/ApiDocumentReader.java index e5de810..8ceaee0 100644 --- a/src/main/java/com/maxsoft/intelliapi/util/reader/ApiDocumentReader.java +++ b/src/main/java/com/maxsoft/intelliapi/util/reader/ApiDocumentReader.java @@ -9,7 +9,7 @@ import java.io.IOException; import java.security.InvalidParameterException; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; import static com.maxsoft.intelliapi.util.DataStoreProcessor.saveValueForScenario; /** diff --git a/src/main/java/com/maxsoft/intelliapi/util/reader/EnvironmentPropertyReader.java b/src/main/java/com/maxsoft/intelliapi/util/reader/EnvironmentPropertyReader.java index e0d989e..c9d483d 100644 --- a/src/main/java/com/maxsoft/intelliapi/util/reader/EnvironmentPropertyReader.java +++ b/src/main/java/com/maxsoft/intelliapi/util/reader/EnvironmentPropertyReader.java @@ -2,7 +2,7 @@ import java.security.InvalidParameterException; -import static com.maxsoft.intelliapi.common.Constants.*; +import static com.maxsoft.intelliapi.Constants.*; /** * Project Name : MaxSoft-IntelliAPI diff --git a/src/test/resources/api_document/dev_api_doc.xlsx b/src/test/resources/api_document/dev_api_doc.xlsx index 83b1273..3fbcf9f 100644 Binary files a/src/test/resources/api_document/dev_api_doc.xlsx and b/src/test/resources/api_document/dev_api_doc.xlsx differ diff --git a/src/test/resources/api_document/qa_api_doc.xlsx b/src/test/resources/api_document/qa_api_doc.xlsx index 3500b73..1f04e2f 100644 Binary files a/src/test/resources/api_document/qa_api_doc.xlsx and b/src/test/resources/api_document/qa_api_doc.xlsx differ diff --git a/src/test/resources/api_document/uat_api_doc.xlsx b/src/test/resources/api_document/uat_api_doc.xlsx index 3500b73..1f04e2f 100644 Binary files a/src/test/resources/api_document/uat_api_doc.xlsx and b/src/test/resources/api_document/uat_api_doc.xlsx differ diff --git a/src/test/resources/csv/timestamp.csv b/src/test/resources/csv/timestamp.csv index 7480781..5e354be 100644 --- a/src/test/resources/csv/timestamp.csv +++ b/src/test/resources/csv/timestamp.csv @@ -1,18 +1,18 @@ "userId","timestamp" -"17","2021-01-04T14:28:24.931Z" -"18","2021-01-04T14:28:24.938Z" -"19","2021-01-04T14:28:24.940Z" -"20","2021-01-04T14:28:24.942Z" -"21","2021-01-04T14:28:24.944Z" -"23","2021-01-04T14:28:24.947Z" -"26","2021-01-04T14:28:24.949Z" -"27","2021-01-04T14:28:24.952Z" -"29","2021-01-04T14:28:24.954Z" -"30","2021-01-04T14:28:24.956Z" -"32","2021-01-04T14:28:24.958Z" -"33","2021-01-04T14:28:24.960Z" -"34","2021-01-04T14:28:24.962Z" -"35","2021-01-04T14:28:24.964Z" -"36","2021-01-04T14:28:24.966Z" -"39","2021-01-04T14:28:24.968Z" -"40","2021-01-04T14:28:24.970Z" +"17","2021-01-18T12:02:32.218Z" +"18","2021-01-18T12:02:32.223Z" +"19","2021-01-18T12:02:32.224Z" +"20","2021-01-18T12:02:32.225Z" +"21","2021-01-18T12:02:32.226Z" +"23","2021-01-18T12:02:32.227Z" +"26","2021-01-18T12:02:32.228Z" +"27","2021-01-18T12:02:32.229Z" +"29","2021-01-18T12:02:32.230Z" +"30","2021-01-18T12:02:32.231Z" +"32","2021-01-18T12:02:32.232Z" +"33","2021-01-18T12:02:32.233Z" +"34","2021-01-18T12:02:32.234Z" +"35","2021-01-18T12:02:32.235Z" +"36","2021-01-18T12:02:32.238Z" +"39","2021-01-18T12:02:32.240Z" +"40","2021-01-18T12:02:32.241Z" diff --git a/src/test/resources/csv/userIds.csv b/src/test/resources/csv/userIds.csv index fe8805c..99754f2 100644 --- a/src/test/resources/csv/userIds.csv +++ b/src/test/resources/csv/userIds.csv @@ -1,13 +1,5 @@ "userId" -"37" -"38" -"39" -"40" -"41" -"42" -"43" -"44" -"45" -"46" -"47" -"48" +"23" +"24" +"25" +"26"