Skip to content

Commit 55c177c

Browse files
committed
Fixed some step names and moved some steps to new class
1 parent 0fad3f0 commit 55c177c

File tree

5 files changed

+102
-80
lines changed

5 files changed

+102
-80
lines changed

specs/other/GET API From Data Store 1.spec

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tags: get_api, regression
1919

2020

2121
## Invoke GET Request from a response's JSON Path value with authentication
22+
2223
* Given that a user needs to invoke "Get urls"
2324
* And the user set the request authentication configurations as follows
2425
|Configuration |Configuration Value|
@@ -39,7 +40,7 @@ tags: get_api, regression
3940
|$[0].name |no | | |First photo |
4041
|$[1].name |no | | |Second photo |
4142
|$[3].name |no | | |Get all tasks with auth header |
42-
* And the user saves an API request url in the JSON Path <JSON Path> to a data store
43+
* Given that a user needs to invoke a GET API from the JSON Path value <JSON Path>
4344
* And the user set the request authentication configurations as follows
4445
|Configuration |Configuration Value|
4546
|------------------------------------------------------------------|-------------------|
@@ -51,5 +52,5 @@ tags: get_api, regression
5152
|-------------|-------------------|---------------|------------------------|-----------------------------------|
5253
|App-Name |no | | |IntelliAPI |
5354
|Organization |no | | |MaxSoft |
54-
* And invoke a GET request from the API request url saved in the data store
55+
* When the user invokes the GET API
5556
* Then the status code for the request is <Expected Response Status Code>

specs/other/GET API From Data Store 2.spec

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tags: get_api, regression
1919

2020

2121
## Invoke GET Request from a response's JSON Path value without authentication
22+
2223
* Given that a user needs to invoke "Get urls"
2324
* And the user set the request authentication configurations as follows
2425
|Configuration |Configuration Value|
@@ -39,6 +40,6 @@ tags: get_api, regression
3940
|$[0].name |no | | |First photo |
4041
|$[1].name |no | | |Second photo |
4142
|$[3].name |no | | |Get all tasks with auth header |
42-
* And the user saves an API request url in the JSON Path <JSON Path> to a data store
43-
* And invoke a GET request from the API request url saved in the data store
43+
* Given that a user needs to invoke a GET API from the JSON Path value <JSON Path>
44+
* When the user invokes the GET API
4445
* Then the status code for the request is <Expected Response Status Code>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.maxsoft.intelliapi.stepimpl.api;
2+
3+
import com.maxsoft.intelliapi.api.ApiInvoker;
4+
import com.thoughtworks.gauge.Step;
5+
import io.restassured.http.Headers;
6+
7+
import static com.maxsoft.intelliapi.Constants.*;
8+
import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.getHeaders;
9+
import static com.maxsoft.intelliapi.api.JsonRequestProcessor.getApiWithAuthMultipleHeaders;
10+
import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario;
11+
import static com.maxsoft.intelliapi.util.FrameworkUtil.isTrue;
12+
import static com.maxsoft.intelliapi.util.FrameworkUtil.readAccessToken;
13+
import static com.maxsoft.intelliapi.util.LogUtil.printInfo;
14+
15+
/**
16+
* Project Name : MaxSoft-IntelliAPI
17+
* Developer : Osanda Deshan
18+
* Version : 1.0.0
19+
* Date : 1/20/2021
20+
* Time : 6:21 PM
21+
* Description :
22+
**/
23+
24+
public class ApiRequestInvokerStepImpl {
25+
26+
/* Use this method when you need to pass the JSON request in previous step and the access token from the text file
27+
into the GET/POST/PUT/DELETE API. The "saveRequestAuthConfigurations" must use before using this step */
28+
@Step("When the user invokes the API")
29+
public void invokeApi() {
30+
String jsonRequest = String.valueOf(getSavedValueForScenario(VAR_API_JSON_REQUEST_BODY));
31+
String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST);
32+
String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST);
33+
34+
if (headerNamesList == null || headerNamesList.equals("") ||
35+
headerValuesList == null || headerValuesList.equals("")) {
36+
ApiInvoker.invoke(jsonRequest, new Headers());
37+
} else {
38+
ApiInvoker.invoke(jsonRequest, new Headers(getHeaders(headerNamesList, headerValuesList)));
39+
}
40+
}
41+
42+
/* Use this method to invoke a GET API from a request url in the response's JSON path.
43+
The "saveApiEndpointInResponseBody" must use before using this step */
44+
@Step("When the user invokes the GET API")
45+
public void doGetRequestFromDataStore() {
46+
String invokingEndpoint = getSavedValueForScenario(VAR_API_ENDPOINT);
47+
String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST);
48+
String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST);
49+
50+
String accessToken, isAuthenticationRequired, isAccessTokenRetrievedFromTextFile, accessTokenString;
51+
String accessTokenInFile = readAccessToken();
52+
53+
try {
54+
isAuthenticationRequired = getSavedValueForScenario(IS_AUTHENTICATION_REQUIRED).toLowerCase();
55+
isAccessTokenRetrievedFromTextFile = getSavedValueForScenario(RETRIEVE_TOKEN_FROM_TEXT_FILE).toLowerCase();
56+
accessTokenString = getSavedValueForScenario(MANUAL_TOKEN);
57+
} catch (Exception ex) {
58+
isAuthenticationRequired = "";
59+
isAccessTokenRetrievedFromTextFile = "";
60+
accessTokenString = "";
61+
}
62+
63+
if (isTrue(isAuthenticationRequired)) {
64+
if (isTrue(isAccessTokenRetrievedFromTextFile)) {
65+
accessToken = accessTokenInFile;
66+
} else {
67+
accessToken = accessTokenString;
68+
}
69+
} else {
70+
accessToken = "";
71+
}
72+
73+
printInfo("");
74+
printInfo("");
75+
printInfo("Invoked API Endpoint:\n" + invokingEndpoint + "\n\n");
76+
printInfo("HTTP Method is: GET\n\n");
77+
78+
if (headerNamesList == null || headerNamesList.equals("") ||
79+
headerValuesList == null || headerValuesList.equals("")) {
80+
getApiWithAuthMultipleHeaders(invokingEndpoint, accessToken, new Headers());
81+
} else {
82+
getApiWithAuthMultipleHeaders(invokingEndpoint, accessToken,
83+
new Headers(getHeaders(headerNamesList, headerValuesList)));
84+
}
85+
}
86+
}

