dayFive:XML Parsing
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package zacksolutions.DayFive;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class ParsingXMLResTest {
|
||||
@Test
|
||||
public void testXMLRes(){
|
||||
given()
|
||||
.when()
|
||||
.get("https://api.nbp.pl/api/exchangerates/tables/a/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Type", "application/json; charset=utf-8")
|
||||
.log().all();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package zacksolutions.DayFour;
|
||||
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
import io.restassured.response.Response;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static io.restassured.RestAssured.when;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class ParsingJSONResDataTest {
|
||||
|
||||
@Test
|
||||
void JSONResData(){
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.when()
|
||||
.get("http://localhost:3000/store/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Type", "application/json")
|
||||
.body("books[2].Name", equalTo("The Lord of the Rings"));
|
||||
}
|
||||
@Test
|
||||
void returnBooks(){
|
||||
// Create JSON object for the book data
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("Author", "George R. R. Martin");
|
||||
data.put("Category", "Fantasy");
|
||||
data.put("SerialNum", "D34C");
|
||||
data.put("Price", 14.99);
|
||||
data.put("Name", "A Song Of Ice and Fire");
|
||||
|
||||
//post the book to the server
|
||||
given().contentType("text/plain; charset=utf-8")
|
||||
.body(data.toString())
|
||||
.when().post("http://localhost:3000/store/books")
|
||||
.then().statusCode(201)
|
||||
.body("Price", equalTo(14.99f))
|
||||
.log().all();
|
||||
|
||||
}
|
||||
@Test
|
||||
void getTitleJSONOBJECT(){
|
||||
Response res =
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.when()
|
||||
.get("http://localhost:3000/store/");
|
||||
JSONObject jsonObject = new JSONObject(res.asString());
|
||||
int length = jsonObject.getJSONArray("books").length();
|
||||
|
||||
boolean status = false;
|
||||
for (int i = 0; i < length; i++) {
|
||||
String title = jsonObject.getJSONArray("books").getJSONObject(i).get("Name").toString();
|
||||
//System.out.println("Books number " + i + " is " + title);
|
||||
if (title.equalsIgnoreCase("1984")){
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(status);
|
||||
/*
|
||||
List<String> booksTitle = new JsonPath(res.asString()).getList("Name");
|
||||
for (String title : booksTitle) {
|
||||
|
||||
System.out.println(title);
|
||||
}
|
||||
*/
|
||||
}
|
||||
@Test
|
||||
void getPrices(){
|
||||
Response res = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.when().get("http://localhost:3000/store/");
|
||||
JSONObject jsonObject = new JSONObject(res.asString());
|
||||
int numOfBooks = 0;
|
||||
for (int i = 0; i < jsonObject.getJSONArray("books").length(); i++) {
|
||||
String title = jsonObject.getJSONArray("books").getJSONObject(i).get("Name").toString();
|
||||
double price = jsonObject.getJSONArray("books").getJSONObject(i).getDouble("Price");
|
||||
if (price >10.00){
|
||||
System.out.println(title);
|
||||
numOfBooks ++;
|
||||
}
|
||||
}
|
||||
System.out.println(numOfBooks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package zacksolutions.DayThree;
|
||||
|
||||
import io.restassured.response.Response;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static io.restassured.RestAssured.when;
|
||||
|
||||
public class CookiesDemoTest {
|
||||
//@Test
|
||||
void getCookies(){
|
||||
given()
|
||||
.when().get("https://www.google.com/")
|
||||
.then().cookie("AEC","").log().all();
|
||||
}
|
||||
@Test(priority = 2)
|
||||
void getCookiesInfo() {
|
||||
Response res = given()
|
||||
.when().get("https://www.google.com/");
|
||||
String cookieVal = res.getCookie("AEC");
|
||||
System.out.println("The value of AEC cookie is: " + cookieVal);
|
||||
|
||||
Map<String,String> cookiesValue = res.getCookies();
|
||||
for (String key : cookiesValue.keySet()) {
|
||||
String cookiesVal = res.getCookie(key);
|
||||
System.out.println( key + " ===> " + cookiesVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package zacksolutions.DayThree;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
|
||||
public class PathandQuerryParTest {
|
||||
@Test
|
||||
void testQuerryPath(){
|
||||
given().pathParams("mypath", "students")
|
||||
.queryParam("id", 9)
|
||||
.when()
|
||||
.get("http://127.0.0.1:3000/{mypath}")
|
||||
.then().statusCode(200).log().all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user