From 9499df8730dd84292d7d2c23ff4e953d38f78664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20H=C3=BCseyin=20Semiz?= Date: Mon, 9 Oct 2023 17:02:06 +0200 Subject: [PATCH 1/9] api 14 --- .idea/misc.xml | 2 +- src/test/java/com/example/runners/CukesRunner.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 3a8fb83..3484372 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/src/test/java/com/example/runners/CukesRunner.java b/src/test/java/com/example/runners/CukesRunner.java index d4e61e0..cd101cc 100644 --- a/src/test/java/com/example/runners/CukesRunner.java +++ b/src/test/java/com/example/runners/CukesRunner.java @@ -12,7 +12,7 @@ "html:target/default-html-reports.html" }, dryRun = false, - tags = "wip" + tags = "@api10" ) public class CukesRunner { } From 23a410bca563340ffc0625f258539f1bb0b81fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20H=C3=BCseyin=20Semiz?= Date: Mon, 9 Oct 2023 17:23:00 +0200 Subject: [PATCH 2/9] api 14 --- .idea/misc.xml | 2 +- src/test/java/com/example/runners/CukesRunner.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 5fbb43a..e5d6295 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/src/test/java/com/example/runners/CukesRunner.java b/src/test/java/com/example/runners/CukesRunner.java index 225299c..766a3c0 100644 --- a/src/test/java/com/example/runners/CukesRunner.java +++ b/src/test/java/com/example/runners/CukesRunner.java @@ -12,7 +12,7 @@ "html:target/default-html-reports.html" }, dryRun = false, - tags = "@api4" + tags = "@api3" ) public class CukesRunner { } From 2b1d697cd6fc69f0ee235a2aa560d4fa355606c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20H=C3=BCseyin=20Semiz?= Date: Thu, 12 Oct 2023 15:29:02 +0200 Subject: [PATCH 3/9] Regression Test --- src/test/java/com/example/runners/CukesRunner.java | 2 +- .../java/com/example/services/DeleteUserAccount.java | 4 ++-- .../com/example/services/PostToCreateRegisterUser.java | 10 +++++----- .../resources/features/deleteToVerifyLogin.feature | 1 + src/test/resources/features/deleteUserAccount.feature | 1 + src/test/resources/features/getAllBrandsList.feature | 1 + src/test/resources/features/getAllProductsList.feature | 1 + .../features/getUserAccountDetailByEmail.feature | 1 + .../resources/features/postToAllProductsList.feature | 1 + .../features/postToCreateRegisterUser.feature | 1 + .../resources/features/postToSearchProduct.feature | 1 + ...oSearchProductWithoutSearchProductParameter.feature | 1 + .../postToVerifyLoginWithInvalidDetails.feature | 3 ++- .../features/postToVerifyLoginWithValidDetails.feature | 1 + .../postToVerifyLoginWithoutEmailparameter.feature | 1 + .../features/putMethodToUpdateUserAccount.feature | 1 + src/test/resources/features/putToAllBrandsList.feature | 1 + 17 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/example/runners/CukesRunner.java b/src/test/java/com/example/runners/CukesRunner.java index d4e61e0..64756f3 100644 --- a/src/test/java/com/example/runners/CukesRunner.java +++ b/src/test/java/com/example/runners/CukesRunner.java @@ -12,7 +12,7 @@ "html:target/default-html-reports.html" }, dryRun = false, - tags = "wip" + tags = "@Regression" ) public class CukesRunner { } diff --git a/src/test/java/com/example/services/DeleteUserAccount.java b/src/test/java/com/example/services/DeleteUserAccount.java index dd6a0c8..1996475 100644 --- a/src/test/java/com/example/services/DeleteUserAccount.java +++ b/src/test/java/com/example/services/DeleteUserAccount.java @@ -12,8 +12,8 @@ public void DeleteUserAccountApi() { // Request Parameters - String email = "ahmetwd@dr.com"; - String password = "Ahmet123"; + String email = "ahmetwdy@drm.com"; + String password = "Ahmet12345y"; // API Endpoint String apiEndpoint = "/api/deleteAccount"; diff --git a/src/test/java/com/example/services/PostToCreateRegisterUser.java b/src/test/java/com/example/services/PostToCreateRegisterUser.java index 77c0b04..8ea7f1e 100644 --- a/src/test/java/com/example/services/PostToCreateRegisterUser.java +++ b/src/test/java/com/example/services/PostToCreateRegisterUser.java @@ -16,8 +16,8 @@ public void postToCreateRegisterUser() { // JSON Request Body String requestBody = "{" - + "\"name\":\"John Dorec\"," - + "\"email\":\"johndorec@example.com\"," + + "\"name\":\"John Doreca\"," + + "\"email\":\"johndorecaa@example.com\"," + "\"password\":\"securedpassword\"," + "\"title\":\"Mr\"," + "\"birth_date\":\"01\"," @@ -41,9 +41,9 @@ public void postToCreateRegisterUser() { // Perform API request and validate response response= RestAssured.given() .contentType(ContentType.MULTIPART) - .multiPart("name", "Ahmet") - .multiPart("email", "ahmetwd@drm.com") - .multiPart("password", "Ahmet12345") + .multiPart("name", "Ahmetz") + .multiPart("email", "ahmetwdz@drm.com") + .multiPart("password", "Ahmet12345z") .multiPart("title", "Mr") .multiPart("birth_date", "10") .multiPart("birth_month", "12") diff --git a/src/test/resources/features/deleteToVerifyLogin.feature b/src/test/resources/features/deleteToVerifyLogin.feature index b66e57b..e410d2e 100644 --- a/src/test/resources/features/deleteToVerifyLogin.feature +++ b/src/test/resources/features/deleteToVerifyLogin.feature @@ -1,3 +1,4 @@ +@Regression Feature: DELETE To Verify Login @api9 diff --git a/src/test/resources/features/deleteUserAccount.feature b/src/test/resources/features/deleteUserAccount.feature index 5bb1734..5c5be71 100644 --- a/src/test/resources/features/deleteUserAccount.feature +++ b/src/test/resources/features/deleteUserAccount.feature @@ -1,3 +1,4 @@ +@Regression Feature: Account Deletion @api12 Scenario: Delete an account with valid credentials diff --git a/src/test/resources/features/getAllBrandsList.feature b/src/test/resources/features/getAllBrandsList.feature index 0b6d6c8..91fc28e 100644 --- a/src/test/resources/features/getAllBrandsList.feature +++ b/src/test/resources/features/getAllBrandsList.feature @@ -1,3 +1,4 @@ +@Regression Feature: Get All Brands List @api3 Scenario: API Test 3 diff --git a/src/test/resources/features/getAllProductsList.feature b/src/test/resources/features/getAllProductsList.feature index 3e3b66b..bcb6305 100644 --- a/src/test/resources/features/getAllProductsList.feature +++ b/src/test/resources/features/getAllProductsList.feature @@ -1,3 +1,4 @@ +@Regression Feature: Get All Products List Scenario: API Test 1 diff --git a/src/test/resources/features/getUserAccountDetailByEmail.feature b/src/test/resources/features/getUserAccountDetailByEmail.feature index d964cb5..687fbe7 100644 --- a/src/test/resources/features/getUserAccountDetailByEmail.feature +++ b/src/test/resources/features/getUserAccountDetailByEmail.feature @@ -1,3 +1,4 @@ +@Regression Feature: GET user account detail by email @api14 diff --git a/src/test/resources/features/postToAllProductsList.feature b/src/test/resources/features/postToAllProductsList.feature index 5ec22cc..7aef9de 100644 --- a/src/test/resources/features/postToAllProductsList.feature +++ b/src/test/resources/features/postToAllProductsList.feature @@ -1,3 +1,4 @@ +@Regression Feature: Post To All Products List @api2 diff --git a/src/test/resources/features/postToCreateRegisterUser.feature b/src/test/resources/features/postToCreateRegisterUser.feature index 213dc9a..fccd72d 100644 --- a/src/test/resources/features/postToCreateRegisterUser.feature +++ b/src/test/resources/features/postToCreateRegisterUser.feature @@ -1,3 +1,4 @@ +@Regression Feature: Post To Create And Register User @api11 Scenario: API Test 11 diff --git a/src/test/resources/features/postToSearchProduct.feature b/src/test/resources/features/postToSearchProduct.feature index aedb382..80e06a7 100644 --- a/src/test/resources/features/postToSearchProduct.feature +++ b/src/test/resources/features/postToSearchProduct.feature @@ -1,3 +1,4 @@ +@Regression Feature: Post To Search Product diff --git a/src/test/resources/features/postToSearchProductWithoutSearchProductParameter.feature b/src/test/resources/features/postToSearchProductWithoutSearchProductParameter.feature index b6b27f5..0af3785 100644 --- a/src/test/resources/features/postToSearchProductWithoutSearchProductParameter.feature +++ b/src/test/resources/features/postToSearchProductWithoutSearchProductParameter.feature @@ -1,3 +1,4 @@ +@Regression Feature: Post To Search Product Without Parameter @api5 diff --git a/src/test/resources/features/postToVerifyLoginWithInvalidDetails.feature b/src/test/resources/features/postToVerifyLoginWithInvalidDetails.feature index 3f31e16..01b8ff6 100644 --- a/src/test/resources/features/postToVerifyLoginWithInvalidDetails.feature +++ b/src/test/resources/features/postToVerifyLoginWithInvalidDetails.feature @@ -1,4 +1,5 @@ - Feature: POST To Verify Login with invalid details +@Regression +Feature: POST To Verify Login with invalid details @api10 Scenario: API Test 10 diff --git a/src/test/resources/features/postToVerifyLoginWithValidDetails.feature b/src/test/resources/features/postToVerifyLoginWithValidDetails.feature index 421699b..4a37a57 100644 --- a/src/test/resources/features/postToVerifyLoginWithValidDetails.feature +++ b/src/test/resources/features/postToVerifyLoginWithValidDetails.feature @@ -1,3 +1,4 @@ +@Regression Feature: Post TO Verify Login @api7 Scenario: API 7 diff --git a/src/test/resources/features/postToVerifyLoginWithoutEmailparameter.feature b/src/test/resources/features/postToVerifyLoginWithoutEmailparameter.feature index 550a6af..498e6db 100644 --- a/src/test/resources/features/postToVerifyLoginWithoutEmailparameter.feature +++ b/src/test/resources/features/postToVerifyLoginWithoutEmailparameter.feature @@ -1,3 +1,4 @@ +@Regression Feature: Verify missing email parameter @api8 Scenario: API 8 diff --git a/src/test/resources/features/putMethodToUpdateUserAccount.feature b/src/test/resources/features/putMethodToUpdateUserAccount.feature index 8780df2..43c080d 100644 --- a/src/test/resources/features/putMethodToUpdateUserAccount.feature +++ b/src/test/resources/features/putMethodToUpdateUserAccount.feature @@ -1,3 +1,4 @@ +@Regression Feature: PUT Method To Update User Account @api13 diff --git a/src/test/resources/features/putToAllBrandsList.feature b/src/test/resources/features/putToAllBrandsList.feature index 6598f2d..08d2bd5 100644 --- a/src/test/resources/features/putToAllBrandsList.feature +++ b/src/test/resources/features/putToAllBrandsList.feature @@ -1,3 +1,4 @@ +@Regression Feature: Put To All Brands List @api4 Scenario: API Test 4 From de92a6d5e6d63577fed4641bb0c3fe33eb9f292b Mon Sep 17 00:00:00 2001 From: Bilal Saglam <104862898+bilalsglm@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:53:52 +0200 Subject: [PATCH 4/9] Create README.md --- README.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b8f0eaa --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# AutomationExercise_API_Testing + +![GitHub last commit](https://img.shields.io/github/last-commit/githsem/AutomationExercise_API_Testing) +![GitHub](https://img.shields.io/github/license/githsem/AutomationExercise_API_Testing) +![GitHub top language](https://img.shields.io/github/languages/top/githsem/AutomationExercise_API_Testing) + +This project is a Java-based API testing exercise inspired by API Test Cases from [automationexercise.com](https://automationexercise.com/). It utilizes the following tools: RestAssured, Cucumber, and JUnit for automated testing and reporting. + +## Table of Contents + +- [Overview](#overview) +- [Prerequisites](#prerequisites) +- [Getting Started](#getting-started) +- [Usage](#usage) +- [Reports](#reports) +- [License](#license) + +## Overview + +The main objective of this project is to perform API testing. It is designed to automate the testing of various API endpoints, ensuring that they meet the expected functionality and behavior. + +## Prerequisites + +Before running the project, make sure you have the following prerequisites installed on your system: + +- Java Development Kit (JDK) +- Maven +- IDE (Eclipse, IntelliJ IDEA, etc.) + +## Getting Started + +1. Clone this repository to your local machine: + + ```shell + git clone https://github.com/githsem/AutomationExercise_API_Testing + + Open the project in your preferred IDE. + +Set up the required dependencies using Maven. + +Update the test configurations, such as the API endpoints and request parameters, in the appropriate test files. + +Run the tests by using JUnit or the test runner provided by your IDE. + +## Usage +You can use this project as a template to create your own API testing framework. Customize the test cases and configurations to match your specific requirements. Here are some key points to get started: + +Modify the test cases and test data according to your API endpoints. +Organize your test scenarios using Cucumber feature files. +Enhance and extend the project by adding additional test cases and utilities as needed. + +## Reports +After running the tests, you can find the test execution reports in the designated folder. These reports provide insights into the test results, including pass/fail status and any errors encountered during testing. + +## License +This project is licensed under the MIT License. + +Feel free to contribute, report issues, or suggest improvements. Happy testing! + + From a8c435f693373f80048591987f675101a68b0b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20H=C3=BCseyin=20Semiz?= <53379599+githsem@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:08:29 +0200 Subject: [PATCH 5/9] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b8f0eaa..5b57800 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# AutomationExercise_API_Testing +# Automation Exercise API Testing ![GitHub last commit](https://img.shields.io/github/last-commit/githsem/AutomationExercise_API_Testing) ![GitHub](https://img.shields.io/github/license/githsem/AutomationExercise_API_Testing) @@ -34,13 +34,13 @@ Before running the project, make sure you have the following prerequisites insta ```shell git clone https://github.com/githsem/AutomationExercise_API_Testing - Open the project in your preferred IDE. +2. Open the project in your preferred IDE. -Set up the required dependencies using Maven. +3. Set up the required dependencies using Maven. -Update the test configurations, such as the API endpoints and request parameters, in the appropriate test files. +4. Update the test configurations, such as the API endpoints and request parameters, in the appropriate test files. -Run the tests by using JUnit or the test runner provided by your IDE. +5. Run the tests by using JUnit or the test runner provided by your IDE. ## Usage You can use this project as a template to create your own API testing framework. Customize the test cases and configurations to match your specific requirements. Here are some key points to get started: From 51998109b668dbd8a500033ffbbbb6b50c15ba40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20H=C3=BCseyin=20Semiz?= Date: Thu, 12 Oct 2023 21:16:09 +0200 Subject: [PATCH 6/9] features refactoring --- .../step_defs/PostToCreateRegisterUser_stepDefs.java | 6 ++---- .../PostToVerifyLoginWithoutEmailParameter_stepDefs.java | 4 ++-- src/test/resources/features/deleteUserAccount.feature | 3 ++- src/test/resources/features/getAllBrandsList.feature | 1 + src/test/resources/features/getAllProductsList.feature | 1 + .../resources/features/postToCreateRegisterUser.feature | 6 +++--- src/test/resources/features/postToSearchProduct.feature | 2 +- ...ostToSearchProductWithoutSearchProductParameter.feature | 2 +- .../features/postToVerifyLoginWithValidDetails.feature | 2 +- .../postToVerifyLoginWithoutEmailparameter.feature | 7 ++++--- src/test/resources/features/putToAllBrandsList.feature | 3 ++- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/test/java/com/example/step_defs/PostToCreateRegisterUser_stepDefs.java b/src/test/java/com/example/step_defs/PostToCreateRegisterUser_stepDefs.java index a472e08..256e4b5 100644 --- a/src/test/java/com/example/step_defs/PostToCreateRegisterUser_stepDefs.java +++ b/src/test/java/com/example/step_defs/PostToCreateRegisterUser_stepDefs.java @@ -11,16 +11,14 @@ public class PostToCreateRegisterUser_stepDefs { PostToCreateRegisterUser postToCreateRegisterUser=new PostToCreateRegisterUser(); + @When("Create And Register User") public void create_and_register_user() { postToCreateRegisterUser.postToCreateRegisterUser(); } @Then("Validate that new user are registered") public void validate_that_new_user_are_registered() { - Assert.assertEquals("User created!", response.jsonPath().getString("message")); - } - @Then("Validate that status code is {string}") - public void validate_that_status_code_is(String string) { Assert.assertEquals(201, response.jsonPath().getInt("responseCode")); + Assert.assertEquals("User created!", response.jsonPath().getString("message")); } } diff --git a/src/test/java/com/example/step_defs/PostToVerifyLoginWithoutEmailParameter_stepDefs.java b/src/test/java/com/example/step_defs/PostToVerifyLoginWithoutEmailParameter_stepDefs.java index 01900be..4ec08c3 100644 --- a/src/test/java/com/example/step_defs/PostToVerifyLoginWithoutEmailParameter_stepDefs.java +++ b/src/test/java/com/example/step_defs/PostToVerifyLoginWithoutEmailParameter_stepDefs.java @@ -8,8 +8,8 @@ public class PostToVerifyLoginWithoutEmailParameter_stepDefs { PostToVerifyLoginWithoutEmail postToVerifyLoginWithoutEmail=new PostToVerifyLoginWithoutEmail(); - @When("Post to login witout email") - public void post_to_login_witout_email() { + @When("Post to login without email") + public void post_to_login_without_email() { postToVerifyLoginWithoutEmail.postToVerifyLoginWithoutEmail(); } @Then("Verify that invalid result") diff --git a/src/test/resources/features/deleteUserAccount.feature b/src/test/resources/features/deleteUserAccount.feature index 5c5be71..63fef57 100644 --- a/src/test/resources/features/deleteUserAccount.feature +++ b/src/test/resources/features/deleteUserAccount.feature @@ -1,6 +1,7 @@ @Regression Feature: Account Deletion -@api12 + + @api12 Scenario: Delete an account with valid credentials When Delete User Account Then Validate that Account was deleted diff --git a/src/test/resources/features/getAllBrandsList.feature b/src/test/resources/features/getAllBrandsList.feature index 91fc28e..2710d6c 100644 --- a/src/test/resources/features/getAllBrandsList.feature +++ b/src/test/resources/features/getAllBrandsList.feature @@ -1,5 +1,6 @@ @Regression Feature: Get All Brands List + @api3 Scenario: API Test 3 When Get All Brands List diff --git a/src/test/resources/features/getAllProductsList.feature b/src/test/resources/features/getAllProductsList.feature index bcb6305..2749add 100644 --- a/src/test/resources/features/getAllProductsList.feature +++ b/src/test/resources/features/getAllProductsList.feature @@ -1,6 +1,7 @@ @Regression Feature: Get All Products List + @api1 Scenario: API Test 1 When Get All Products List Then Validate that all products are listed \ No newline at end of file diff --git a/src/test/resources/features/postToCreateRegisterUser.feature b/src/test/resources/features/postToCreateRegisterUser.feature index fccd72d..89e8a0d 100644 --- a/src/test/resources/features/postToCreateRegisterUser.feature +++ b/src/test/resources/features/postToCreateRegisterUser.feature @@ -1,7 +1,7 @@ @Regression Feature: Post To Create And Register User -@api11 + + @api11 Scenario: API Test 11 When Create And Register User - Then Validate that new user are registered - And Validate that status code is "200" \ No newline at end of file + Then Validate that new user are registered \ No newline at end of file diff --git a/src/test/resources/features/postToSearchProduct.feature b/src/test/resources/features/postToSearchProduct.feature index 80e06a7..e140e0f 100644 --- a/src/test/resources/features/postToSearchProduct.feature +++ b/src/test/resources/features/postToSearchProduct.feature @@ -1,7 +1,7 @@ @Regression Feature: Post To Search Product - + @api5 Scenario: API Test 5 When Post To Search Product Then Validate that products list searched \ No newline at end of file diff --git a/src/test/resources/features/postToSearchProductWithoutSearchProductParameter.feature b/src/test/resources/features/postToSearchProductWithoutSearchProductParameter.feature index 0af3785..17b0e54 100644 --- a/src/test/resources/features/postToSearchProductWithoutSearchProductParameter.feature +++ b/src/test/resources/features/postToSearchProductWithoutSearchProductParameter.feature @@ -1,7 +1,7 @@ @Regression Feature: Post To Search Product Without Parameter - @api5 + @api6 Scenario: API Test 6 When Post To Search Product without Search product parameter Then Validate that product parameter is missing in post request \ No newline at end of file diff --git a/src/test/resources/features/postToVerifyLoginWithValidDetails.feature b/src/test/resources/features/postToVerifyLoginWithValidDetails.feature index 4a37a57..ae243e7 100644 --- a/src/test/resources/features/postToVerifyLoginWithValidDetails.feature +++ b/src/test/resources/features/postToVerifyLoginWithValidDetails.feature @@ -1,7 +1,7 @@ @Regression Feature: Post TO Verify Login + @api7 Scenario: API 7 - When Post to verify login Then Verify that valid result diff --git a/src/test/resources/features/postToVerifyLoginWithoutEmailparameter.feature b/src/test/resources/features/postToVerifyLoginWithoutEmailparameter.feature index 498e6db..b6ce7d1 100644 --- a/src/test/resources/features/postToVerifyLoginWithoutEmailparameter.feature +++ b/src/test/resources/features/postToVerifyLoginWithoutEmailparameter.feature @@ -1,6 +1,7 @@ @Regression Feature: Verify missing email parameter -@api8 -Scenario: API 8 - When Post to login witout email + + @api8 + Scenario: API 8 + When Post to login without email Then Verify that invalid result diff --git a/src/test/resources/features/putToAllBrandsList.feature b/src/test/resources/features/putToAllBrandsList.feature index 08d2bd5..32ae429 100644 --- a/src/test/resources/features/putToAllBrandsList.feature +++ b/src/test/resources/features/putToAllBrandsList.feature @@ -1,6 +1,7 @@ @Regression Feature: Put To All Brands List -@api4 + + @api4 Scenario: API Test 4 When Put to All Brands List Then Validate that response message \ No newline at end of file From 1e854dc8670dd42af75b87671dac84c294a2f9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20H=C3=BCseyin=20Semiz?= Date: Thu, 12 Oct 2023 21:36:17 +0200 Subject: [PATCH 7/9] Step Def refactoring --- .../services/PostToCreateRegisterUser.java | 33 +++++-------------- .../DeleteToVerifyLogin_stepDefs.java | 9 ++--- .../step_defs/DeleteUserAccount_stepDefs.java | 26 +++++---------- .../step_defs/GetAllBrandsList_stepDefs.java | 2 +- .../GetAllProductsList_stepDefs.java | 2 -- .../GetUserAccountDetailByEmail_stepDefs.java | 1 + .../PostToAllProductsList_stepDefs.java | 1 + .../PostToCreateRegisterUser_stepDefs.java | 9 ++--- ...earchProductWithoutParameter_stepDefs.java | 8 +++-- .../PostToSearchProduct_stepDefs.java | 8 ++--- ...erifyLoginWithInvalidDetails_stepDefs.java | 5 +-- .../PostToVerifyLoginWithValidDetails.java | 9 +++-- ...fyLoginWithoutEmailParameter_stepDefs.java | 5 +-- ...PutMethodToUpdateUserAccount_stepDefs.java | 1 + .../PutToAllBrandsList_stepDefs.java | 2 -- 15 files changed, 47 insertions(+), 74 deletions(-) diff --git a/src/test/java/com/example/services/PostToCreateRegisterUser.java b/src/test/java/com/example/services/PostToCreateRegisterUser.java index 8ea7f1e..dcc7091 100644 --- a/src/test/java/com/example/services/PostToCreateRegisterUser.java +++ b/src/test/java/com/example/services/PostToCreateRegisterUser.java @@ -3,46 +3,25 @@ import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; public class PostToCreateRegisterUser extends Globals { - @Test public void postToCreateRegisterUser() { // API Base URL RestAssured.baseURI = "https://automationexercise.com"; - // JSON Request Body - String requestBody = "{" - + "\"name\":\"John Doreca\"," - + "\"email\":\"johndorecaa@example.com\"," - + "\"password\":\"securedpassword\"," - + "\"title\":\"Mr\"," - + "\"birth_date\":\"01\"," - + "\"birth_month\":\"01\"," - + "\"birth_year\":\"1990\"," - + "\"firstname\":\"John\"," - + "\"lastname\":\"Dorec\"," - + "\"company\":\"Example Company\"," - + "\"address1\":\"123 Main St\"," - + "\"address2\":\"Apartment 456\"," - + "\"country\":\"US\"," - + "\"zipcode\":\"12345\"," - + "\"state\":\"CA\"," - + "\"city\":\"San Francisco\"," - + "\"mobile_number\":\"1234567890\"" - + "}"; - - String apiEndpoint = "/api/createAccount"; // Perform API request and validate response response= RestAssured.given() .contentType(ContentType.MULTIPART) .multiPart("name", "Ahmetz") - .multiPart("email", "ahmetwdz@drm.com") + .multiPart("email", "ahmetwdze@drm.com") .multiPart("password", "Ahmet12345z") .multiPart("title", "Mr") .multiPart("birth_date", "10") @@ -60,6 +39,10 @@ public void postToCreateRegisterUser() { .multiPart("mobile_number", "32452168") .when() .post(apiEndpoint); - } + + public void validateCreatedUser() { + Assert.assertEquals(201, response.jsonPath().getInt("responseCode")); + Assert.assertEquals("User created!", response.jsonPath().getString("message")); + } } \ No newline at end of file diff --git a/src/test/java/com/example/step_defs/DeleteToVerifyLogin_stepDefs.java b/src/test/java/com/example/step_defs/DeleteToVerifyLogin_stepDefs.java index da1c9e6..d0bb2ae 100644 --- a/src/test/java/com/example/step_defs/DeleteToVerifyLogin_stepDefs.java +++ b/src/test/java/com/example/step_defs/DeleteToVerifyLogin_stepDefs.java @@ -6,14 +6,15 @@ public class DeleteToVerifyLogin_stepDefs { - DeleteToVerifyLogin deleteToVerifyLogin=new DeleteToVerifyLogin(); + DeleteToVerifyLogin deleteToVerifyLogin = new DeleteToVerifyLogin(); + @When("Delete To Verify Login") public void delete_to_verify_login() { - deleteToVerifyLogin.deleteToVerifyLogin(); + deleteToVerifyLogin.deleteToVerifyLogin(); } + @Then("Validate that DELETE To Verify Login") public void validate_that_delete_to_verify_login() { - deleteToVerifyLogin.validateThatDeleteToVerifyLogin(); + deleteToVerifyLogin.validateThatDeleteToVerifyLogin(); } - } diff --git a/src/test/java/com/example/step_defs/DeleteUserAccount_stepDefs.java b/src/test/java/com/example/step_defs/DeleteUserAccount_stepDefs.java index fabe072..1856bae 100644 --- a/src/test/java/com/example/step_defs/DeleteUserAccount_stepDefs.java +++ b/src/test/java/com/example/step_defs/DeleteUserAccount_stepDefs.java @@ -1,30 +1,22 @@ package com.example.step_defs; + import com.example.services.DeleteUserAccount; -import io.cucumber.java.en.Given; -import io.cucumber.java.en.When; import io.cucumber.java.en.Then; -import io.cucumber.java.en.And; -import io.restassured.RestAssured; -import io.restassured.http.ContentType; - -import java.util.Map; - -import static com.example.utilities.Globals.response; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import io.cucumber.java.en.When; public class DeleteUserAccount_stepDefs { - DeleteUserAccount deleteUserAccount=new DeleteUserAccount(); - @When("Delete User Account") - public void delete_user_account() { deleteUserAccount.DeleteUserAccountApi(); + DeleteUserAccount deleteUserAccount = new DeleteUserAccount(); + @When("Delete User Account") + public void delete_user_account() { + deleteUserAccount.DeleteUserAccountApi(); } - @Then("Validate that Account was deleted") - public void validate_that_account_was_deleted() { deleteUserAccount.verifyAccountUser(); + @Then("Validate that Account was deleted") + public void validate_that_account_was_deleted() { + deleteUserAccount.verifyAccountUser(); } - } diff --git a/src/test/java/com/example/step_defs/GetAllBrandsList_stepDefs.java b/src/test/java/com/example/step_defs/GetAllBrandsList_stepDefs.java index 77413b6..f16b5b8 100644 --- a/src/test/java/com/example/step_defs/GetAllBrandsList_stepDefs.java +++ b/src/test/java/com/example/step_defs/GetAllBrandsList_stepDefs.java @@ -5,6 +5,7 @@ import io.cucumber.java.en.When; public class GetAllBrandsList_stepDefs { + GetAllBrandsList getAllBrandsList = new GetAllBrandsList(); @When("Get All Brands List") @@ -16,5 +17,4 @@ public void get_all_brands_list() { public void validate_that_all_brands_are_listed() { getAllBrandsList.validateThatAllBrands(); } - } diff --git a/src/test/java/com/example/step_defs/GetAllProductsList_stepDefs.java b/src/test/java/com/example/step_defs/GetAllProductsList_stepDefs.java index eac76ad..6b3aca5 100644 --- a/src/test/java/com/example/step_defs/GetAllProductsList_stepDefs.java +++ b/src/test/java/com/example/step_defs/GetAllProductsList_stepDefs.java @@ -3,7 +3,6 @@ import com.example.services.GetAllProductsList; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; -import org.junit.Assert; public class GetAllProductsList_stepDefs { @@ -18,5 +17,4 @@ public void get_all_products_list() { public void validate_that_all_products_are_listed() { getAllProductsList.validateThatAllProductsAreListed(); } - } diff --git a/src/test/java/com/example/step_defs/GetUserAccountDetailByEmail_stepDefs.java b/src/test/java/com/example/step_defs/GetUserAccountDetailByEmail_stepDefs.java index 414dd57..92599e9 100644 --- a/src/test/java/com/example/step_defs/GetUserAccountDetailByEmail_stepDefs.java +++ b/src/test/java/com/example/step_defs/GetUserAccountDetailByEmail_stepDefs.java @@ -12,6 +12,7 @@ public class GetUserAccountDetailByEmail_stepDefs { public void get_to_user_account_detail_by_email() { getUserAccountDetailByEmail.GetUserAccountDetailByEmail(); } + @Then("Validate User Detail") public void validate_user_detail() { getUserAccountDetailByEmail.validateUserDetail(); diff --git a/src/test/java/com/example/step_defs/PostToAllProductsList_stepDefs.java b/src/test/java/com/example/step_defs/PostToAllProductsList_stepDefs.java index 75e1d9b..8b82210 100644 --- a/src/test/java/com/example/step_defs/PostToAllProductsList_stepDefs.java +++ b/src/test/java/com/example/step_defs/PostToAllProductsList_stepDefs.java @@ -12,6 +12,7 @@ public class PostToAllProductsList_stepDefs { public void post_to_all_products_list() { postToAllProductsList.postToAllProductsList(); } + @Then("Validate that this request method is not supported.") public void validate_that_this_request_method_is_not_supported() { postToAllProductsList.validateThisPostRequestMethod(); diff --git a/src/test/java/com/example/step_defs/PostToCreateRegisterUser_stepDefs.java b/src/test/java/com/example/step_defs/PostToCreateRegisterUser_stepDefs.java index 256e4b5..4cfa839 100644 --- a/src/test/java/com/example/step_defs/PostToCreateRegisterUser_stepDefs.java +++ b/src/test/java/com/example/step_defs/PostToCreateRegisterUser_stepDefs.java @@ -3,22 +3,19 @@ import com.example.services.PostToCreateRegisterUser; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; -import org.junit.Assert; - -import static com.example.utilities.Globals.response; public class PostToCreateRegisterUser_stepDefs { - PostToCreateRegisterUser postToCreateRegisterUser=new PostToCreateRegisterUser(); + PostToCreateRegisterUser postToCreateRegisterUser = new PostToCreateRegisterUser(); @When("Create And Register User") public void create_and_register_user() { postToCreateRegisterUser.postToCreateRegisterUser(); } + @Then("Validate that new user are registered") public void validate_that_new_user_are_registered() { - Assert.assertEquals(201, response.jsonPath().getInt("responseCode")); - Assert.assertEquals("User created!", response.jsonPath().getString("message")); + postToCreateRegisterUser.validateCreatedUser(); } } diff --git a/src/test/java/com/example/step_defs/PostToSearchProductWithoutParameter_stepDefs.java b/src/test/java/com/example/step_defs/PostToSearchProductWithoutParameter_stepDefs.java index f0e0f0d..9b2bbd5 100644 --- a/src/test/java/com/example/step_defs/PostToSearchProductWithoutParameter_stepDefs.java +++ b/src/test/java/com/example/step_defs/PostToSearchProductWithoutParameter_stepDefs.java @@ -6,13 +6,15 @@ public class PostToSearchProductWithoutParameter_stepDefs { - PostToSearchProductWithoutParameter postToSearchProductWithoutParameter=new PostToSearchProductWithoutParameter(); + PostToSearchProductWithoutParameter postToSearchProductWithoutParameter = new PostToSearchProductWithoutParameter(); + @When("Post To Search Product without Search product parameter") public void post_to_search_product_without_search_product_parameter() { - postToSearchProductWithoutParameter.postToSearchProductWithoutParameter(); + postToSearchProductWithoutParameter.postToSearchProductWithoutParameter(); } + @Then("Validate that product parameter is missing in post request") public void validate_that_product_parameter_is_missing_in_post_request() { - postToSearchProductWithoutParameter.validateThatProductSearchedWithoutParameter(); + postToSearchProductWithoutParameter.validateThatProductSearchedWithoutParameter(); } } diff --git a/src/test/java/com/example/step_defs/PostToSearchProduct_stepDefs.java b/src/test/java/com/example/step_defs/PostToSearchProduct_stepDefs.java index 6a97728..50652ab 100644 --- a/src/test/java/com/example/step_defs/PostToSearchProduct_stepDefs.java +++ b/src/test/java/com/example/step_defs/PostToSearchProduct_stepDefs.java @@ -6,17 +6,15 @@ public class PostToSearchProduct_stepDefs { - PostToSearchProduct postToSearchProduct=new PostToSearchProduct(); + PostToSearchProduct postToSearchProduct = new PostToSearchProduct(); + @When("Post To Search Product") public void post_to_search_product() { postToSearchProduct.postToSearchProduct(); - } + @Then("Validate that products list searched") public void validate_that_products_list_searched() { postToSearchProduct.validateProductsSearched(); - } - - } diff --git a/src/test/java/com/example/step_defs/PostToVerifyLoginWithInvalidDetails_stepDefs.java b/src/test/java/com/example/step_defs/PostToVerifyLoginWithInvalidDetails_stepDefs.java index d887d4a..b174863 100644 --- a/src/test/java/com/example/step_defs/PostToVerifyLoginWithInvalidDetails_stepDefs.java +++ b/src/test/java/com/example/step_defs/PostToVerifyLoginWithInvalidDetails_stepDefs.java @@ -5,14 +5,15 @@ import io.cucumber.java.en.When; - public class PostToVerifyLoginWithInvalidDetails_stepDefs { - PostToVerifyLoginWithInvalidDetails postToVerifyLoginWithInvalidDetails=new PostToVerifyLoginWithInvalidDetails(); + PostToVerifyLoginWithInvalidDetails postToVerifyLoginWithInvalidDetails = new PostToVerifyLoginWithInvalidDetails(); + @When("User writes invalid email and password") public void user_writes_invalid_email_and_password() { postToVerifyLoginWithInvalidDetails.postToVerifyLoginWithInvalidDetails(); } + @Then("Validate that invalid result") public void validate_that_invalid_result() { postToVerifyLoginWithInvalidDetails.validateLoginWithInvalidDetails(); diff --git a/src/test/java/com/example/step_defs/PostToVerifyLoginWithValidDetails.java b/src/test/java/com/example/step_defs/PostToVerifyLoginWithValidDetails.java index e6b5cc3..9102c15 100644 --- a/src/test/java/com/example/step_defs/PostToVerifyLoginWithValidDetails.java +++ b/src/test/java/com/example/step_defs/PostToVerifyLoginWithValidDetails.java @@ -3,19 +3,18 @@ import com.example.services.PostToVerifyLoginwithValidDetails; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; -import org.apiguardian.api.API; public class PostToVerifyLoginWithValidDetails { - PostToVerifyLoginwithValidDetails postToVerifyLoginwithValidDetails=new PostToVerifyLoginwithValidDetails(); + + PostToVerifyLoginwithValidDetails postToVerifyLoginwithValidDetails = new PostToVerifyLoginwithValidDetails(); @When("Post to verify login") public void post_to_verify_login() { - postToVerifyLoginwithValidDetails.postToVerifyLoginwithValidDetails(); + postToVerifyLoginwithValidDetails.postToVerifyLoginwithValidDetails(); } + @Then("Verify that valid result") public void verify_that_valid_result() { - postToVerifyLoginwithValidDetails.verifyUserLogin(); - } } diff --git a/src/test/java/com/example/step_defs/PostToVerifyLoginWithoutEmailParameter_stepDefs.java b/src/test/java/com/example/step_defs/PostToVerifyLoginWithoutEmailParameter_stepDefs.java index 4ec08c3..e69e3c2 100644 --- a/src/test/java/com/example/step_defs/PostToVerifyLoginWithoutEmailParameter_stepDefs.java +++ b/src/test/java/com/example/step_defs/PostToVerifyLoginWithoutEmailParameter_stepDefs.java @@ -6,14 +6,15 @@ public class PostToVerifyLoginWithoutEmailParameter_stepDefs { - PostToVerifyLoginWithoutEmail postToVerifyLoginWithoutEmail=new PostToVerifyLoginWithoutEmail(); + PostToVerifyLoginWithoutEmail postToVerifyLoginWithoutEmail = new PostToVerifyLoginWithoutEmail(); @When("Post to login without email") public void post_to_login_without_email() { postToVerifyLoginWithoutEmail.postToVerifyLoginWithoutEmail(); } + @Then("Verify that invalid result") public void verify_that_invalid_result() { - postToVerifyLoginWithoutEmail.verifyLoginWithInvalidDetails(); + postToVerifyLoginWithoutEmail.verifyLoginWithInvalidDetails(); } } diff --git a/src/test/java/com/example/step_defs/PutMethodToUpdateUserAccount_stepDefs.java b/src/test/java/com/example/step_defs/PutMethodToUpdateUserAccount_stepDefs.java index 4792c2e..2e89fb5 100644 --- a/src/test/java/com/example/step_defs/PutMethodToUpdateUserAccount_stepDefs.java +++ b/src/test/java/com/example/step_defs/PutMethodToUpdateUserAccount_stepDefs.java @@ -12,6 +12,7 @@ public class PutMethodToUpdateUserAccount_stepDefs { public void put_to_account() { putMethodToUpdateUserAccount.updateAccount(); } + @Then("Validate that user updated") public void validate_that_user_updated() { putMethodToUpdateUserAccount.validateUSerUpdated(); diff --git a/src/test/java/com/example/step_defs/PutToAllBrandsList_stepDefs.java b/src/test/java/com/example/step_defs/PutToAllBrandsList_stepDefs.java index 6e8548b..4968062 100644 --- a/src/test/java/com/example/step_defs/PutToAllBrandsList_stepDefs.java +++ b/src/test/java/com/example/step_defs/PutToAllBrandsList_stepDefs.java @@ -16,6 +16,4 @@ public void put_to_all_brands_list() { public void validate_that_response_message() { putToAllBrandsList.validateThatPostRequestMethod(); } - - } From ee7f1d4a27ee8ec040ee60cdb3bed221b7366b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20H=C3=BCseyin=20Semiz?= Date: Thu, 12 Oct 2023 21:42:04 +0200 Subject: [PATCH 8/9] services refactoring --- .../example/services/DeleteToVerifyLogin.java | 10 ++--- .../example/services/DeleteUserAccount.java | 43 +++++++++---------- .../example/services/GetAllBrandsList.java | 5 +-- .../example/services/GetAllProductsList.java | 5 ++- .../services/GetUserAccountDetailByEmail.java | 5 +-- .../services/PostToAllProductsList.java | 4 +- .../services/PostToCreateRegisterUser.java | 7 ++- .../example/services/PostToSearchProduct.java | 22 ++++------ .../PostToSearchProductWithoutParameter.java | 9 ++-- .../PostToVerifyLoginWithInvalidDetails.java | 17 +++----- .../PostToVerifyLoginWithoutEmail.java | 16 +++---- .../PostToVerifyLoginwithValidDetails.java | 6 +-- .../PutMethodToUpdateUserAccount.java | 5 ++- .../example/services/PutToAllBrandsList.java | 11 ++--- 14 files changed, 74 insertions(+), 91 deletions(-) diff --git a/src/test/java/com/example/services/DeleteToVerifyLogin.java b/src/test/java/com/example/services/DeleteToVerifyLogin.java index 2314e14..3d07642 100644 --- a/src/test/java/com/example/services/DeleteToVerifyLogin.java +++ b/src/test/java/com/example/services/DeleteToVerifyLogin.java @@ -7,16 +7,16 @@ public class DeleteToVerifyLogin extends Globals { - public void deleteToVerifyLogin(){ - response= RestAssured.given() + public void deleteToVerifyLogin() { + response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.JSON) .when() .delete("/api/verifyLogin"); } - public void validateThatDeleteToVerifyLogin(){ - Assert.assertEquals(405,response.jsonPath().getInt("responseCode")); - Assert.assertEquals("This request method is not supported.",response.jsonPath().getString("message")); + public void validateThatDeleteToVerifyLogin() { + Assert.assertEquals(405, response.jsonPath().getInt("responseCode")); + Assert.assertEquals("This request method is not supported.", response.jsonPath().getString("message")); } } diff --git a/src/test/java/com/example/services/DeleteUserAccount.java b/src/test/java/com/example/services/DeleteUserAccount.java index 1996475..85a33ee 100644 --- a/src/test/java/com/example/services/DeleteUserAccount.java +++ b/src/test/java/com/example/services/DeleteUserAccount.java @@ -1,36 +1,33 @@ package com.example.services; + import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.junit.Assert; -import org.testng.annotations.Test; -public class DeleteUserAccount extends Globals { - - - - public void DeleteUserAccountApi() { +public class DeleteUserAccount extends Globals { - // Request Parameters - String email = "ahmetwdy@drm.com"; - String password = "Ahmet12345y"; + public void DeleteUserAccountApi() { - // API Endpoint - String apiEndpoint = "/api/deleteAccount"; + // Request Parameters + String email = "ahmetwdy@drm.com"; + String password = "Ahmet12345y"; - // Perform API request and validate response - response= RestAssured.given() - .contentType(ContentType.MULTIPART) - .multiPart("email", email) - .multiPart("password", password) - .when() - .delete(apiEndpoint); + // API Endpoint + String apiEndpoint = "/api/deleteAccount"; - } + // Perform API request and validate response + response = RestAssured.given() + .contentType(ContentType.MULTIPART) + .multiPart("email", email) + .multiPart("password", password) + .when() + .delete(apiEndpoint); + } - public void verifyAccountUser(){ - Assert.assertEquals(200, response.jsonPath().getInt("responseCode")); - Assert.assertEquals("Account deleted!", response.jsonPath().getString("message")); - } + public void verifyAccountUser() { + Assert.assertEquals(200, response.jsonPath().getInt("responseCode")); + Assert.assertEquals("Account deleted!", response.jsonPath().getString("message")); } +} diff --git a/src/test/java/com/example/services/GetAllBrandsList.java b/src/test/java/com/example/services/GetAllBrandsList.java index 27070f8..2871f43 100644 --- a/src/test/java/com/example/services/GetAllBrandsList.java +++ b/src/test/java/com/example/services/GetAllBrandsList.java @@ -3,10 +3,8 @@ import com.example.utilities.Globals; import io.restassured.http.ContentType; import org.junit.Assert; - import java.util.List; import java.util.Map; - import static io.restassured.RestAssured.given; public class GetAllBrandsList extends Globals { @@ -18,7 +16,6 @@ public void getAllBrandsList() { public void validateThatAllBrands() { Assert.assertEquals(200, response.statusCode()); List brands = response.jsonPath().getList("brands"); - Assert.assertEquals(34,brands.size()); - // Assert.assertEquals("Madame", brands.get(2).get("brand")); + Assert.assertEquals(34, brands.size()); } } diff --git a/src/test/java/com/example/services/GetAllProductsList.java b/src/test/java/com/example/services/GetAllProductsList.java index 3e8ad4f..2974fdb 100644 --- a/src/test/java/com/example/services/GetAllProductsList.java +++ b/src/test/java/com/example/services/GetAllProductsList.java @@ -9,7 +9,8 @@ import java.util.Map; public class GetAllProductsList extends Globals { - public void getAllProductsList(){ + + public void getAllProductsList() { response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.JSON) @@ -17,7 +18,7 @@ public void getAllProductsList(){ .get("/api/productsList"); } - public void validateThatAllProductsAreListed(){ + public void validateThatAllProductsAreListed() { Assert.assertEquals(200, response.statusCode()); List products = response.jsonPath().getList("products"); diff --git a/src/test/java/com/example/services/GetUserAccountDetailByEmail.java b/src/test/java/com/example/services/GetUserAccountDetailByEmail.java index c0a22f5..eb1d1ee 100644 --- a/src/test/java/com/example/services/GetUserAccountDetailByEmail.java +++ b/src/test/java/com/example/services/GetUserAccountDetailByEmail.java @@ -7,7 +7,7 @@ public class GetUserAccountDetailByEmail extends Globals { - public void GetUserAccountDetailByEmail(){ + public void GetUserAccountDetailByEmail() { response = RestAssured.given() .contentType(ContentType.JSON) .accept(ContentType.JSON) @@ -16,7 +16,7 @@ public void GetUserAccountDetailByEmail(){ .get("/api/getUserDetailByEmail"); } - public void validateUserDetail(){ + public void validateUserDetail() { Assert.assertEquals(200, response.jsonPath().getInt("responseCode")); @@ -25,6 +25,5 @@ public void validateUserDetail(){ //validate city Assert.assertEquals("Berlin", response.jsonPath().getString("user.city")); - } } diff --git a/src/test/java/com/example/services/PostToAllProductsList.java b/src/test/java/com/example/services/PostToAllProductsList.java index e1e35f3..7e303b8 100644 --- a/src/test/java/com/example/services/PostToAllProductsList.java +++ b/src/test/java/com/example/services/PostToAllProductsList.java @@ -7,7 +7,7 @@ public class PostToAllProductsList extends Globals { - public void postToAllProductsList(){ + public void postToAllProductsList() { response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.JSON) @@ -15,7 +15,7 @@ public void postToAllProductsList(){ .post("/api/productsList"); } - public void validateThisPostRequestMethod(){ + public void validateThisPostRequestMethod() { Assert.assertEquals(405, response.jsonPath().getInt("responseCode")); Assert.assertEquals("This request method is not supported.", response.jsonPath().getString("message")); } diff --git a/src/test/java/com/example/services/PostToCreateRegisterUser.java b/src/test/java/com/example/services/PostToCreateRegisterUser.java index dcc7091..a27f184 100644 --- a/src/test/java/com/example/services/PostToCreateRegisterUser.java +++ b/src/test/java/com/example/services/PostToCreateRegisterUser.java @@ -4,21 +4,20 @@ import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; public class PostToCreateRegisterUser extends Globals { public void postToCreateRegisterUser() { + // API Base URL RestAssured.baseURI = "https://automationexercise.com"; String apiEndpoint = "/api/createAccount"; // Perform API request and validate response - response= RestAssured.given() + response = RestAssured.given() .contentType(ContentType.MULTIPART) .multiPart("name", "Ahmetz") .multiPart("email", "ahmetwdze@drm.com") @@ -39,7 +38,7 @@ public void postToCreateRegisterUser() { .multiPart("mobile_number", "32452168") .when() .post(apiEndpoint); - } + } public void validateCreatedUser() { Assert.assertEquals(201, response.jsonPath().getInt("responseCode")); diff --git a/src/test/java/com/example/services/PostToSearchProduct.java b/src/test/java/com/example/services/PostToSearchProduct.java index 45e314f..7fbeebe 100644 --- a/src/test/java/com/example/services/PostToSearchProduct.java +++ b/src/test/java/com/example/services/PostToSearchProduct.java @@ -3,34 +3,28 @@ import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; -import io.restassured.path.json.JsonPath; import org.junit.Assert; -import java.util.HashMap; import java.util.List; import java.util.Map; public class PostToSearchProduct extends Globals { - public void postToSearchProduct(){ + public void postToSearchProduct() { - response=RestAssured.given() + response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.MULTIPART) - .multiPart("search_product","jean") + .multiPart("search_product", "jean") .and() .when() - .post("/api/searchProduct") - .prettyPeek(); - + .post("/api/searchProduct"); } - public void validateProductsSearched(){ - - Assert.assertEquals(200,response.jsonPath().getInt("responseCode")); - List jeanProductsList=response.jsonPath().getList("products"); - Assert.assertEquals(3,jeanProductsList.size()); + public void validateProductsSearched() { + Assert.assertEquals(200, response.jsonPath().getInt("responseCode")); + List jeanProductsList = response.jsonPath().getList("products"); + Assert.assertEquals(3, jeanProductsList.size()); } - } diff --git a/src/test/java/com/example/services/PostToSearchProductWithoutParameter.java b/src/test/java/com/example/services/PostToSearchProductWithoutParameter.java index 8b0d910..bfad951 100644 --- a/src/test/java/com/example/services/PostToSearchProductWithoutParameter.java +++ b/src/test/java/com/example/services/PostToSearchProductWithoutParameter.java @@ -7,16 +7,17 @@ public class PostToSearchProductWithoutParameter extends Globals { - public void postToSearchProductWithoutParameter(){ + public void postToSearchProductWithoutParameter() { - response=RestAssured.given() + response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.JSON) .when() .post("/api/searchProduct"); } - public void validateThatProductSearchedWithoutParameter(){ - Assert.assertEquals(400,response.jsonPath().getInt("responseCode")); + + public void validateThatProductSearchedWithoutParameter() { + Assert.assertEquals(400, response.jsonPath().getInt("responseCode")); Assert.assertEquals("Bad request, search_product parameter is missing in POST request.", response.jsonPath().getString("message")); } } diff --git a/src/test/java/com/example/services/PostToVerifyLoginWithInvalidDetails.java b/src/test/java/com/example/services/PostToVerifyLoginWithInvalidDetails.java index fb9bf74..ef4acca 100644 --- a/src/test/java/com/example/services/PostToVerifyLoginWithInvalidDetails.java +++ b/src/test/java/com/example/services/PostToVerifyLoginWithInvalidDetails.java @@ -3,26 +3,23 @@ import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; -import org.codehaus.groovy.control.io.ReaderSource; import org.junit.Assert; public class PostToVerifyLoginWithInvalidDetails extends Globals { - - public void postToVerifyLoginWithInvalidDetails(){ - response= RestAssured.given() + public void postToVerifyLoginWithInvalidDetails() { + response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.MULTIPART) - .multiPart("email","b@aa.com") + .multiPart("email", "b@aa.com") .and() - .multiPart("password","1234") + .multiPart("password", "1234") .when() .post("/api/verifyLogin"); - } - public void validateLoginWithInvalidDetails(){ - Assert.assertEquals(404,response.jsonPath().getInt("responseCode")); - Assert.assertEquals("User not found!",response.jsonPath().getString("message")); + public void validateLoginWithInvalidDetails() { + Assert.assertEquals(404, response.jsonPath().getInt("responseCode")); + Assert.assertEquals("User not found!", response.jsonPath().getString("message")); } } diff --git a/src/test/java/com/example/services/PostToVerifyLoginWithoutEmail.java b/src/test/java/com/example/services/PostToVerifyLoginWithoutEmail.java index 13b32e2..e3bc594 100644 --- a/src/test/java/com/example/services/PostToVerifyLoginWithoutEmail.java +++ b/src/test/java/com/example/services/PostToVerifyLoginWithoutEmail.java @@ -3,22 +3,22 @@ import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; -import io.restassured.response.Response; import org.junit.Assert; public class PostToVerifyLoginWithoutEmail extends Globals { - public void postToVerifyLoginWithoutEmail(){ - response = RestAssured.given() + public void postToVerifyLoginWithoutEmail() { + response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.MULTIPART) - .multiPart("password","Test1234") - .when() + .multiPart("password", "Test1234") + .when() .post("/api/verifyLogin"); } - public void verifyLoginWithInvalidDetails(){ - Assert.assertEquals(400,response.jsonPath().getInt("responseCode")); - Assert.assertEquals("Bad request, email or password parameter is missing in POST request.",response.jsonPath().getString("message")); + + public void verifyLoginWithInvalidDetails() { + Assert.assertEquals(400, response.jsonPath().getInt("responseCode")); + Assert.assertEquals("Bad request, email or password parameter is missing in POST request.", response.jsonPath().getString("message")); } } diff --git a/src/test/java/com/example/services/PostToVerifyLoginwithValidDetails.java b/src/test/java/com/example/services/PostToVerifyLoginwithValidDetails.java index 42b9243..6945803 100644 --- a/src/test/java/com/example/services/PostToVerifyLoginwithValidDetails.java +++ b/src/test/java/com/example/services/PostToVerifyLoginwithValidDetails.java @@ -3,12 +3,11 @@ import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; -import io.restassured.response.Response; import org.junit.Assert; public class PostToVerifyLoginwithValidDetails extends Globals { - public void postToVerifyLoginwithValidDetails (){ + public void postToVerifyLoginwithValidDetails() { response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.MULTIPART) @@ -17,7 +16,8 @@ public void postToVerifyLoginwithValidDetails (){ .when() .post("/api/verifyLogin"); } - public void verifyUserLogin(){ + + public void verifyUserLogin() { Assert.assertEquals(200, response.jsonPath().getInt("responseCode")); Assert.assertEquals("User exists!", response.jsonPath().getString("message")); } diff --git a/src/test/java/com/example/services/PutMethodToUpdateUserAccount.java b/src/test/java/com/example/services/PutMethodToUpdateUserAccount.java index ef6f7b8..2c2c9a5 100644 --- a/src/test/java/com/example/services/PutMethodToUpdateUserAccount.java +++ b/src/test/java/com/example/services/PutMethodToUpdateUserAccount.java @@ -6,7 +6,8 @@ import org.junit.Assert; public class PutMethodToUpdateUserAccount extends Globals { - public void updateAccount(){ + + public void updateAccount() { response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.MULTIPART) @@ -18,7 +19,7 @@ public void updateAccount(){ .put("/api/updateAccount"); } - public void validateUSerUpdated(){ + public void validateUSerUpdated() { Assert.assertEquals(200, response.jsonPath().getInt("responseCode")); Assert.assertEquals("User updated!", response.jsonPath().getString("message")); } diff --git a/src/test/java/com/example/services/PutToAllBrandsList.java b/src/test/java/com/example/services/PutToAllBrandsList.java index a639ea2..e7d8022 100644 --- a/src/test/java/com/example/services/PutToAllBrandsList.java +++ b/src/test/java/com/example/services/PutToAllBrandsList.java @@ -3,23 +3,20 @@ import com.example.utilities.Globals; import io.restassured.http.ContentType; import org.junit.Assert; - import static io.restassured.RestAssured.given; public class PutToAllBrandsList extends Globals { - public void putToAllBrandsList(){ - response= given().accept(ContentType.JSON) + public void putToAllBrandsList() { + response = given().accept(ContentType.JSON) .contentType(ContentType.JSON) .when() .put("/api/brandsList"); } - public void validateThatPostRequestMethod(){ - String expectedMessage="This request method is not supported."; + public void validateThatPostRequestMethod() { + String expectedMessage = "This request method is not supported."; Assert.assertEquals(405, response.jsonPath().getInt("responseCode")); Assert.assertEquals(expectedMessage, response.jsonPath().getString("message")); } - - } From 73c5debeb254578a51f27810a8c77aa322ed5705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20H=C3=BCseyin=20Semiz?= Date: Thu, 12 Oct 2023 22:27:48 +0200 Subject: [PATCH 9/9] ConfigurationReader refactoring --- configuration.properties | 4 ++ .../example/services/DeleteUserAccount.java | 19 ++++---- .../services/GetUserAccountDetailByEmail.java | 8 ++-- .../services/PostToCreateRegisterUser.java | 13 +++-- .../PostToVerifyLoginWithoutEmail.java | 3 +- .../PostToVerifyLoginwithValidDetails.java | 5 +- .../PutMethodToUpdateUserAccount.java | 7 +-- .../utilities/ConfigurationReader.java | 48 +++++++++++++++++++ .../java/com/example/utilities/Globals.java | 1 - ...ser.feature => CreateRegisterUser.feature} | 0 ...ount.feature => userAccountDelete.feature} | 0 11 files changed, 83 insertions(+), 25 deletions(-) create mode 100644 configuration.properties create mode 100644 src/test/java/com/example/utilities/ConfigurationReader.java rename src/test/resources/features/{postToCreateRegisterUser.feature => CreateRegisterUser.feature} (100%) rename src/test/resources/features/{deleteUserAccount.feature => userAccountDelete.feature} (100%) diff --git a/configuration.properties b/configuration.properties new file mode 100644 index 0000000..da71d49 --- /dev/null +++ b/configuration.properties @@ -0,0 +1,4 @@ +#Thu Oct 12 22:27:09 CEST 2023 +email= +password= +userName= diff --git a/src/test/java/com/example/services/DeleteUserAccount.java b/src/test/java/com/example/services/DeleteUserAccount.java index 85a33ee..055b1a2 100644 --- a/src/test/java/com/example/services/DeleteUserAccount.java +++ b/src/test/java/com/example/services/DeleteUserAccount.java @@ -1,5 +1,6 @@ package com.example.services; +import com.example.utilities.ConfigurationReader; import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -9,20 +10,18 @@ public class DeleteUserAccount extends Globals { public void DeleteUserAccountApi() { - // Request Parameters - String email = "ahmetwdy@drm.com"; - String password = "Ahmet12345y"; - - // API Endpoint - String apiEndpoint = "/api/deleteAccount"; - // Perform API request and validate response response = RestAssured.given() .contentType(ContentType.MULTIPART) - .multiPart("email", email) - .multiPart("password", password) + .multiPart("email", ConfigurationReader.get("email")) + .multiPart("password", ConfigurationReader.get("password")) .when() - .delete(apiEndpoint); + .delete("/api/deleteAccount"); + + //clear configurationReader + ConfigurationReader.set("userName",""); + ConfigurationReader.set("email",""); + ConfigurationReader.set("password",""); } public void verifyAccountUser() { diff --git a/src/test/java/com/example/services/GetUserAccountDetailByEmail.java b/src/test/java/com/example/services/GetUserAccountDetailByEmail.java index eb1d1ee..65b83dd 100644 --- a/src/test/java/com/example/services/GetUserAccountDetailByEmail.java +++ b/src/test/java/com/example/services/GetUserAccountDetailByEmail.java @@ -1,5 +1,6 @@ package com.example.services; +import com.example.utilities.ConfigurationReader; import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -11,7 +12,7 @@ public void GetUserAccountDetailByEmail() { response = RestAssured.given() .contentType(ContentType.JSON) .accept(ContentType.JSON) - .queryParam("email", "hans@hans.com") + .queryParam("email", ConfigurationReader.get("email")) .when() .get("/api/getUserDetailByEmail"); } @@ -21,9 +22,6 @@ public void validateUserDetail() { Assert.assertEquals(200, response.jsonPath().getInt("responseCode")); //validate username - Assert.assertEquals("hans", response.jsonPath().getString("user.name")); - - //validate city - Assert.assertEquals("Berlin", response.jsonPath().getString("user.city")); + Assert.assertEquals(ConfigurationReader.get("userName"), response.jsonPath().getString("user.name")); } } diff --git a/src/test/java/com/example/services/PostToCreateRegisterUser.java b/src/test/java/com/example/services/PostToCreateRegisterUser.java index a27f184..f9c64b2 100644 --- a/src/test/java/com/example/services/PostToCreateRegisterUser.java +++ b/src/test/java/com/example/services/PostToCreateRegisterUser.java @@ -1,6 +1,8 @@ package com.example.services; +import com.example.utilities.ConfigurationReader; import com.example.utilities.Globals; +import com.github.javafaker.Faker; import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.junit.Assert; @@ -11,6 +13,11 @@ public class PostToCreateRegisterUser extends Globals { public void postToCreateRegisterUser() { + Faker faker = new Faker(); + ConfigurationReader.set("userName", faker.name().firstName()); + ConfigurationReader.set("email", faker.internet().emailAddress()); + ConfigurationReader.set("password", "Ac!2" + faker.internet().password()); + // API Base URL RestAssured.baseURI = "https://automationexercise.com"; @@ -19,9 +26,9 @@ public void postToCreateRegisterUser() { // Perform API request and validate response response = RestAssured.given() .contentType(ContentType.MULTIPART) - .multiPart("name", "Ahmetz") - .multiPart("email", "ahmetwdze@drm.com") - .multiPart("password", "Ahmet12345z") + .multiPart("name", ConfigurationReader.get("userName")) + .multiPart("email", ConfigurationReader.get("email")) + .multiPart("password", ConfigurationReader.get("password")) .multiPart("title", "Mr") .multiPart("birth_date", "10") .multiPart("birth_month", "12") diff --git a/src/test/java/com/example/services/PostToVerifyLoginWithoutEmail.java b/src/test/java/com/example/services/PostToVerifyLoginWithoutEmail.java index e3bc594..d575e6c 100644 --- a/src/test/java/com/example/services/PostToVerifyLoginWithoutEmail.java +++ b/src/test/java/com/example/services/PostToVerifyLoginWithoutEmail.java @@ -1,5 +1,6 @@ package com.example.services; +import com.example.utilities.ConfigurationReader; import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -11,7 +12,7 @@ public void postToVerifyLoginWithoutEmail() { response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.MULTIPART) - .multiPart("password", "Test1234") + .multiPart("password", ConfigurationReader.get("password")) .when() .post("/api/verifyLogin"); } diff --git a/src/test/java/com/example/services/PostToVerifyLoginwithValidDetails.java b/src/test/java/com/example/services/PostToVerifyLoginwithValidDetails.java index 6945803..e6ca8a9 100644 --- a/src/test/java/com/example/services/PostToVerifyLoginwithValidDetails.java +++ b/src/test/java/com/example/services/PostToVerifyLoginwithValidDetails.java @@ -1,5 +1,6 @@ package com.example.services; +import com.example.utilities.ConfigurationReader; import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -11,8 +12,8 @@ public void postToVerifyLoginwithValidDetails() { response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.MULTIPART) - .multiPart("email", "mike01@gmail.com") - .multiPart("password", "Test1234") + .multiPart("email", ConfigurationReader.get("email")) + .multiPart("password", ConfigurationReader.get("password")) .when() .post("/api/verifyLogin"); } diff --git a/src/test/java/com/example/services/PutMethodToUpdateUserAccount.java b/src/test/java/com/example/services/PutMethodToUpdateUserAccount.java index 2c2c9a5..714a67e 100644 --- a/src/test/java/com/example/services/PutMethodToUpdateUserAccount.java +++ b/src/test/java/com/example/services/PutMethodToUpdateUserAccount.java @@ -1,5 +1,6 @@ package com.example.services; +import com.example.utilities.ConfigurationReader; import com.example.utilities.Globals; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -11,9 +12,9 @@ public void updateAccount() { response = RestAssured.given() .accept(ContentType.JSON) .contentType(ContentType.MULTIPART) - .multiPart("name", "hans") - .multiPart("email", "hans@hans.com") - .multiPart("password", "Test1234") + .multiPart("name", ConfigurationReader.get("userName")) + .multiPart("email", ConfigurationReader.get("email")) + .multiPart("password", ConfigurationReader.get("password")) .multiPart("city", "Berlin") .when() .put("/api/updateAccount"); diff --git a/src/test/java/com/example/utilities/ConfigurationReader.java b/src/test/java/com/example/utilities/ConfigurationReader.java new file mode 100644 index 0000000..3006e7c --- /dev/null +++ b/src/test/java/com/example/utilities/ConfigurationReader.java @@ -0,0 +1,48 @@ +package com.example.utilities; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +public class ConfigurationReader { + + private static Properties properties; + + static { + try { + //path of file which is wanted to read + String path = "configuration.properties"; + + //read file into Java + //using string path to find the file + FileInputStream input = new FileInputStream(path); + + //properties--> class can store data (properties) in key/value format + properties = new Properties(); + + //the values (data) from input is loaded to the properties object + properties.load(input); + input.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static String get(String keyName){ + return properties.getProperty(keyName); + } + + public static void set(String keyName, String value){ + //path of file which is wanted to write + String path = "configuration.properties"; + try { + FileOutputStream output = new FileOutputStream(path); + properties.setProperty(keyName, value); + properties.store(output,null); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/test/java/com/example/utilities/Globals.java b/src/test/java/com/example/utilities/Globals.java index c7d127a..50538fe 100644 --- a/src/test/java/com/example/utilities/Globals.java +++ b/src/test/java/com/example/utilities/Globals.java @@ -4,5 +4,4 @@ public class Globals { public static Response response; - } diff --git a/src/test/resources/features/postToCreateRegisterUser.feature b/src/test/resources/features/CreateRegisterUser.feature similarity index 100% rename from src/test/resources/features/postToCreateRegisterUser.feature rename to src/test/resources/features/CreateRegisterUser.feature diff --git a/src/test/resources/features/deleteUserAccount.feature b/src/test/resources/features/userAccountDelete.feature similarity index 100% rename from src/test/resources/features/deleteUserAccount.feature rename to src/test/resources/features/userAccountDelete.feature