src/main/java/com/maxsoft/intelliapi/stepimpl/api/ApiRequestPayloadConfigStepImpl.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
import java.util.List;
1010

11+
import static com.maxsoft.intelliapi.Constants.*;
1112
import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.*;
13+
import static com.maxsoft.intelliapi.api.ApiResponseProcessor.saveResponseJsonPathValue;
14+
import static com.maxsoft.intelliapi.util.DataStoreProcessor.*;
1215
import static com.maxsoft.intelliapi.util.FrameworkUtil.*;
13-
import static com.maxsoft.intelliapi.Constants.*;
1416
import static com.maxsoft.intelliapi.util.LogUtil.printInfo;
15-
import static com.maxsoft.intelliapi.util.DataStoreProcessor.*;
1617

1718
/**
1819
* Project Name : MaxSoft-IntelliAPI
@@ -31,6 +32,12 @@ public void apiToBeInvoked(String apiEndpointName) {
3132
initializeApiToBeInvoked(apiEndpointName);
3233
}
3334

35+
// Use this method before invoking a GET API from a request url in the response's JSON path
36+
@Step("Given that a user needs to invoke a GET API from the JSON Path value <jsonPath>")
37+
public void saveApiEndpointInResponseBody(String jsonPath) {
38+
saveResponseJsonPathValue(SCENARIO, VAR_API_ENDPOINT, jsonPath);
39+
}
40+
3441
// Use this method to replace the placeholders inside the API Endpoint in Excel
3542
@Step("And the user set values to the API endpoint placeholders as follows <table>")
3643
public void setApiEndpointReplacements(Table table) {

src/main/java/com/maxsoft/intelliapi/stepimpl/api/OtherStepImpl.java

+1-74
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
package com.maxsoft.intelliapi.stepimpl.api;
22

3-
import com.maxsoft.intelliapi.api.ApiInvoker;
43
import com.maxsoft.intelliapi.util.FrameworkUtil;
54
import com.thoughtworks.gauge.Step;
6-
import io.restassured.http.Headers;
75

8-
import static com.maxsoft.intelliapi.api.ApiRequestPayloadProcessor.getHeaders;
9-
import static com.maxsoft.intelliapi.Constants.*;
10-
import static com.maxsoft.intelliapi.api.ApiResponseProcessor.saveResponseJsonPathValue;
11-
import static com.maxsoft.intelliapi.api.JsonRequestProcessor.getApiWithAuthMultipleHeaders;
12-
import static com.maxsoft.intelliapi.util.DataStoreProcessor.getSavedValueForScenario;
13-
import static com.maxsoft.intelliapi.util.FrameworkUtil.isTrue;
14-
import static com.maxsoft.intelliapi.util.FrameworkUtil.readAccessToken;
15-
import static com.maxsoft.intelliapi.util.LogUtil.printInfo;
6+
import static com.maxsoft.intelliapi.Constants.CURRENT_DIRECTORY;
167

178
/**
189
* Project Name : MaxSoft-IntelliAPI
@@ -31,70 +22,6 @@ public void printTestingEnvDetails() {
3122
FrameworkUtil.printTestingEnvDetails();
3223
}
3324

34-
/* 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.
35-
The "saveRequestAuthConfigurations" must use before using this step */
36-
@Step("When the user invokes the API")
37-
public void invokeApi() {
38-
String jsonRequest = String.valueOf(getSavedValueForScenario(VAR_API_JSON_REQUEST_BODY));
39-
String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST);
40-
String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST);
41-
42-
if (headerNamesList == null || headerNamesList.equals("") ||
43-
headerValuesList == null || headerValuesList.equals("")) {
44-
ApiInvoker.invoke(jsonRequest, new Headers());
45-
} else {
46-
ApiInvoker.invoke(jsonRequest, new Headers(getHeaders(headerNamesList, headerValuesList)));
47-
}
48-
}
49-
50-
@Step("And the user saves an API request url in the JSON Path <jsonPath> to a data store")
51-
public void saveApiEndpointInResponseBody(String jsonPath) {
52-
saveResponseJsonPathValue(SCENARIO, VAR_API_ENDPOINT, jsonPath);
53-
}
54-
55-
@Step("And invoke a GET request from the API request url saved in the data store")
56-
public void doGetRequestFromDataStore() {
57-
String invokingEndpoint = getSavedValueForScenario(VAR_API_ENDPOINT);
58-
String headerNamesList = getSavedValueForScenario(VAR_API_HEADER_NAMES_LIST);
59-
String headerValuesList = getSavedValueForScenario(VAR_API_HEADER_VALUES_LIST);
60-
61-
String accessToken, isAuthenticationRequired, isAccessTokenRetrievedFromTextFile, accessTokenString;
62-
String accessTokenInFile = readAccessToken();
63-
64-
try {
65-
isAuthenticationRequired = getSavedValueForScenario(IS_AUTHENTICATION_REQUIRED).toLowerCase();
66-
isAccessTokenRetrievedFromTextFile = getSavedValueForScenario(RETRIEVE_TOKEN_FROM_TEXT_FILE).toLowerCase();
67-
accessTokenString = getSavedValueForScenario(MANUAL_TOKEN);
68-
} catch (Exception ex) {
69-
isAuthenticationRequired = "";
70-
isAccessTokenRetrievedFromTextFile = "";
71-
accessTokenString = "";
72-
}
73-
74-
if (isTrue(isAuthenticationRequired)) {
75-
if (isTrue(isAccessTokenRetrievedFromTextFile)) {
76-
accessToken = accessTokenInFile;
77-
} else {
78-
accessToken = accessTokenString;
79-
}
80-
} else {
81-
accessToken = "";
82-
}
83-
84-
printInfo("");
85-
printInfo("");
86-
printInfo("Invoked API Endpoint:\n" + invokingEndpoint + "\n\n");
87-
printInfo("HTTP Method is: GET\n\n");
88-
89-
if (headerNamesList == null || headerNamesList.equals("") ||
90-
headerValuesList == null || headerValuesList.equals("")) {
91-
getApiWithAuthMultipleHeaders(invokingEndpoint, accessToken, new Headers());
92-
} else {
93-
getApiWithAuthMultipleHeaders(invokingEndpoint, accessToken,
94-
new Headers(getHeaders(headerNamesList, headerValuesList)));
95-
}
96-
}
97-
9825
// Use this method to replace the rows of a column in a given CSV with the timestamp
9926
@Step("And replace the row values in <columnName> column of the CSV <filePath> into the <timestampPattern> timestamp pattern")
10027
public void replaceAllColumnValuesToCurrentTimestamp(String columnName, String filePath, String timestampPattern) {

0 commit comments

Comments
 (0)