Giter Club home page Giter Club logo

Comments (3)

amar-1314 avatar amar-1314 commented on September 4, 2024

Can someone please look into it?

from restassured.net.

ViniGasp avatar ViniGasp commented on September 4, 2024

I have the same problem, I need the response body to perform validations with the database.
I'm working on a big project and this is essential for validations.

Thanks.

from restassured.net.

numo16 avatar numo16 commented on September 4, 2024

The lack of strongly typed Retrieve can be gotten around with something like JSON.net to serialize/deserialize to your desired type. I use an extension method like the following to wrap this functionality:

public static T RetrieveBody<T>(this ResponseContext context)
{
    var json = (string)context.Retrieve(x => JsonConvert.SerializeObject(x));
    return JsonConvert.DeserializeObject<T>(json);
}

Which then allows you to use it like this:

var response = new RestAssured()
  .Given()
    .Name("JsonIP Test Suite")
    .Header("Content-Type", "application/json")
    .Header("Accept-Encoding", "gzip,deflate")
  .When()
    .Get("http://jsonip.com")
  .Then()
    .RetrieveBody<Dictionary<string,string>>();

Assert.Equal(response["ip"], "2605:6000:f705:ab00:78e3:1959:78d4:bd76");

where Dictionary<string, string> is whatever type you want to convert the response to.

from restassured.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.