Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Addidng additional examples to step definitons #127

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
352 changes: 329 additions & 23 deletions src/Context/BrowserContext.php

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/Context/DebugContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ class DebugContext extends BaseContext
{
private $screenshotDir;

public function __construct($screenshotDir = '.')
public function __construct($screenshotDir = './screenshots')
{
$this->screenshotDir = $screenshotDir;
}

/**
* Pauses the scenario until the user presses a key. Useful when debugging a scenario.
* Example: When I put a breakpoint
* Example: Then I put a breakpoint
* Example: And I put a breakpoint
*
* @Then (I )put a breakpoint
*/
Expand All @@ -30,6 +33,9 @@ public function iPutABreakpoint()

/**
* Saving a screenshot
* Example: When I save a screenshot in "logInView"
* Example: Then I save a screenshot in "logInView"
* Example: And I save a screenshot in "logInView"
*
* @When I save a screenshot in :filename
*/
Expand Down
92 changes: 92 additions & 0 deletions src/Context/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function __construct(HttpCallResultPool $httpCallResultPool, $evaluationM

/**
* Checks, that the response is correct JSON
* Example: Then the response should be in JSON
* Example: And the response should be in JSON
*
* @Then the response should be in JSON
*/
Expand All @@ -33,6 +35,8 @@ public function theResponseShouldBeInJson()

/**
* Checks, that the response is not correct JSON
* Example: Then the response should not be in JSON
* Example: And the response should not be in JSON
*
* @Then the response should not be in JSON
*/
Expand All @@ -46,6 +50,8 @@ public function theResponseShouldNotBeInJson()

/**
* Checks, that given JSON node is equal to given value
* Example: Then the JSON node "isBatman"should be equal to "true"
* Example: And the JSON node "isBatman" should be equal to "true"
*
* @Then the JSON node :node should be equal to :text
*/
Expand All @@ -64,6 +70,8 @@ public function theJsonNodeShouldBeEqualTo($node, $text)

/**
* Checks, that given JSON node has N element(s)
* Example: Then the JSON node "bio" should have 5 elements
* Example: And the JSON node "bio" should have 5 elements
*
* @Then the JSON node :node should have :count element(s)
*/
Expand All @@ -78,6 +86,8 @@ public function theJsonNodeShouldHaveElements($node, $count)

/**
* Checks, that given JSON node contains given value
* Example: Then the JSON node "trueIdentity" should contain "Bruce Wayne"
* Example: And the JSON node "trueIdentity" should contain "Bruce Wayne"
*
* @Then the JSON node :node should contain :text
*/
Expand All @@ -92,6 +102,8 @@ public function theJsonNodeShouldContain($node, $text)

/**
* Checks, that given JSON node does not contain given value
* Example: Then the JSON node "isRobin" should not contain "true"
* Example: And the JSON node "isRobin" should not contain "true"
*
* @Then the JSON node :node should not contain :text
*/
Expand All @@ -106,6 +118,8 @@ public function theJsonNodeShouldNotContain($node, $text)

/**
* Checks, that given JSON node exist
* Example: Then the JSON node "id" should exist
* Example: And the JSON node "id" should exist
*
* @Given the JSON node :name should exist
*/
Expand All @@ -124,6 +138,8 @@ public function theJsonNodeShouldExist($name)

/**
* Checks, that given JSON node does not exist
* Example: Then the JSON node "Robin" should not exist
* Example: And the JSON node "Robin" should not exist
*
* @Given the JSON node :name should not exist
*/
Expand All @@ -135,6 +151,56 @@ public function theJsonNodeShouldNotExist($name)
}

/**
* Checks provided JSON against a JSON schema
* Example: Then the JSON should be valid according to this schema:
* """
* {
* "$schema": "http://json-schema.org/draft-04/schema#",
* "title": "Heroes",
* "description": "A list of heroes from the known universe",
* "type": "object",
* "properties": {
* "id": {
* "description": "The unique identifier for a hero",
* "type": "integer"
* },
* "name": {
* "description": "Name of the hero",
* "type": "string"
* },
* "alterEgo": {
* "description": "Alter ego for hero",
* "type": "string"
* }
* },
* "required": ["id", "name", "alterEgo"]
* }
* """
* Example: And the JSON should be valid according to this schema:
* """
* {
* "$schema": "http://json-schema.org/draft-04/schema#",
* "title": "Heroes",
* "description": "A list of heroes from the known universe",
* "type": "object",
* "properties": {
* "id": {
* "description": "The unique identifier for a hero",
* "type": "integer"
* },
* "name": {
* "description": "Name of the hero",
* "type": "string"
* },
* "alterEgo": {
* "description": "Alter ego for hero",
* "type": "string"
* }
* },
* "required": ["id", "name", "alterEgo"]
* }
* """
*
* @Then the JSON should be valid according to this schema:
*/
public function theJsonShouldBeValidAccordingToThisSchema(PyStringNode $schema)
Expand All @@ -146,6 +212,10 @@ public function theJsonShouldBeValidAccordingToThisSchema(PyStringNode $schema)
}

/**
* Checks provided JSON against a provided JSON schema
* Example: Then the JSON should be valid according to the schema "http://batman.com/secret-schema"
* Example: And the JSON should be valid according to the schema "http://batman.com/secret-schema"
*
* @Then the JSON should be valid according to the schema :filename
*/
public function theJsonShouldBeValidAccordingToTheSchema($filename)
Expand All @@ -166,6 +236,24 @@ public function theJsonShouldBeValidAccordingToTheSchema($filename)
}

/**
* Checks that the JSON response is equal to value
* Example: Then the JSON should be equal to:
* """
* {
* "id": 1,
* "name": "Batman",
* "alterEgo": "Bruce Wayne"
* }
* """
* Example: And the JSON should be equal to:
* """
* {
* "id": 1,
* "name": "Batman",
* "alterEgo": "Bruce Wayne"
* }
* """
*
* @Then the JSON should be equal to:
*/
public function theJsonShouldBeEqualTo(PyStringNode $content)
Expand All @@ -187,6 +275,10 @@ public function theJsonShouldBeEqualTo(PyStringNode $content)
}

/**
* Prints last JSON response
* Example: Then print last JSON response
* Example: And print last JSON response
*
* @Then print last JSON response
*/
public function printLastJsonResponse()
Expand Down
Loading