1

I'm having an issue, the issue seems to me very strange , I don't really got it , in order to explain you guys , let me share the code.

so I'm testing API with rest assured, programming language is JAVA, so the problem is here , when I run my test using JUnit's @TEST annotation , it works fine , the code as follows

 @Test
    public void searchData() {
        Response response = given()
                .header("Authorization", PropertiesReader.getPropertiesValue("TokenPub"))
                .queryParam("langId", "PdOnv3OV")
                .queryParam("Regions", "52aAGOZ7")
                .queryParam("From","2022-01-30")
                .queryParam("To","2022-02-06")
                .when()
                .request(String.valueOf(RestHttpRequest.HttpMethods.GET), "/api/product/search");
        response.prettyPrint();

    }

And I'm getting expected output as follows

{
    "fromDate": "2022-01-30",
    "toDate": "2022-02-06",
    "products": [
        {
            "id": "k8p0V0lJ",
            "name": "ביקור באתר התיירות ראש הנקרה",
            "minOfficialPrice": 40.0000,
            "customerTypeId": "q1lox9O7",
            "currencyId": "Belm3pnb"
        },
        {
            "id": "5bpJgVaV",
            "name": "אירוח ביתי בוכרי",
            "minOfficialPrice": 30.0000,
            "customerTypeId": "q7OxNwa6",
            "currencyId": "Belm3pnb"
        },
        {
            "id": "3pWok6p4",
            "name": "ghjkl",
            "minOfficialPrice": 123.0000,
            "customerTypeId": "vApRn5pY",
            "currencyId": "Belm3pnb"
        },
        {
            "id": "ApRDK9lY",
            "name": "טיול רייזרים בשבליי ההרים",
            "minOfficialPrice": 500.0000,
            "customerTypeId": "oylKk6l8",
            "currencyId": "Belm3pnb"
        },
        {
            "id": "Bl5165lX",
            "name": "טיול רייזרים למבצרים וכפר עתיק",
            "minOfficialPrice": 5.0000,
            "customerTypeId": "BJpgYvlq",
            "currencyId": "Belm3pnb"
        }
    ],
    "warning": null
}

Attention here is the issue , when i try to run the same thing using cucumber , I'm getting an exception com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

I have the following scenario

Feature: data is being searched in public API
  Scenario: searching the data in public API
    Given searching the data in public api

I have the following step definition

@Given("^searching the data in public api$")
public void searching_the_data_in_public_api_with_the_following_fields() throws Throwable {


   CommonData.response = given()
            .header("Authorization", PropertiesReader.getPropertiesValue("TokenPub"))
            .queryParam("langId", "PdOnv3OV")
            .queryParam("Regions", "52aAGOZ7")
            .queryParam("From","2022-01-30")
            .queryParam("To","2022-02-06")
            .when()
            .request(String.valueOf(RestHttpRequest.HttpMethods.GET), "/api/product/search");
   CommonData.response.prettyPrint();



}

please help me, all opinions and comments will be much appreciated, Thanks in advance

Qa Automation
  • 41
  • 1
  • 6
  • This might help you https://stackoverflow.com/questions/28418662/expected-begin-object-but-was-string-at-line-1-column-1 – lucas-nguyen-17 Nov 17 '21 at 07:51
  • @lucasnguyen17 I have kinda figured out the problem , problem was caused by Cucumber Before annotation , where i usually put my BaseURL , until today I have been using only one BaseURL , but today I have had to test the public APIs , where the BaseURl is little different & i added new BaseURL in properties file , where I usually store my tokens and URLs, I have a method which reads values from properties file, so I removed Before annotation & put the BaseURL directly to the request , and it worked , but I still don't understand the issue , what is the exact problem? – Qa Automation Nov 17 '21 at 10:00
  • You can compare request logging between 2 scenarios. I guess the second one, your request URL is not correct. – lucas-nguyen-17 Nov 17 '21 at 11:23

0 Answers0