-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Ensure Content-Type is set based on header value if not explicit…
…ly set - Modified the `prepareRequestSpecs` method to check if `contentType` is still `ContentType.ANY`. - If `ContentType` is not explicitly set by the user, it now retrieves the `Content-Type` from `sessionHeaders` and applies it directly to the `RequestSpecBuilder`. - This change ensures that the request uses the exact `Content-Type` provided in the headers, preventing encoding and serialization issues. This update fixes issues where requests with XML or JSON bodies were not being encoded correctly due to the `contentType` defaulting to `ContentType.ANY`.
- Loading branch information
Kyrillos Nageh Abdelnour Flamon
committed
Aug 17, 2024
1 parent
c49990a
commit 548b888
Showing
8 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.shaft.api; | ||
|
||
import com.shaft.driver.SHAFT; | ||
import io.qameta.allure.TmsLinks; | ||
import io.restassured.builder.RequestSpecBuilder; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* @author Kyrillos Nageh | ||
*/ | ||
public class testss { | ||
SHAFT.API api; | ||
|
||
|
||
@BeforeClass | ||
public void setUp() { | ||
// api = new SHAFT.API("http://www.dneonline.com"); | ||
} | ||
|
||
@Test | ||
public void testCreateUser() { | ||
|
||
|
||
String requestBody= " {\n" + | ||
" \"name\": \"Test user1\",\n" + | ||
" \"job\": \"leader\"\n" + | ||
" }"; | ||
|
||
api = new SHAFT.API("https://reqres.in/api/"); | ||
//api.addHeader("Content-Type", "application/json"); | ||
Response response = api.post("users") | ||
.setContentType("application/json") | ||
.setRequestBody(requestBody) | ||
.performRequest(); | ||
System.out.println("Response Body: " + response.getBody().asString()); | ||
} | ||
@Test | ||
public void testAddOperation() { | ||
/* | ||
AddRequest request = AddRequest.builder() | ||
.intA(5) | ||
.intB(10) | ||
.build(); | ||
AddResponse response = calculatorService.add(request); | ||
Assert.assertEquals(response.getAddResult(), 15); | ||
*/ | ||
|
||
String requestXml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + | ||
" <soapenv:Body>\n" + | ||
" <tem:Multiply xmlns:tem=\"http://tempuri.org/\">\n" + | ||
" <tem:intA>10</tem:intA>\n" + | ||
" <tem:intB>2</tem:intB>\n" + | ||
" </tem:Multiply>\n" + | ||
" </soapenv:Body>\n" + | ||
"</soapenv:Envelope>"; | ||
|
||
api = new SHAFT.API(""); | ||
api.addHeader("Content-Type", "text/xml; charset=UTF-8"); | ||
api.addHeader("SOAPAction", "http://tempuri.org/" + "Multiply"); | ||
|
||
System.out.println("Request Body: " + requestXml); | ||
|
||
Response response = api.post("http://www.dneonline.com/calculator.asmx") | ||
.setRequestBody(requestXml) | ||
.performRequest(); | ||
|
||
String Result =RestActions.getResponseXMLValue(response, "AddResponse/AddResult"); | ||
|
||
SHAFT.Report.log(">>>>>>>>>>>> Test result >>>> " + Result); | ||
|
||
/* | ||
Response response = given() | ||
.header("Content-Type", "text/xml") | ||
.contentType(ContentType.XML) | ||
.header("SOAPAction", "http://tempuri.org/" + "Multiply") | ||
.body(requestXml) | ||
.when() | ||
.post("http://www.dneonline.com/calculator.asmx") | ||
.then() | ||
.statusCode(200) // Validate status code directly | ||
.extract().response(); | ||
String Result =RestActions.getResponseXMLValue(response, "AddResponse/AddResult"); | ||
SHAFT.Report.log(">>>>>>>>>>>> Test result >>>> " + Result); | ||
*/ | ||
} | ||
|
||
} | ||
|
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/io.qameta.allure.listener.ContainerLifecycleListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.shaft.listeners.AllureListener |
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/io.qameta.allure.listener.FixtureLifecycleListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.shaft.listeners.AllureListener |
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/io.qameta.allure.listener.StepLifecycleListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.shaft.listeners.AllureListener |
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/io.qameta.allure.listener.TestLifecycleListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.shaft.listeners.AllureListener |
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/org.testng.ITestNGListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.shaft.listeners.TestNGListener |