I have a following question: In my project I’m using Page Object pattern. When I click some button I recieve a JSON response like that:
{“description”:“Just a sample description for this application [Application Information 0]”, “category”:{“id”:“57a9e39d48f26f74e054b764”,“title”:“Information”},“iconData”:null,“imageData”:null,“author”:{“name”:“admin”,“password”:“21232f297a57a5a743894a0e4a801fc3”,“roleModel”:{“name”:“DEVELOPER”,“id”:“57a9e39d48f26f74e054b762”,“developer”:true,“title”:“DEVELOPER”},“lname”:“Petrov”,“fname”:“Ivan”},“numberOfDownloads”:9,“uploadedTimeStamp”:1470751645983,“title”:“Application Information 0”}
I described a page in project that contains an element “textInJson”
import com.google.gson.JsonElement;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class JsonResponsePage extends BasicPage {
@FindBy(xpath = JSON_RESPONSE_ELEMENT)
JsonElement textInJson;
public static final String JSON_RESPONSE_ELEMENT = "html/body/div[2]/div[3]/div/div[1]/a";
}
And I need to make sure that each parameter has corresponding value (e.g. first you find ‘“numberOfDownloads”:’ and then you make sure that following is ‘9’ and so on.)
How would I implement this in JAVA? I know that I should be using gson library, but don’t really undertand how it works right now, so some examples would be nice.
Thank you very much!
PS: Еще не до конца разобрался как правильно писать слекторы, не обращайте внимания на xpath, просто скопировал из firebug