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

Search for json element in a GET api response #98

Open
johnreytanquinco opened this issue May 28, 2018 · 1 comment
Open

Search for json element in a GET api response #98

johnreytanquinco opened this issue May 28, 2018 · 1 comment

Comments

@johnreytanquinco
Copy link

johnreytanquinco commented May 28, 2018

Im happy that I was able to use and test this extension for my needs. But I encounter an issue, might be a support feature given the condition and result below.

Condition:
GET api/123-123-123?_format=json - FAILED

[
	{
		"uuid": "123-123-123"
	}
]

GET content/1?_format=json - PASSED

{
	"uuid": [
		{
			"value": "abc-abc-abc"
		}
	]
}

Test Result


  Scenario: Sending GET request to existing resource should lead to 200                         # /opt/app-root/src/html/modules/custom/spa/behat/features/capabilities/custom/send_request.feature:10
    When I send a GET request to "content/1?_format=json"                                      # Ubirak\RestApiBehatExtension\RestApiContext::iSendARequest()
    Then the response status code should be in 200                                              # Ubirak\RestApiBehatExtension\RestApiContext::theResponseCodeShouldBeIn()
    And the JSON node "uuid[0].value" should be equal to "abc-abc-abc" # Ubirak\RestApiBehatExtension\Json\JsonContext::theJsonNodeShouldBeEqualTo()

  Scenario: Sending GET request to existing resource should lead to 200                         # /opt/app-root/src/html/modules/custom/spa/behat/features/capabilities/custom/send_request.feature:15
    When I send a GET request to "api/123-123-123?_format=json" # Ubirak\RestApiBehatExtension\RestApiContext::iSendARequest()
    And print last responses                                                                    # ApiFeatureContext::printLastResponses()
    Then the response status code should be in 200                                              # Ubirak\RestApiBehatExtension\RestApiContext::theResponseCodeShouldBeIn()
    And the JSON node "uuid[0].value" should be equal to "123-123-123"    # Ubirak\RestApiBehatExtension\Json\JsonContext::theJsonNodeShouldBeEqualTo()
      Failed to evaluate expression "uuid[0].value" (Ubirak\RestApiBehatExtension\Json\WrongJsonExpectation)
    │
    ╳  Warning: file_put_contents(/opt/app-root/src/html/modules/custom/spa/behat/screenshot/20180528-04_33_52-test-rest-api-request-error.jpg): failed to open stream: Permission denied in /opt/app-root/src/html/modules/custom/spa/behat/features/bootstrap/SocialMinkContext.php line 58
    │
    └─ @AfterStep # SocialMinkContext::takeScreenShotAfterFailedStep()

Does it have to do with the json format response? If yes, can anyone help of what is the correct way of searching for an element for uuid[0].value(on the failing result).

Already tried uuid and uuid[0], same result.

@stephpy
Copy link
Member

stephpy commented May 30, 2018

Hi, did you try root[0].uuid ?

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

No branches or pull requests

2 participants