From 279c27afcdb623d90c403bd1aed3d7ef6aa77aa5 Mon Sep 17 00:00:00 2001 From: dadgam3er Date: Tue, 8 Oct 2024 10:53:03 -0400 Subject: [PATCH] restAssuredIntro --- .gitignore | 38 +++++ .idea/.gitignore | 3 + .idea/encodings.xml | 7 + .idea/misc.xml | 14 ++ pom.xml | 134 ++++++++++++++++++ .../zacksolutions/DayOne/HttpRequest.java | 49 +++++++ testNG.xml | 0 7 files changed, 245 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 pom.xml create mode 100644 src/test/java/zacksolutions/DayOne/HttpRequest.java create mode 100644 testNG.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e122dea --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b85344b --- /dev/null +++ b/pom.xml @@ -0,0 +1,134 @@ + + 4.0.0 + + zacksolutions + restAssured + 1.0-SNAPSHOT + jar + + restAssured + http://maven.apache.org + + + UTF-8 + + + + + com.fasterxml.jackson.core + jackson-databind + 2.18.0 + + + + io.github.bonigarcia + webdrivermanager + 5.9.2 + + + com.aventstack + extentreports + 5.1.2 + + + + org.testng + testng + 7.10.2 + compile + + + + org.seleniumhq.selenium + selenium-java + 4.25.0 + + + + org.apache.poi + poi + 5.3.0 + + + + org.apache.poi + poi-ooxml + 5.3.0 + + + + org.apache.poi + poi-scratchpad + 5.3.0 + + + + org.apache.poi + poi-ooxml-schemas + 4.1.2 + + + + org.apache.logging.log4j + log4j-core + 2.24.0 + + + + io.cucumber + cucumber-java + 7.19.0 + + + + io.cucumber + cucumber-testng + 7.19.0 + + + io.cucumber + cucumber-java + 7.14.1 + + + + io.rest-assured + rest-assured + 5.5.0 + test + + + + io.rest-assured + json-path + 5.5.0 + test + + + + io.rest-assured + json-schema-validator + 5.5.0 + + + + com.github.scribejava + scribejava-apis + 8.3.3 + runtime + + + + com.google.code.gson + gson + 2.11.0 + + + + io.rest-assured + xml-path + 5.5.0 + + + diff --git a/src/test/java/zacksolutions/DayOne/HttpRequest.java b/src/test/java/zacksolutions/DayOne/HttpRequest.java new file mode 100644 index 0000000..d66ab3a --- /dev/null +++ b/src/test/java/zacksolutions/DayOne/HttpRequest.java @@ -0,0 +1,49 @@ +package zacksolutions.DayOne; + +import org.testng.annotations.Test; + +import java.util.HashMap; + +import static io.restassured.RestAssured.*; +import static io.restassured.matcher.ResponseAwareMatcher.*; +import static org.hamcrest.Matcher.*; +import static org.hamcrest.Matchers.equalTo; + +public class HttpRequest { + public int id; + public String job; + @Test(priority = 1) + void getUser() { + when() + .get("https://reqres.in/api/users?page=2") + .then() + .statusCode(200) + .body("page", equalTo(2)) + .log().all(); + } + @Test(priority = 2) + void createUser(){ + HashMap data = new HashMap<>(); + data.put("name", "Zakaria"); + data.put("job", "Engineer"); + + id = given().contentType("Application/json").body(data).when().post("https://reqres.in/api/users").jsonPath().getInt("id"); + System.out.println(id); + } + @Test(priority = 3, dependsOnMethods = {"createUser"}) + void updateUser(){ + + HashMap data = new HashMap<>(); + data.put("name", "Sami"); + data.put("job", "Engineer/Surgeon"); + given().contentType("Application/json").body(data).when().put("https://reqres.in/api/users/" + id).then().statusCode(200).log().all(); + } + @Test(priority = 4) + void deleteUser(){ + when().delete("https://reqres.in/api/users/" + id).then().statusCode(204).log().all(); + System.out.println("id number: " + id + " is deleted"); + } + + + +} diff --git a/testNG.xml b/testNG.xml new file mode 100644 index 0000000..e69de29