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

Schema Validation issues. Not ending launch #67

Open
dantench opened this issue Sep 23, 2021 · 3 comments
Open

Schema Validation issues. Not ending launch #67

dantench opened this issue Sep 23, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@dantench
Copy link

dantench commented Sep 23, 2021

In our suite we have been using the following:

pm.test("Validate schema 2", ()=> { pm.response.to.have.jsonSchema(JSON.parse(pm.collectionVariables.get("schema"))); });

In ReportPortal this doesn't seem to validate/result in an 'finish' result.

Changing to:

pm.test("Validate schema 1", function() { pm.expect(tv4.validate(pm.response.json(),((JSON.parse(pm.collectionVariables.get("schema"))),true,true))).to.be.true; });

image

image

Then frustratingly when removing "Validate Schema 2" ... it also then doesn't work for "Validate Schema 1" though it did before... so something somewhere isn't right when it comes to validating schemas.

image

Incidently, postman itself has no issues with either:

image

@dantench dantench changed the title Postman pm.response.to.have.jsonSchema = not ending launch Schema Validation issues. Not ending launch Sep 23, 2021
@dantench
Copy link
Author

dantench commented Sep 23, 2021

Okay...... so on more playing this is actually a different issue :)

//Response time validation
if (!pm.collectionVariables.has("skipResponseTimeValidation")) {
    var responseTime = (pm.environment.has("responseTimeThreshold") ? pm.environment.get("responseTimeThreshold") : 500);
    pm.test("Response time is less than 500ms", function () {
        console.log(parseInt(responseTime));
		pm.expect(pm.response.responseTime).to.be.below(parseInt(responseTime));
    });
}

//JSON and Content-type validation
if (!pm.collectionVariables.has("skipContentTypeValidation")) {
    pm.test("Verify Response is JSON & validate Content-Type ", function () {
        pm.response.to.be.json;
        pm.expect((pm.response.headers.get("Content-Type")).replace(/\s/g, "")).to.eql("application/json;charset=UTF-8");
    });
} 

^ this caused the issue, where the below was set:

pm.collectionVariables.set("skipContentTypeValidation"); pm.collectionVariables.set("skipResponseTimeValidation");

The tests would still 'run' ( according to report portal ) and wouldn't close out. I think this is an extension of: #65 because report portal doesn't recognise a test wasn't completed/skipped.

Changing this to:

//Response time validation
if (pm.collectionVariables.has("skipResponseTimeValidation")) {
    var responseTime = (pm.environment.has("responseTimeThreshold") ? pm.environment.get("responseTimeThreshold") : 500);
    pm.test.skip("Response time is less than 500ms", function () {
        console.log("Skip Response Time Validation");
		pm.expect(pm.response.responseTime).to.be.below(parseInt(responseTime));
    })
}
else {
    pm.test("Response time is less than 500ms", function () {
        var responseTime = (pm.environment.has("responseTimeThreshold") ? pm.environment.get("responseTimeThreshold") : 500);
        console.log("Skip Response Time Validation");
		pm.expect(pm.response.responseTime).to.be.below(parseInt(responseTime));
    })
}


//JSON and Content-type validation
if (pm.collectionVariables.has("skipContentTypeValidation")) {
    pm.test.skip("Verify Response is JSON & validate Content-Type ", function () {
        console.log("Skip Content Type Validation");
        pm.response.to.be.json;
        pm.expect((pm.response.headers.get("Content-Type")).replace(/\s/g, "")).to.eql("application/json;charset=UTF-8");
    });
}
else {
    pm.test("Verify Response is JSON & validate Content-Type ", function () {
        pm.response.to.be.json;
        pm.expect((pm.response.headers.get("Content-Type")).replace(/\s/g, "")).to.eql("application/json;charset=UTF-8");
    });
}

Solved this problem.

@dantench
Copy link
Author

I think this is ultimatly caused by : #64

@chivekrodis chivekrodis added the bug Something isn't working label Oct 19, 2021
@dgosantos89
Copy link

#94

@AmsterGet AmsterGet linked a pull request Aug 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants