Skip to content

Commit 12e89aa

Browse files
committed
Request body from excel
1 parent 41162cc commit 12e89aa

15 files changed

Lines changed: 53 additions & 63 deletions

File tree

pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@
3838
<version>3.9</version>
3939
</dependency>
4040

41-
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
41+
<!-- https://mvnrepository.com/artifact/org.json/json -->
4242
<dependency>
43-
<groupId>com.googlecode.json-simple</groupId>
44-
<artifactId>json-simple</artifactId>
45-
<version>1.1.1</version>
43+
<groupId>org.json</groupId>
44+
<artifactId>json</artifactId>
45+
<version>20180130</version>
4646
</dependency>
4747

48+
4849
</dependencies>
4950
</project>

src/test/java/javaTest/ExcelOperation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public static void readExcel(String filePath, String fileName, String sheetName)
3939
System.out.println("Processing "+i+") " +reqUrl+" "+method);
4040

4141
//call to method which sends request
42-
if(sendRequest.testResponseCode(reqUrl,sheet.getRow(i).getCell(2).toString(),Double.parseDouble(sheet.getRow(i).getCell(3).toString()))==0) {
42+
if(sendRequest.testResponseCode(reqUrl,sheet.getRow(i).getCell(2).toString(),Double.parseDouble(sheet.getRow(i).getCell(3).toString()),
43+
sheet.getRow(i).getCell(5).toString())==0) {
4344
FileOutputStream f2 = new FileOutputStream(file);
4445
HSSFCell cell = sheet.getRow(i).createCell(4);
4546
cell.setCellValue("PASS");

src/test/java/javaTest/sendRequest.java

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static io.restassured.RestAssured.get;
44

5-
import org.json.simple.JSONObject;
5+
import org.json.JSONObject;
66
import org.testng.annotations.Test;
77

88
import io.restassured.RestAssured;
@@ -11,59 +11,47 @@
1111

1212
public class sendRequest {
1313

14-
@Test
15-
public static int testResponseCode(String reqUrl, String methodName, double expectedCode) {
16-
System.out.println("method : "+methodName);
17-
18-
System.out.println("expected code is :- "+expectedCode);
14+
@Test
15+
public static int testResponseCode(String reqUrl, String methodName, double expectedCode, String jsonBody) {
16+
System.out.println("method : " + methodName);
17+
System.out.println("expected code is :- " + expectedCode);
18+
if (!jsonBody.contains("NA")) {
19+
JSONObject jsonobj = new JSONObject(jsonBody);
20+
}
1921
Response resp = null;
2022
int code = 0;
21-
RestAssured.baseURI =reqUrl;
23+
RestAssured.baseURI = reqUrl;
2224
RequestSpecification request = RestAssured.given();
23-
24-
if(methodName.equalsIgnoreCase("get")) {
25+
26+
if (methodName.equalsIgnoreCase("get")) {
2527
resp = get(reqUrl);
26-
}
27-
else if(methodName.equalsIgnoreCase("post")) {
28-
JSONObject requestParams = new JSONObject();
29-
requestParams.put("name", "morpheus");
30-
requestParams.put("job", "leader");
31-
28+
} else if (methodName.equalsIgnoreCase("post")) {
29+
3230
request.header("Content-Type", "application/json");
33-
34-
request.body(requestParams.toJSONString());
35-
3631
resp = request.post();
37-
}else if(methodName.equalsIgnoreCase("put")) {
38-
39-
JSONObject requestParams = new JSONObject();
40-
requestParams.put("name", "morpheus");
41-
requestParams.put("job", "zion resident");
42-
32+
33+
} else if (methodName.equalsIgnoreCase("put")) {
34+
4335
request.header("Content-Type", "application/json");
44-
45-
request.body(requestParams.toJSONString());
46-
4736
resp = request.put();
48-
}else if(methodName.equalsIgnoreCase("delete")) {
37+
38+
} else if (methodName.equalsIgnoreCase("delete")) {
4939

5040
request.header("Content-Type", "application/json");
51-
5241
resp = request.delete();
42+
5343
}
54-
System.out.println(methodName+" method :"+ code);
55-
if(resp != null) {
44+
System.out.println(methodName + " method :" + code);
45+
if (resp != null) {
5646
code = resp.getStatusCode();
57-
5847
}
59-
60-
if(code == Math.round(expectedCode)) {
48+
49+
if (code == Math.round(expectedCode)) {
6150
return 0;
62-
}
63-
else {
51+
} else {
6452
return -1;
6553
}
66-
54+
6755
}
6856

6957
}

src/test/resources/Test-Api.xls

512 Bytes
Binary file not shown.

target/test-classes/Test-Api.xls

512 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.
-316 Bytes
Binary file not shown.

test-output/Default suite/Default test.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ <h2 align='center'>Default test</h2><table border='1' align="center">
5757
<tr>
5858
<td>Tests passed/Failed/Skipped:</td><td>1/0/0</td>
5959
</tr><tr>
60-
<td>Started on:</td><td>Mon Dec 17 23:54:09 IST 2018</td>
60+
<td>Started on:</td><td>Wed Dec 19 01:27:02 IST 2018</td>
6161
</tr>
62-
<tr><td>Total time:</td><td>12 seconds (12691 ms)</td>
62+
<tr><td>Total time:</td><td>12 seconds (12010 ms)</td>
6363
</tr><tr>
6464
<td>Included groups:</td><td></td>
6565
</tr><tr>
@@ -77,8 +77,8 @@ <h2 align='center'>Default test</h2><table border='1' align="center">
7777
<tr>
7878
<td title='javaTest.JavaTest.testResponseCode()'><b>testResponseCode</b><br>Test class: javaTest.JavaTest</td>
7979
<td></td>
80-
<td>12</td>
81-
<td>javaTest.JavaTest@58651fd0</td></tr>
80+
<td>11</td>
81+
<td>javaTest.JavaTest@5419f379</td></tr>
8282
</table><p>
8383
</body>
8484
</html>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!-- Generated by org.testng.reporters.JUnitXMLReporter -->
3-
<testsuite hostname="SAGAR" name="Default test" tests="1" failures="0" timestamp="17 Dec 2018 18:24:22 GMT" time="12.691" errors="0">
4-
<testcase name="testResponseCode" time="12.672" classname="javaTest.JavaTest"/>
3+
<testsuite hostname="SAGAR" name="Default test" tests="1" failures="0" timestamp="18 Dec 2018 19:57:14 GMT" time="12.01" errors="0">
4+
<testcase name="testResponseCode" time="11.993" classname="javaTest.JavaTest"/>
55
</testsuite> <!-- Default test -->

test-output/emailable-report.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
<body>
3232
<table cellspacing="0" cellpadding="0" class="result">
3333
<tr><th>Test</th><th class="numi">Methods<br/>Passed</th><th class="numi">Scenarios<br/>Passed</th><th class="numi"># skipped</th><th class="numi"># failed</th><th class="numi">Total<br/>Time</th><th class="numi">Included<br/>Groups</th><th class="numi">Excluded<br/>Groups</th></tr>
34-
<tr><td style="text-align:left;padding-right:2em">Default test</td><td class="numi">1</td><td class="numi">1</td><td class="numi">0</td><td class="numi">0</td><td class="numi">12.7 seconds</td><td class="numi"></td><td class="numi"></td></tr>
34+
<tr><td style="text-align:left;padding-right:2em">Default test</td><td class="numi">1</td><td class="numi">1</td><td class="numi">0</td><td class="numi">0</td><td class="numi">12.0 seconds</td><td class="numi"></td><td class="numi"></td></tr>
3535
</table>
3636
<table cellspacing="0" cellpadding="0" class="passed" id="summary">
3737
<tr><th>Class</th><th>Method</th><th># of<br/>Scenarios</th><th>Start</th><th>Time<br/>(ms)</th></tr>
3838
<tr><th colspan="4">Default test &#8212; passed</th></tr>
39-
<tr class="passedodd"><td rowspan="1">javaTest.JavaTest</td><td><a href="#m1"><b>testResponseCode</b> </a></td><td class="numi">1</td><td>1545071049521</td><td class="numi">12672</td></tr>
39+
<tr class="passedodd"><td rowspan="1">javaTest.JavaTest</td><td><a href="#m1"><b>testResponseCode</b> </a></td><td class="numi">1</td><td>1545163022216</td><td class="numi">11993</td></tr>
4040
</table>
4141
<h1>Default test</h1>
4242
<h2 id="m1">javaTest.JavaTest:testResponseCode</h2>

0 commit comments

Comments
 (0)