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

Support JSONPath expression syntax #44

Open
oqq opened this issue Feb 8, 2017 · 6 comments
Open

Support JSONPath expression syntax #44

oqq opened this issue Feb 8, 2017 · 6 comments
Assignees

Comments

@oqq
Copy link

oqq commented Feb 8, 2017

Hi @christeredvartsen!

Your current implementation for json tests are not really flexible. I would recommend another approach for a test expression.

How about a new behavior like @Then JSONPath :path in response contains :value, where :path got resolved by something like https://github.com/FlowCommunications/JSONPath and the value could be any scalar value or one of your @function expressions.

@christeredvartsen
Copy link
Member

I have a local branch that does exactly that. I haven't added anything regarding that to #39, but will consider it. So it will be added to either 2.0 or 2.1.

@christeredvartsen
Copy link
Member

Do you have any experience with mtdowling/jmespath.php? That seems to be somewhat more stable than flow/jsonpath (at least wrt version numbers) and has a bunch more downloads.

@oqq
Copy link
Author

oqq commented Feb 22, 2017

To be honest I have only experience with jmespath.php and would prefer it for the same reasons.

@christeredvartsen christeredvartsen modified the milestone: v2.1 Feb 23, 2017
@christeredvartsen christeredvartsen self-assigned this Feb 23, 2017
@christeredvartsen
Copy link
Member

I have finally started working on this, and have currently come up with two possible steps:

Then the :expression expression in the response body JSON matches :value

and

Then the :expression expression in the response body JSON matches: <PyStringNode>

The first does a simple value matching using Assert\Assertion::eq, while the second uses Assert\Asseriton::same, and decodes the value of the <PyStringNode> as JSON before doing the match.

Are you still interested in this functionality @oqq? If so, do you have anything to add to the above?

@oqq
Copy link
Author

oqq commented Nov 23, 2017

Of curse I am!

Maybe a test with Assertion::same would fail, since the response string is not exactly the same for a json string.

I would like to a test against json data type (string, number, object, area, boolean and null).
Also a test against existent or lacking paths/values.

@christeredvartsen
Copy link
Member

Perhaps sending the data through to the array comparator would work better. Then one could use the matcher functions against the data found by the expression.

@christeredvartsen christeredvartsen removed this from the v2.2 milestone Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants