Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertions using json schema v3 or v4 #126

Open
dinesh76in opened this issue Sep 6, 2018 · 9 comments
Open

Assertions using json schema v3 or v4 #126

dinesh76in opened this issue Sep 6, 2018 · 9 comments

Comments

@dinesh76in
Copy link
Collaborator

dinesh76in commented Sep 6, 2018

AC1:
GIVEN-The JSON schema of the API response
WHEN-I assert the API response using the schema with version as parameter
THEN-I should be able to get the desired result as PASS or FAIL to determine the test status.
AND-If failed, it should display or log(WARN or ERROR level) list the failure reasons in a pretty format.

AC2:
Have mechanism to pass the Schema file for the API response in the DSL.

Note:
"responseSchema" : (* new field which you can introduce) : Keep it optional. If supplied by the user, only then validate against it(the "body" of the response).

I think only the "body" should match the Schema definition, right?
Definitely not the "status" I mean. Have a look at the Schema definition file.
If yes, then implement the field as "responseBodySchema" (instead of "responseSchema")

Example:

{
    ...
    ...
    "responseSchema": {
        "schemaPath": "path/to/schema/file",
        "schemaVersion": "W3 Version? 3.0 or 4.0" //<--- optional (assign a default value if not supplied by user)
    },
    "verify": {
        "status": 200,
        "body": {
            "login": "octocat",
            "id": 583231,
            "type": "User"
        }
    }
}

AC3: (Future purpose - Implement via a new ticket if there is a Usecase for this, otherwise not needed now as AC2 shd cover most usecases)
GIVEN-I want to assert the API response using a given schema of v3 or v4(parameterised)
WHEN-I receive the API response
THEN-I should be able to get the desired result as PASS or FAIL to determine the test status

@santhoshTpixler
Copy link
Collaborator

santhoshTpixler commented Jan 17, 2019

This feature looks interesting. Do we have it already? @dinesh76in

@Yash-cor
Copy link

Yash-cor commented Sep 3, 2024

Are we having Json Schema validation or we have to include it from scratch.

@authorjapps
Copy link
Owner

authorjapps commented Sep 4, 2024

Are we having Json Schema validation or we have to include it from scratch.

Currently it does a kind of schema validation(data types, values etc at basic level) with respect to the response it receives from the API. But it doesn't do a validation against an external schema file. Also there is no mechanism currently to pass an external schema file name to the DSL/framework.
Some impl was done by a collaborator on this line few years ago, but Swagger based, and it was not fully developed then. You can search for this ticket and see how far it was done, probably draw some idea from there and dev it.

If you are trying to implement this external file based validation, it will be a nice feature and very helpful for the automation journey.

@Yash-cor
Copy link

Yash-cor commented Sep 5, 2024

Ok so i will be working on this. Could you also provide with some test case from your side.

@Yash-cor

This comment was marked as resolved.

@authorjapps
Copy link
Owner

Hello @Yash-cor , appreciate you're trying trying to dev this.
Can you attach the PR link here to this ticket?

I think we need a schema file against which the response can be validated, it should be W3 standard imo.
Lets have a look at the PR, then I will try to add some ACs which will help in impl.
Thanks for understanding

@Yash-cor
Copy link

This is the link of the PR that i've raised.
In this I tried to implement Json Schema validation for Response that we get from API testing.

@Yash-cor
Copy link

Hello I've raised PR and attached the link above.

@authorjapps
Copy link
Owner

authorjapps commented Oct 8, 2024

Hello @Yash-cor , appreciate you're trying trying to dev this. Can you attach the PR link here to this ticket?

I think we need a schema file against which the response can be validated, it should be W3 standard imo. Lets have a look at the PR, then I will try to add some ACswhich will help in the impl. Thanks for understanding.

Apologies for late reply @Yash-cor . Now I have captured the ACs(see AC2 mostly) , have a look please.
You can tweak your implementation and reuse most of your code.

Also, don't delete this current PR. Keep it as it is and do not change it. You can decline or close to avoid accidental merge if that's allowed).
Create a new PR matching the ACs in the description please.
Hope it's clear :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants