Skip to content

Commit 42e507a

Browse files
committed
version1
0 parents  commit 42e507a

43 files changed

Lines changed: 1180 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.classpath

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
31+
<attributes>
32+
<attribute name="maven.pomderived" value="true"/>
33+
</attributes>
34+
</classpathentry>
35+
<classpathentry kind="output" path="target/classes"/>
36+
</classpath>

.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Rest-Assured-Framework</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3+
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.source=1.5
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>1.0</groupId>
6+
<artifactId>Rest-Assured-Framework</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>io.rest-assured</groupId>
12+
<artifactId>rest-assured</artifactId>
13+
<version>3.1.1</version>
14+
</dependency>
15+
16+
<dependency>
17+
<groupId>org.testng</groupId>
18+
<artifactId>testng</artifactId>
19+
<version>6.8</version>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>com.googlecode.json-simple</groupId>
24+
<artifactId>json-simple</artifactId>
25+
<version>1.1.1</version>
26+
</dependency>
27+
28+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
29+
<dependency>
30+
<groupId>org.apache.poi</groupId>
31+
<artifactId>poi</artifactId>
32+
<version>4.0.1</version>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.apache.poi</groupId>
37+
<artifactId>poi-ooxml</artifactId>
38+
<version>3.9</version>
39+
</dependency>
40+
41+
42+
</dependencies>
43+
</project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package javaTest;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
8+
import org.apache.poi.hssf.usermodel.HSSFCell;
9+
import org.apache.poi.hssf.usermodel.HSSFSheet;
10+
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
11+
import org.apache.poi.ss.usermodel.Workbook;
12+
13+
import io.restassured.response.Response;
14+
15+
public class ExcelOperation {
16+
17+
public static void readExcel(String filePath, String fileName, String sheetName) throws IOException {
18+
19+
//initializing vars
20+
File file = new File(filePath + "\\" + fileName);
21+
FileInputStream inputStream = new FileInputStream(file);
22+
23+
String reqUrl = null;
24+
String method = null;
25+
Workbook workbook = null;
26+
Response resp;
27+
28+
String fileExtensionName = fileName.substring(fileName.indexOf("."));
29+
if (fileExtensionName.equals(".xls")) {
30+
workbook = new HSSFWorkbook(inputStream);
31+
HSSFSheet sheet = (HSSFSheet) workbook.getSheetAt(0);
32+
33+
System.out.println("Total APIs are : "+ sheet.getLastRowNum());
34+
for(int i=1; i<=sheet.getLastRowNum();i++) {
35+
36+
reqUrl = sheet.getRow(i).getCell(1).toString();
37+
method = sheet.getRow(i).getCell(2).toString();
38+
39+
System.out.println("Processing "+ i +reqUrl+" "+method);
40+
41+
//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) {
43+
FileOutputStream f2 = new FileOutputStream(file);
44+
HSSFCell cell = sheet.getRow(i).createCell(4);
45+
cell.setCellValue("PASS");
46+
System.out.println("writing PASS"+cell.getRowIndex() +" : " + cell.getColumnIndex());
47+
workbook.write(f2);
48+
f2.close();
49+
}
50+
else {
51+
FileOutputStream f2 = new FileOutputStream(file);
52+
HSSFCell cell = sheet.getRow(i).createCell(4);
53+
cell.setCellValue("FAIL");
54+
workbook.write(f2);
55+
f2.close();
56+
}
57+
58+
}
59+
}
60+
}
61+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package javaTest;
2+
3+
import java.io.IOException;
4+
5+
import org.testng.annotations.Test;
6+
7+
// framework to test whether any api call fail to response for what it is made.
8+
public class JavaTest {
9+
10+
public ExcelOperation excelOp;
11+
12+
//TestNg will analyze for this annotation and execute script from here
13+
@Test
14+
public void testResponseCode() throws IOException {
15+
16+
//initializing imp variables
17+
String filePath = "C:\\API-Test-Excel";
18+
String fileName = "Test-Api.xls";
19+
String sheetName = "Sheet1";
20+
21+
ExcelOperation.readExcel(filePath, fileName, sheetName);
22+
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package javaTest;
2+
3+
import static io.restassured.RestAssured.get;
4+
5+
import io.restassured.response.Response;
6+
7+
public class sendRequest {
8+
9+
public static int testResponseCode(String reqUrl, String methodName, double expectedCode) {
10+
System.out.println(reqUrl);
11+
System.out.println(expectedCode);
12+
Response resp = null;
13+
int code;
14+
15+
if(methodName.equalsIgnoreCase("get")) {
16+
resp = get(reqUrl);
17+
}
18+
code = resp.getStatusCode();
19+
20+
if(code == Math.round(expectedCode)) {
21+
return 0;
22+
}
23+
else {
24+
return -1;
25+
}
26+
27+
}
28+
29+
30+
}

src/test/resources/Test-Api.xls

39 KB
Binary file not shown.

target/test-classes/Test-Api.xls

39 KB
Binary file not shown.

0 commit comments

Comments
 (0)