0

I'm getting trough initial very first blind steps of rest-assured with Java.

I have few requests, which actually works well and I started to add assertions. So I'm sending request, getting JSON as response, extracting it. And I need to verify if part of it equals to "success".

I'm taking it as

Response res = given().
when().post("/profile").then().contentType(ContentType.JSON).extract().response();

rc3 = res.path("op_list.msg").toString();

System.out.println(rc3);

So output looks like array according to toString method's documentation. Surely, assertion won't work :( it sees difference between

[success]

and

success

Substrings is not recommended by internal code requirements. I just thought I'm using wrong method, but didn't find any besides asString, but it won't work with path expression. I have no any clue or relative search results. If you would help me with advice I'd be grateful.

3 Answers3

1

Well have you tried to substring it?

Something like rc3.substring(0,rc3.length()-1) should do the job, another solution would be to use replaceAll method, or maybe to use some JSON parsing library.

FilipRistic
  • 2,661
  • 4
  • 22
  • 31
1
  1. You can substring your output.
  2. You can use contains() method of String class.
  3. You can use Jackson to convert it to Java Object. See Jackson Blog
Shrikshel
  • 37
  • 1
  • 9
  • substrings is not recommended by internal code requirements :( they said it's a smell code lol. Thank you for java object convert direction. I just thought I'm using wrong method, but didn't find any besides asString, but it won't work with path expression. Works with whole JSON answer :( – Juliya Sergey Miheeva Mar 29 '18 at 13:19
-1

You could possibly try the below:

String Input = "[success]";

String replacedInput = Input.replaceAll("[,]","");

Hope this helps!

Conboy137
  • 1
  • 1
  • 4