From 5d46d0ab2092e7a9fd911e2875bd2c4ee5aba267 Mon Sep 17 00:00:00 2001 From: Sajjad Hossain Date: Mon, 1 Jun 2015 15:13:55 -0400 Subject: [PATCH 1/5] added addtional documents, added examples to all step definitions for additional clarity when running 'behat -di' or 'behat -dl' --- src/Context/BrowserContext.php | 375 ++++++++++++++++++++++++++++++--- src/Context/DebugContext.php | 8 +- src/Context/JsonContext.php | 94 +++++++++ src/Context/RestContext.php | 92 +++++++- src/Context/SystemContext.php | 88 +++++++- src/Context/TableContext.php | 16 ++ src/Context/XmlContext.php | 109 ++++++++++ 7 files changed, 753 insertions(+), 29 deletions(-) diff --git a/src/Context/BrowserContext.php b/src/Context/BrowserContext.php index 617ac481..f73a47cf 100644 --- a/src/Context/BrowserContext.php +++ b/src/Context/BrowserContext.php @@ -2,12 +2,19 @@ namespace Sanpi\Behatch\Context; +/** + * Set this to your local timezone + */ +date_default_timezone_set('America/New_York'); + use Behat\Gherkin\Node\TableNode; use Behat\Mink\Exception\ExpectationException; use Behat\Mink\Exception\ResponseTextException; use Behat\Mink\Exception\ElementNotFoundException; +use Behat\Behat\Context\Context; +use Behat\Behat\Context\SnippetAcceptingContext; -class BrowserContext extends BaseContext +class BrowserContext extends BaseContext implements Context, SnippetAcceptingContext { private $timeout; private $dateFormat = 'dmYHi'; @@ -25,24 +32,113 @@ public function closeBrowser() $this->getSession()->stop(); } + //Window sizes for Mac and Windows + + /** + * Sets browser window to custom size + * Example: Given I set browser window size to "1900" x "1200" + * Example: When I set browser window size to "800" x "400" + * Example: And I set browser window size to "2880" x "1800" + * + * @Given (I )set my browser window size to :width x :height + * @param string $width, $height The message. + */ + public function iSetMyBrowserWindowSizeToX($width, $height) { + $this->getSession()->getDriver()->resizeWindow((int)$width, (int)$height, 'current'); + } + /** + * Sets browser window to 1440 by 900 + * Example: Given I set my browser window size to MacBook Standard + * Example: When I set my browser window size to MacBook Standard + * Example: And I set my browser window size to MacBook Standard + * + * @Given (I )set my browser window size to MacBook Air + */ + public function iSetMyBrowserWindowSizeToMacbookStandard() + { + $this->getSession()->getDriver()->resizeWindow((int)'1440', (int)'900', 'current'); + } + + /** + * Sets browser window to 2880 by 1800 + * Example: Given I set my browser window size to 15 inch MacBook Retina + * Example: When I set my browser window size to 15 inch MacBook Retina + * Example: And I set my browser window size to 15 inch MacBook Retina + * + * @Given I set my browser window size to 15 inch MacBook Retina + */ + public function iSetMyBrowserWindowSizeTo15InchMacbookRetina() + { + $this->getSession()->getDriver()->resizeWindow((int)'2880', (int)'1800', 'current'); + } + + /** + * Sets browser window to 2560 by 1600 + * Example: Given I set my browser window size to 13 inch MacBook Retina + * Example: When I set my browser window size to 13 inch MacBook Retina + * Example: And I set my browser window size to 13 inch MacBook Retina + * + * @Given (I )set my browser window size to 13 inch MacBook Retina + */ + public function iSetMyBrowserWindowSizeTo13InchMacbookRetina() + { + $this->getSession()->getDriver()->resizeWindow((int)'2560', (int)'1600', 'current'); + } + + /** + * Sets browser window to 1280 by 1280 + * Example: Given I set my browser window size to Windows Standard + * Example: When I set my browser window size to Windows Standard + * Example: And I set my browser window size to Windows Standard + * + * @Given (I )set my browser window size to Windows Standard + */ + public function iSetMyBrowserWindowSizeToWindowsStandard() + { + $this->getSession()->getDriver()->resizeWindow((int)'1280', (int)'1280', 'current'); + } + + //HTTP Authentication + /** * Set login / password for next HTTP authentication + * Example: Given I set authentication with "bwayne" and "iLoveBats" + * Example: When I set authentication with "bwayne" and "iLoveBats" + * Example: And I set authentication with "bwayne" and "iLoveBats" * - * @When I set basic authentication with :user and :password + * @When (I )set basic authentication with :user and :password + * @param $user + * @param $password */ public function iSetBasicAuthenticationWithAnd($user, $password) { $this->getSession()->setBasicAuth($user, $password); } + //Go to URL with parameters + /** * Open url with various parameters + * Change line:128 $url variable to url of choice + * Example: Given I am on url composed by: + * | parameters | + * | /heroes | + * | /batman | + * Example: When I am on url composed by: + * | parameters | + * | /heroes | + * | /batman | + * Example: And I am on url composed by: + * | parameters | + * | /heroes | + * | /batman | * * @Given (I )am on url composed by: + * @param TableNode $tableNode */ public function iAmOnUrlComposedBy(TableNode $tableNode) { - $url = ''; + $url = 'http://adcade.com/'; foreach ($tableNode->getHash() as $hash) { $url .= $hash['parameters']; } @@ -51,8 +147,12 @@ public function iAmOnUrlComposedBy(TableNode $tableNode) ->visit($url); } + //Clicks CSS element + /** * Clicks on the nth CSS element + * Example: When I click on 1st "ul li a" element + * Example: And I click on 6th "ul li a" element * * @When (I )click on the :index :element element */ @@ -69,7 +169,150 @@ public function iClickOnTheNthElement($index, $element) } /** + * Confirms the popup with "OK" press + * Example: When I confirm the popup + * Example: And I confirm the popup + * + * @When /^I confirm the popup$/ + */ + public function confirmPopup() + { + $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); + } + /** + * Cancels the popup with "OK" press + * Example: When I cancel the popup + * Example: And I cancel the popup + * + * @When /^(?:|I )cancel the popup$/ + */ + public function cancelPopup() + { + $this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert(); + } + + /** + * Asserts string in popup + * Example: And I should see "Bruce Wayne is not Batman" in popup + * Example: Then I should see "Bruce Wayne is not Batman" in popup + * + * @When /^I should see "([^"]*)" in popup$/ + * @param string $message The message. + * @throws Exception + */ + public function assertPopupMessage($message) + { + $alertText = $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text(); + if ($alertText !== $message){ + throw new Exception("Modal dialog present: $alertText, when expected was $message"); + } + } + + /** + * Fills out popup field with text + * Example: When I fill "Then why does he hang out with Dick Grayson?" in popup + * Example: And I fill "Then why does he hang out with Dick Grayson?" in popup + * + * @When /^(?:|I )fill "([^"]*)" in popup$/ + * @param string $message The message. + */ + public function setPopupText($message) + { + $this->getSession()->getDriver()->getWebDriverSession()->postAlert_text($message); + } + + /** + * Scrolls to the bottom of the given page + * Example: Given I scroll to the bottom + * Example: When I scroll to the bottom + * Example: And I scroll to the bottom + * + * @Given /^I scroll to the bottom$/ + */ + public function iScrollToBottom() { + $javascript = 'window.scrollTo(0, Math.max(document.documentElement.scrollHeight, document.body.scrollHeight, document.documentElement.clientHeight));'; + $this->getSession()->executeScript($javascript); + } + + /** + * Scrolls to the top of the given page + * Example: Given I scroll to the top + * Example: When I scroll to the top + * Example: And I scroll to the top + * + * @Given /^I scroll to the top$/ + */ + public function iScrollToTop() { + $this->getSession()->executeScript('window.scrollTo(0,0);'); + } + + /** + * Scroll to a certain element by label. + * Requires an "id" attribute to uniquely identify the element in the document. + * + * Example: Given I scroll to the "Submit" button + * Example: Given I scroll to the "My Date" field + * + * @Given /^I scroll to the "([^"]*)" (field|link|button)$/ + */ + public function iScrollToField($locator, $type) { + $page = $this->getSession()->getPage(); + $el = $page->find('named', array($type, $locator)); + # assertNotNull($el, sprintf('%s element not found', $locator)); + $id = $el->getAttribute('id'); + if(empty($id)) { + throw new \InvalidArgumentException('Element requires an "id" attribute'); + } + $js = sprintf("document.getElementById('%s').scrollIntoView(true);", $id); + $this->getSession()->executeScript($js); + } + + /** + * Restarts Selenium session + * Example: Given I am on a new session + * Example: And I am on a new session + * + * @Given /^I am on a new session$/ + */ + public function iAmOnANewSession() + { + $this->getSession()->restart(); + } + + /** + * Clicks on element via XPath + * Example: When I click on the element with xpath '//*[@id="find-out-who-batman-is"]' + * Example: And I click on the element with xpath '//*[@id="find-out-who-batman-is"]' + * + * @When /^I click on the element with xpath \'([^\']*)\'$/ + * @Given /^I click on the element with xpath "([^"]*)"$/ + * @param string $xpath is an XPath for an object + */ + public function iClickOnTheElementWithXPath($xpath) + { + $session = $this->getSession(); // get the mink session + $element = $session->getPage()->find( + 'xpath', + $session->getSelectorsHandler()->selectorToXpath('xpath', $xpath) + ); // runs the actual query and returns the element + + // errors must not pass silently + if (null === $element) { + throw new \InvalidArgumentException(sprintf('Could not evaluate XPath: "%s"', $xpath)); + } + + // ok, let's click on it + $element->click(); + } + + //Follows XPath element + //TODO: Fix this function + + /** + * THIS FUNCTION IS CURRENTLY DEPRECATED AND NEEDS TLC * Click on the nth specified link + * Example: When I click on 1st "ul li a" link + * Example: And I click on 6th "ul li a" link * * @When (I )follow the :index :link link */ @@ -90,6 +333,8 @@ public function iFollowTheNthLink($index, $link) /** * Fills in form field with current date + * Example: When I fill in "unix-date" with the current date + * Example: And I fill in "unix-date" with the current date * * @When (I )fill in :field with the current date */ @@ -99,7 +344,9 @@ public function iFillInWithTheCurrentDate($field) } /** - * Fills in form field with current date and strtotime modifier + * Fills in form field with current date and string to time (strtotime) modifier + * Example: When I fill in "unix-date" with the current date and modifier "+1 day" + * Example: And I fill in "unix-date" with the current date * * @When (I )fill in :field with the current date and modifier :modifier */ @@ -111,6 +358,8 @@ public function iFillInWithTheCurrentDateAndModifier($field, $modifier) /** * Mouse over a CSS element + * Example: When I hover "large-button" + * Example: And I hover "large-button" * * @When (I )hover :element */ @@ -118,13 +367,15 @@ public function iHoverIShouldSeeIn($element) { $node = $this->getSession()->getPage()->find('css', $element); if ($node === null) { - throw new \Exception("The hovered element '$element' was not found anywhere in the page"); + throw new \Exception("The hoverable element '$element' was not found anywhere in the page"); } $node->mouseOver(); } /** * Save value of the field in parameters array + * Example: When I save the value of "name" in the "name" parameter + * Example: And I save the value of "name" in the "name" parameter * * @When (I )save the value of :field in the :parameter parameter */ @@ -141,6 +392,9 @@ public function iSaveTheValueOfInTheParameter($field, $parameter) /** * Checks, that the page should contains specified text after given timeout + * Example: Given I wait 3 seconds until I see "Hello, Bruce Wayne" + * Example: When I wait 3 seconds until I see "Hello, Bruce Wayne" + * Example: And I wait 3 seconds until I see "Hello, Bruce Wayne" * * @Then (I )wait :count second(s) until I see :text */ @@ -151,6 +405,9 @@ public function iWaitSecondsUntilISee($count, $text) /** * Checks, that the page should contains specified text after timeout + * Example: Given I wait until I see "Hello, Bruce Wayne" + * Example: When I wait until I see "Hello, Bruce Wayne" + * Example: And I wait until I see "Hello, Bruce Wayne" * * @Then (I )wait until I see :text */ @@ -161,6 +418,9 @@ public function iWaitUntilISee($text) /** * Checks, that the element contains specified text after timeout + * Example: Given I wait 3 seconds until I see "Hello, Bruce Wayne" in the "nav" element + * Example: When I wait 3 seconds until I see "Hello, Bruce Wayne" in the "nav" element + * Example: And I wait 3 seconds until I see "Hello, Bruce Wayne" in the "nav" element * * @Then (I )wait :count second(s) until I see :text in the :element element */ @@ -175,16 +435,12 @@ public function iWaitSecondsUntilISeeInTheElement($count, $text, $element) $this->assertContains($expected, $node->getText(), $message); } - /** - * @Then (I )wait :count second(s) - */ - public function iWaitSeconds($count) - { - sleep($count); - } /** * Checks, that the element contains specified text after timeout + * Example: Given I wait until I see "Hello, Bruce Wayne" in the "nav" element + * Example: When I wait until I see "Hello, Bruce Wayne" in the "nav" element + * Example: And I wait until I see "Hello, Bruce Wayne" in the "nav" element * * @Then (I )wait until I see :text in the :element element */ @@ -193,18 +449,11 @@ public function iWaitUntilISeeInTheElement($text, $element) $this->iWaitSecondsUntilISeeInTheElement($this->timeout, $text, $element); } - /** - * Checks, that the page should contains specified element after timeout - * - * @Then (I )wait for :element element - */ - public function iWaitForElement($element) - { - $this->iWaitSecondsForElement($this->timeout, $element); - } - /** * Wait for a element + * Example: Given I wait 1 second for "sign-up" element + * Example: When I wait 2 seconds for "sign-up" element + * Example: And I wait 3 seconds for "sign-up" element * * @Then (I )wait :count second(s) for :element element */ @@ -232,7 +481,53 @@ public function iWaitSecondsForElement($count, $element) } /** + * Checks, that the page should contains specified element after timeout + * Example: Given I wait for "sign-up" element + * Example: When I wait for "sign-up" element + * Example: And I wait for "sign-up" element + * + * @Then (I )wait for :element element + */ + public function iWaitForElement($element) + { + $this->iWaitSecondsForElement($this->timeout, $element); + } + + /** + * Waits seconds + * Example: Given I wait 1 second + * Example: When I wait 2 second + * Example: And I wait 3 seconds + * + * @Then (I )wait :count second(s) + * + */ + public function iWaitSeconds($count) + { + sleep($count); + } + + /** + * Waits seconds + * Example: Given I wait for 10 seconds + * Example: When I wait for 9 seconds + * Example: And I wait for 8 seconds + * + * @Given /^I wait for (\d+) seconds$/ + * + */ + public function iWaitForSeconds($seconds) + { + $this->getSession()->wait($seconds*1000); + } + + /** + * Asserts against number of elements in a response + * Example: Then I should see 80 "div" in the 1st "body" + * Example: And I should see 10 "li" in the 1st "body" + * * @Then /^(?:|I )should see (?P\d+) "(?P[^"]*)" in the (?P\d+)(?:st|nd|rd|th) "(?P[^"]*)"$/ + * */ public function iShouldSeeNElementInTheNthParent($count, $element, $index, $parent) { @@ -243,6 +538,10 @@ public function iShouldSeeNElementInTheNthParent($count, $element, $index, $pare } /** + * Asserts against number of elements in a response + * Example: Then I should see less than 199 "div" in the 1st "body" + * Example: And I should see less than 200 "li" in the 1st "body" + * * @Then (I )should see less than :count :element in the :index :parent */ public function iShouldSeeLessThanNElementInTheNthParent($count, $element, $index, $parent) @@ -254,7 +553,17 @@ public function iShouldSeeLessThanNElementInTheNthParent($count, $element, $inde } /** + * Asserts against number of elements in a response + * Example: Then I should see more than 10 "div" in the 1st "body" + * Example: And I should see more than 1 "li" in the 1st "body" + * * @Then (I )should see more than :count :element in the :index :parent + * + * @param $count + * @param $element + * @param $index + * @param $parent + * @throws \Exception */ public function iShouldSeeMoreThanNElementInTheNthParent($count, $element, $index, $parent) { @@ -266,8 +575,12 @@ public function iShouldSeeMoreThanNElementInTheNthParent($count, $element, $inde /** * Checks, that element with given CSS is enabled + * Example: Then the element ".btn .btn-default" should be enabled + * Example: And the element ".btn .btn-default" should be enabled * * @Then the element :element should be enabled + * @param $element + * @throws \Exception */ public function theElementShouldBeEnabled($element) { @@ -283,6 +596,8 @@ public function theElementShouldBeEnabled($element) /** * Checks, that element with given CSS is disabled + * Example: Then the element ".btn .btn-default" should be disabled + * Example: And the element ".btn .btn-default" should be disabled * * @Then the element :element should be disabled */ @@ -295,6 +610,8 @@ public function theElementShouldBeDisabled($element) /** * Checks, that given select box contains the specified option + * Example: Then the "heroes" select box should contain "Batman" + * Example: And the "heroes" select box should contain "Batman" * * @Then the :select select box should contain :option */ @@ -317,6 +634,8 @@ public function theSelectBoxShouldContain($select, $option) /** * Checks, that given select box does not contain the specified option + * Example: Then the "heroes" select box should not contain "Superman" + * Example: And the "heroes" select box should not contain "Superman" * * @Then the :select select box should not contain :option */ @@ -329,6 +648,8 @@ public function theSelectBoxShouldNotContain($select, $option) /** * Checks, that the specified CSS element is visible + * Example: Then the ".btn" element should be visible + * Example: And the ".btn" element should be visible * * @Then the :element element should be visible */ @@ -346,6 +667,8 @@ public function theElementShouldBeVisible($element) /** * Checks, that the specified CSS element is not visible + * Example: Then the ".btn" element should not be visible + * Example: And the ".btn" element should not be visible * * @Then the :element element should not be visible */ @@ -359,7 +682,9 @@ public function theElementShouldNotBeVisible($element) } /** - * Select a frame by its name or ID. + * Select a frame by its name or ID + * Example: When I switch to iframe "justAnotherIframe" + * Example: And I switch to frame "justAnotherIframe" * * @When (I )switch to iframe :name * @When (I )switch to frame :name @@ -370,7 +695,9 @@ public function switchToIFrame($name) } /** - * Go back to main document frame. + * Go back to main document frame + * Example: When I switch to main frame + * Example: And I switch to main frame * * @When (I )switch to main frame */ diff --git a/src/Context/DebugContext.php b/src/Context/DebugContext.php index 9e2d8667..4f1f1406 100644 --- a/src/Context/DebugContext.php +++ b/src/Context/DebugContext.php @@ -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 */ @@ -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 */ diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index 5b1e1fe0..13bc8f0d 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -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 */ @@ -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 */ @@ -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 */ @@ -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) */ @@ -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 */ @@ -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 */ @@ -106,6 +118,9 @@ public function theJsonNodeShouldNotContain($node, $text) /** * Checks, that given JSON node exist + * Example: Given the JSON node "id" should exist + * Example: Then the JSON node "id" should exist + * Example: And the JSON node "id" should exist * * @Given the JSON node :name should exist */ @@ -124,6 +139,9 @@ public function theJsonNodeShouldExist($name) /** * Checks, that given JSON node does not exist + * Example: Given the JSON node "Robin" should 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 */ @@ -135,6 +153,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) @@ -146,6 +214,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) @@ -166,6 +238,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) @@ -187,6 +277,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() diff --git a/src/Context/RestContext.php b/src/Context/RestContext.php index 292f0282..d1c9d2b4 100644 --- a/src/Context/RestContext.php +++ b/src/Context/RestContext.php @@ -5,18 +5,20 @@ use Behat\Gherkin\Node\TableNode; use Sanpi\Behatch\HttpCall\Request; use Behat\Gherkin\Node\PyStringNode; +use Buzz\Browser; class RestContext extends BaseContext { - private $request; - public function __construct(Request $request) { $this->request = $request; - } + } /** * Sends a HTTP request + * Example: Given I send a GET request to "/heroes/list" + * Example: When I send a GET request to "/heroes/list" + * Example: And I send a GET request to "/heroes/list" * * @Given I send a :method request to :url */ @@ -33,6 +35,18 @@ public function iSendARequestTo($method, $url, PyStringNode $body = null) /** * Sends a HTTP request with a some parameters + * Example: Given I send a GET request to "/heroes/list" with parameters: + * | userId | 27 | + * | username | bruceWayne | + * | password | iLoveBats123 | + * Example: When I send a GET request to "/heroes/list" with parameters: + * | userId | 27 | + * | username | bruceWayne | + * | password | iLoveBats123 | + * Example: And I send a GET request to "/heroes/list" with parameters: + * | userId | 27 | + * | username | bruceWayne | + * | password | iLoveBats123 | * * @Given I send a :method request to :url with parameters: */ @@ -66,6 +80,35 @@ public function iSendARequestToWithParameters($method, $url, TableNode $datas) /** * Sends a HTTP request with a body + * Example: Given I send a GET request to "/heroes/list" with body: + * """ + * { + * { + * "body": "I am not batman I take serious offense to any claims suggesting such outlandish remarks.", + * "id" : 1 + * } + * } + * """ + * Example: When I send a POST request to "/heroes/list" with form data: + * """ + * { + * { + * "postId": 1, + * "id": 1, + * "name": "I know who Batman is", + * "email": "Eliseo@gardner.biz", + * } + * } + * """ + * Example: And I send a GET request to "/heroes/list" with body: + * """ + * { + * { + * "body": "I am not batman I take serious offense to any claims suggesting such outlandish remarks.", + * "id" : 1 + * } + * } + * """ * * @Given I send a :method request to :url with body: */ @@ -74,8 +117,27 @@ public function iSendARequestToWithBody($method, $url, PyStringNode $body) $this->iSendARequestTo($method, $url, $body); } + /** * Checks, whether the response content is equal to given text + * Example: Then the response should be equal to + * """ + * { + * { + * "body": "Bruce Wayne, billionaire playboy.", + * "id" : 1 + * } + * } + * """ + * Example: And the response should be equal to + * """ + * { + * { + * "body": "Bruce Wayne, billionaire playboy.", + * "id" : 1 + * } + * } + * """ * * @Then the response should be equal to */ @@ -89,6 +151,8 @@ public function theResponseShouldBeEqualTo(PyStringNode $expected) /** * Checks, whether the response content is null or empty string + * Example: Then the response should be empty + * Example: And the response should be empty * * @Then the response should be empty */ @@ -101,6 +165,8 @@ public function theResponseShouldBeEmpty() /** * Checks, whether the header name is equal to given text + * Example: Then the header "User-Agent" should be equal to "Batbook, BatBrowser" + * Example: And the header "User-Agent" should be equal to "Batbook, BatBrowser" * * @Then the header :name should be equal to :value */ @@ -114,6 +180,8 @@ public function theHeaderShouldBeEqualTo($name, $value) /** * Checks, whether the header name contains the given text + * Example: Then the header "Authentication" should contain "1024 Bit Super-Authenticated" + * Example: And the header "Authentication" should contain "1024 Bit Super-Authenticated" * * @Then the header :name should contain :value */ @@ -126,6 +194,8 @@ public function theHeaderShouldBeContains($name, $value) /** * Checks, whether the header name doesn't contain the given text + * Example: Then the header "" should contain "1024 Bit Super-Authenticated" + * Example: And the header "Authentication" should contain "1024 Bit Super-Authenticated" * * @Then the header :name should not contain :value */ @@ -138,6 +208,8 @@ public function theHeaderShouldNotContain($name, $value) /** * Checks, whether the header not exist + * Example: Then the header "Content-Type" should not exist + * Example: And the header "Content-Type" should not exist * * @Then the header :name should not exist */ @@ -155,6 +227,8 @@ protected function theHeaderShouldExist($name) /** * Checks, that the response header expire is in the future + * Example: Then the response should expire in the future + * Example: And the response should expire in the future * * @Then the response should expire in the future */ @@ -170,6 +244,8 @@ public function theResponseShouldExpireInTheFuture() /** * Add an header element in a request + * Example: Then I add "Content-Type" header equal to "application/json" + * Example: And I add "Content-Type" header equal to "application/json" * * @Then I add :name header equal to :value */ @@ -179,6 +255,10 @@ public function iAddHeaderEqualTo($name, $value) } /** + * Asserts against responses encoding type, see http://www.iana.org/assignments/character-sets/character-sets.xhtml + * Example: Then the response should be encoded in "UTF-8" + * Example: And the response should be encoded in "UTF-8" + * * @Then the response should be encoded in :encoding */ public function theResponseShouldBeEncodedIn($encoding) @@ -192,6 +272,9 @@ public function theResponseShouldBeEncodedIn($encoding) } /** + * Prints last response + * Example: Then print last response headers + * * @Then print last response headers */ public function printLastResponseHeaders() @@ -207,6 +290,9 @@ public function printLastResponseHeaders() /** + * Prints the curl equivalent to the request + * Example: Then print the corresponding curl command + * * @Then print the corresponding curl command */ public function printTheCorrespondingCurlCommand() diff --git a/src/Context/SystemContext.php b/src/Context/SystemContext.php index 017dbffd..e8dca9d0 100644 --- a/src/Context/SystemContext.php +++ b/src/Context/SystemContext.php @@ -21,8 +21,39 @@ public static function getTranslationResources() return glob(__DIR__ . '/../../i18n/*.xliff'); } + /** + * Changes directory to :directory requested + * Example: Given I am in "/Users/bWayne/secretfiles/batman" + * Example: And I am in "/Users/bWayne/secretfiles/batman" + * + * @Given I am in :dir directory + */ + public function iAmInDirectory($dir) + { + //if (!file_exists($dir)) { + // mkdir($dir); + //} + chdir($dir); + } + + /** + * Runs a command line argument + * Example: When I run ".openCaveEntrance" + * Example: And I run ".openCaveEntrance" + * + * @When /^I run :command + */ + public function iRun($command) + { + exec($command, $output); + $this->output = trim(implode("\n", $output)); + } + /** * Uploads a file using the specified input field + * Example: Given I put the file "batman_profile.jpg" into "heroImage" + * Example: When I put the file "batman_profile.jpg" into "heroImage" + * Example: And I put the file "batman_profile.jpg" into "heroImage" * * @When (I )put the file :file into :field */ @@ -37,6 +68,9 @@ public function putFileIntoField($file, $field) /** * Execute a command + * Example: Given I execute "pwd" + * Example: When I execute "pwd" + * Example: And I execute "pwd" * * @Given (I )execute :command */ @@ -51,6 +85,9 @@ public function iExecute($cmd) /** * Execute a command from project root + * Example: Given I execute "php ./openBatCave.php" from project root + * Example: When I execute "php ./openBatCave.php" from project root + * Example: And I execute "php ./openBatCave.php" from project root * * @Given (I )execute :command from project root */ @@ -61,8 +98,30 @@ public function iExecuteFromProjectRoot($cmd) } /** + * Creates a file via touch command + * Example: Given I create the file "batmansPasswords.txt" containing" + * """ + * Facebook: RIPMarthaThomas1927 + * Twitter: RIPTimothyDrake1986 + * Netflix: RIPDamianWayne2009 + * Google: DamnIveSeenSomeStuff + * """ + * Example: When I create the file "batmansPasswords.txt" containing" + * """ + * Facebook: RIPMarthaThomas1927 + * Twitter: RIPTimothyDrake1986 + * Netflix: RIPDamianWayne2009 + * Google: DamnIveSeenSomeStuff + * """ + * Example: And I create the file "batmansPasswords.txt" containing" + * """ + * Facebook: RIPMarthaThomas1927 + * Twitter: RIPTimothyDrake1986 + * Netflix: RIPDamianWayne2009 + * Google: DamnIveSeenSomeStuff + * """ + * * @Given (I )create the file :filename containing: - * @Given (I )create the file :filename contening: */ public function iCreateTheFileContaining($filename, PyStringNode $string) { @@ -76,6 +135,11 @@ public function iCreateTheFileContaining($filename, PyStringNode $string) } /** + * Prints the content of passed file + * Example: Given I print the content of "./batmansGreatestSecrets.txt" file + * Example: When I print the content of "./batmansGreatestSecrets.txt" file + * Example: Then I print the content of "./batmansGreatestSecrets.txt" file + * * @Then print the content of :filename file */ public function printTheContentOfFile($filename) @@ -88,6 +152,28 @@ public function printTheContentOfFile($filename) } } + /** + * Asserts against previously run command line argument + * Example: Then I should see: + * """ + * Opening cave, master Bruce. + * """ + * Example: And I should see: + * """ + * Opening cave, master Bruce. + * """ + * + * @Then I should see: + */ + public function iShouldSee(PyStringNode $string) + { + if ($string->getRaw() !== $this->output) { + throw new \Exception( + "Actual output is:\n" . $this->output + ); + } + } + /** * @AfterScenario */ diff --git a/src/Context/TableContext.php b/src/Context/TableContext.php index 61999e89..dfe71392 100644 --- a/src/Context/TableContext.php +++ b/src/Context/TableContext.php @@ -8,6 +8,10 @@ class TableContext extends BaseContext { /** * Checks that the specified table's columns match the given schema + * Example: Then the columns schema of the "heroes" table should match: + * | hero_id | hero_name | alter_ego | + * Example: And the columns schema of the "heroes" table should match: + * | hero_id | hero_name | alter_ego | * * @Then the columns schema of the :table table should match: */ @@ -25,6 +29,8 @@ public function theColumnsSchemaShouldMatch($table, TableNode $text) /** * Checks that the specified table contains the given number of columns + * Example: Then I should see 4 columns in the "heroes" table + * Example: And I should see 4 columns in the "heroes" table * * @Then (I )should see :count column(s) in the :table table */ @@ -38,6 +44,8 @@ public function iShouldSeeColumnsInTheTable($count, $table) /** * Checks that the specified table contains the specified number of rows in its body + * Example: Then I should see 4 rows in the "hero_body" "heroes" table + * Example: And I should see 4 rows in the "hero_body" "heroes" table * * @Then (I )should see :count rows in the :index :table table */ @@ -49,6 +57,8 @@ public function iShouldSeeRowsInTheNthTable($count, $index, $table) /** * Checks that the specified table contains the specified number of rows in its body + * Example: Then I should see 500 rows in the "heroes" table + * Example: And I should see 500 rows in the "heroes" table * * @Then (I )should see :count row(s) in the :table table */ @@ -59,6 +69,10 @@ public function iShouldSeeRowsInTheTable($count, $table) /** * Checks that the data of the specified row matches the given schema + * Example: Then the data in the 4th row of the "heroes" table should match: + * | 1 | Batman | Bruce Wayne | + * Example: And the data in the 4th row of the "heroes" table should match: + * | 1 | Batman | Bruce Wayne | * * @Then the data in the :index row of the :table table should match: */ @@ -87,6 +101,8 @@ public function theDataOfTheRowShouldMatch($index, $table, TableNode $text) /** * Checks that the specified cell (column/row) of the table's body contains the specified text + * Example: Then the 1st column of the 4th row in the "heroes" table should contain "Aquaman" + * Example: Then the 1st column of the 5th row in the "heroes" table should contain "Wonder Woman" * * @Then the :colIndex column of the :rowIndex row in the :table table should contain :text */ diff --git a/src/Context/XmlContext.php b/src/Context/XmlContext.php index d94d293c..e999dccf 100644 --- a/src/Context/XmlContext.php +++ b/src/Context/XmlContext.php @@ -9,6 +9,8 @@ class XmlContext extends BaseContext { /** * Checks that the response is correct XML + * Example: Then the response should be in XML + * Example: And the response should be in XML * * @Then the response should be in XML */ @@ -19,6 +21,8 @@ public function theResponseShouldBeInXml() /** * Checks that the response is not correct XML + * Example: Then the response should not be in XML + * Example: And the response should not be in XML * * @Then the response should not be in XML */ @@ -32,6 +36,8 @@ public function theResponseShouldNotBeInXml() /** * Checks that the specified XML element exists + * Example: Then the XML element "Vehicles" should exist + * Example: And the XML element "Vehicles" should exist * * @param string $element * @throws \Exception @@ -53,6 +59,8 @@ public function theXmlElementShouldExist($element) /** * Checks that the specified XML element does not exist + * Example: Then the XML element "Suits" should not exist + * Example: And the XML element "Suits" should exist * * @Then the XML element :element should not exist(s) */ @@ -65,6 +73,8 @@ public function theXmlElementShouldNotExist($element) /** * Checks that the specified XML element is equal to the given value + * Example: Then the XML element "Vehicles" should be equal to "Batmobile, Batwing, Batboat, Battank" + * Example: And the XML element "Vehicles" should be equal to "Batmobile, Batwing, Batboat, Battank" * * @Then the XML element :element should be equal to :text */ @@ -81,6 +91,8 @@ public function theXmlElementShouldBeEqualTo($element, $text) /** * Checks that the specified XML element is not equal to the given value + * Example: Then the XML element "Suits" should not be equal to "Santiago's BatSuit" + * Example: And the XML element "Suits" should not be equal to "Santiago's BatSuit" * * @Then the XML element :element should not be equal to :text */ @@ -93,6 +105,8 @@ public function theXmlElementShouldNotBeEqualTo($element, $text) /** * Checks that the XML attribute on the specified element exists + * Example: Then the XML attribute "VehicleID" on element "Vehicles" should exist + * Example: And the XML attribute "VehicleID" on element "Vehicles" should exist * * @Then the XML attribute :attribute on element :element should exist(s) */ @@ -111,6 +125,8 @@ public function theXmlAttributeShouldExist($attribute, $element) /** * Checks that the XML attribute on the specified element does not exist + * Example: Then the XML attribute "VehicleID" on element "Vehicles" should not exist + * Example: And the XML attribute "VehicleID" on element "Vehicles" should not exist * * @Then the XML attribute :attribute on element :element should not exist(s) */ @@ -121,6 +137,8 @@ public function theXmlAttributeShouldNotExist($attribute, $element) /** * Checks that the XML attribute on the specified element is equal to the given value + * Example: Then the XML attribute "VehicleName" on element "Vehicles" should be equal to "Batmobile" + * Example: And the XML attribute "VehicleName" on element "Vehicles" should be equal to "Batmobile" * * @Then the XML attribute :attribute on element :element should be equal to :text */ @@ -135,6 +153,8 @@ public function theXmlAttributeShouldBeEqualTo($attribute, $element, $text) /** * Checks that the XML attribute on the specified element is not equal to the given value + * Example: Then the XML attribute "SuitOwner" on element "Suits" should not be equal to "David Zavimbe" + * Example: And the XML attribute "SuitOwner" on element "Suits" should not be equal to "David Zavimbe" * * @Then the XML attribute :attribute on element :element should not be equal to :text */ @@ -149,6 +169,8 @@ public function theXmlAttributeShouldNotBeEqualTo($attribute, $element, $text) /** * Checks that the given XML element has N child element(s) + * Example: Then the XML element "Vehicles" should have "6" elements + * Example: And the XML element "Vehicles" should have "6" elements * * @Then the XML element :element should have :count element(s) */ @@ -168,6 +190,8 @@ public function theXmlElementShouldHaveNChildElements($element, $count) /** * Checks that the given XML element contains the given value + * Example: Then the XML element "VehicleName" should contain "Batmobile" + * Example: And the XML element "VehicleName" should contain "Batmobile" * * @Then the XML element :element should contain :text */ @@ -180,6 +204,8 @@ public function theXmlElementShouldContain($element, $text) /** * Checks that the given XML element does not contain the given value + * Example: Then the XML element "VehicleName" should not contain "Batsub" + * Example: And the XML element "VehicleName" should not contain "Batsub" * * @Then the XML element :element should not contain :text */ @@ -192,6 +218,8 @@ public function theXmlElementShouldNotContain($element, $text) /** * Checks that the XML uses the specified namespace + * Example: Then the XML should use the namespace "Batman" + * Example: And the XML should use the namespace "Batman" * * @Then the XML should use the namespace :namespace */ @@ -207,6 +235,8 @@ public function theXmlShouldUseTheNamespace($namespace) /** * Checks that the XML does not use the specified namespace + * Example: Then the XML should not use the namespace "Robin" + * Example: And the XML should not use the namespace "Robin" * * @Then the XML should not use the namespace :namespace */ @@ -222,6 +252,7 @@ public function theXmlShouldNotUseTheNamespace($namespace) /** * Optimistically (ignoring errors) attempt to pretty-print the last XML response + * Example: Then print last XML response * * @Then print last XML response */ @@ -240,6 +271,10 @@ public function beforeScenario() } /** + * Checks validity of XML against a DTD + * Example: Then the XML feed should be valid according to its DTD + * Example: And the XML feed should be valid according to its DTD + * * @Then the XML feed should be valid according to its DTD */ public function theXmlFeedShouldBeValidAccordingToItsDtd() @@ -253,6 +288,10 @@ public function theXmlFeedShouldBeValidAccordingToItsDtd() } /** + * Checks validity of XML against a provided XSD + * Example: Then the XML feed should be valid according to the XSD "batman.xsd" + * Example: And the XML feed should be valid according to the XSD "batman.xsd" + * * @Then the XML feed should be valid according to the XSD :filename */ public function theXmlFeedShouldBeValidAccordingToTheXsd($filename) @@ -268,6 +307,44 @@ public function theXmlFeedShouldBeValidAccordingToTheXsd($filename) } /** + * Checks validity of XML against a provided XSD + * Example: Then the XML feed should be valid according to this XSD: + * """ + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * """ + * Example: And the XML feed should be valid according to this XSD: + * """ + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * """ + * * @Then the XML feed should be valid according to this XSD: */ public function theXmlFeedShouldBeValidAccordingToThisXsd(PyStringNode $xsd) @@ -277,6 +354,10 @@ public function theXmlFeedShouldBeValidAccordingToThisXsd(PyStringNode $xsd) } /** + * Checks validity of XML against a provided RELAX NG Schema + * Example: Then the XML feed should be valid according to the relax NG schema "batman.xsd" + * Example: And the XML feed should be valid according to the relax NG schema "batman.xsd" + * * @Then the XML feed should be valid according to the relax NG schema :filename */ public function theXmlFeedShouldBeValidAccordingToTheRelaxNgSchema($filename) @@ -292,6 +373,28 @@ public function theXmlFeedShouldBeValidAccordingToTheRelaxNgSchema($filename) } /** + * Checks validity of XML against a provided RELAX NG Schema + * Example: Then the XML feed should be valid according to this relax NG schema: + * """ + * + * + * + * + * + * + * + * """ + * Example: And the XML feed should be valid according to this relax NG schema: + * """ + * + * + * + * + * + * + * + * """ + * * @Then the XML feed should be valid according to this relax NG schema: */ public function theXmlFeedShouldBeValidAccordingToThisRelaxNgSchema(PyStringNode $ng) @@ -301,6 +404,9 @@ public function theXmlFeedShouldBeValidAccordingToThisRelaxNgSchema(PyStringNode } /** + * Checks the validity of the atom XML feed + * Example: Then the atom feed should be valid + * * @Then the atom feed should be valid */ public function theAtomFeedShouldBeValid() @@ -311,6 +417,9 @@ public function theAtomFeedShouldBeValid() } /** + * Checks the validity of the RSS2 feed + * Example: Then the RSS2 feed should be valid + * * @Then the RSS2 feed should be valid */ public function theRss2FeedShouldBeValid() From dcddbb4fddbf6e3fa9af4212d6642b7ef474e31e Mon Sep 17 00:00:00 2001 From: Sajjad Hossain Date: Mon, 1 Jun 2015 15:17:12 -0400 Subject: [PATCH 2/5] added addtional documents, added examples to all step definitions for additional clarity when running 'behat -di' or 'behat -dl' --- src/Context/RestContext.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Context/RestContext.php b/src/Context/RestContext.php index d1c9d2b4..2a40c90e 100644 --- a/src/Context/RestContext.php +++ b/src/Context/RestContext.php @@ -5,7 +5,6 @@ use Behat\Gherkin\Node\TableNode; use Sanpi\Behatch\HttpCall\Request; use Behat\Gherkin\Node\PyStringNode; -use Buzz\Browser; class RestContext extends BaseContext { From ee4919e06121f93a9c5e33ba01be846ed8cb7958 Mon Sep 17 00:00:00 2001 From: Sajjad Hossain Date: Mon, 1 Jun 2015 16:37:12 -0400 Subject: [PATCH 3/5] removed hardcoded url Oops, added hardcoded url possibly causing tests to fail --- src/Context/BrowserContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Context/BrowserContext.php b/src/Context/BrowserContext.php index f73a47cf..ec6f0347 100644 --- a/src/Context/BrowserContext.php +++ b/src/Context/BrowserContext.php @@ -138,7 +138,7 @@ public function iSetBasicAuthenticationWithAnd($user, $password) */ public function iAmOnUrlComposedBy(TableNode $tableNode) { - $url = 'http://adcade.com/'; + $url = ''; foreach ($tableNode->getHash() as $hash) { $url .= $hash['parameters']; } From b8504246b16c74ad0136bb8a75de78501ebfe2b4 Mon Sep 17 00:00:00 2001 From: Sajjad Hossain Date: Mon, 8 Jun 2015 17:12:17 -0400 Subject: [PATCH 4/5] added tests to browser.feature for new step definitions, modified all examples and desc to match requirements set forth by MinkExtension PR --- src/Context/BrowserContext.php | 13 ------------- src/Context/JsonContext.php | 2 -- src/Context/SystemContext.php | 12 +----------- src/Context/XmlContext.php | 4 ---- tests/features/browser.feature | 21 ++++++++++++++++++--- 5 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/Context/BrowserContext.php b/src/Context/BrowserContext.php index f73a47cf..fff613ed 100644 --- a/src/Context/BrowserContext.php +++ b/src/Context/BrowserContext.php @@ -32,8 +32,6 @@ public function closeBrowser() $this->getSession()->stop(); } - //Window sizes for Mac and Windows - /** * Sets browser window to custom size * Example: Given I set browser window size to "1900" x "1200" @@ -98,8 +96,6 @@ public function iSetMyBrowserWindowSizeToWindowsStandard() $this->getSession()->getDriver()->resizeWindow((int)'1280', (int)'1280', 'current'); } - //HTTP Authentication - /** * Set login / password for next HTTP authentication * Example: Given I set authentication with "bwayne" and "iLoveBats" @@ -249,7 +245,6 @@ public function iScrollToTop() { /** * Scroll to a certain element by label. * Requires an "id" attribute to uniquely identify the element in the document. - * * Example: Given I scroll to the "Submit" button * Example: Given I scroll to the "My Date" field * @@ -392,7 +387,6 @@ public function iSaveTheValueOfInTheParameter($field, $parameter) /** * Checks, that the page should contains specified text after given timeout - * Example: Given I wait 3 seconds until I see "Hello, Bruce Wayne" * Example: When I wait 3 seconds until I see "Hello, Bruce Wayne" * Example: And I wait 3 seconds until I see "Hello, Bruce Wayne" * @@ -405,7 +399,6 @@ public function iWaitSecondsUntilISee($count, $text) /** * Checks, that the page should contains specified text after timeout - * Example: Given I wait until I see "Hello, Bruce Wayne" * Example: When I wait until I see "Hello, Bruce Wayne" * Example: And I wait until I see "Hello, Bruce Wayne" * @@ -418,7 +411,6 @@ public function iWaitUntilISee($text) /** * Checks, that the element contains specified text after timeout - * Example: Given I wait 3 seconds until I see "Hello, Bruce Wayne" in the "nav" element * Example: When I wait 3 seconds until I see "Hello, Bruce Wayne" in the "nav" element * Example: And I wait 3 seconds until I see "Hello, Bruce Wayne" in the "nav" element * @@ -438,7 +430,6 @@ public function iWaitSecondsUntilISeeInTheElement($count, $text, $element) /** * Checks, that the element contains specified text after timeout - * Example: Given I wait until I see "Hello, Bruce Wayne" in the "nav" element * Example: When I wait until I see "Hello, Bruce Wayne" in the "nav" element * Example: And I wait until I see "Hello, Bruce Wayne" in the "nav" element * @@ -451,7 +442,6 @@ public function iWaitUntilISeeInTheElement($text, $element) /** * Wait for a element - * Example: Given I wait 1 second for "sign-up" element * Example: When I wait 2 seconds for "sign-up" element * Example: And I wait 3 seconds for "sign-up" element * @@ -482,7 +472,6 @@ public function iWaitSecondsForElement($count, $element) /** * Checks, that the page should contains specified element after timeout - * Example: Given I wait for "sign-up" element * Example: When I wait for "sign-up" element * Example: And I wait for "sign-up" element * @@ -495,7 +484,6 @@ public function iWaitForElement($element) /** * Waits seconds - * Example: Given I wait 1 second * Example: When I wait 2 second * Example: And I wait 3 seconds * @@ -509,7 +497,6 @@ public function iWaitSeconds($count) /** * Waits seconds - * Example: Given I wait for 10 seconds * Example: When I wait for 9 seconds * Example: And I wait for 8 seconds * diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index 13bc8f0d..367665c4 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -118,7 +118,6 @@ public function theJsonNodeShouldNotContain($node, $text) /** * Checks, that given JSON node exist - * Example: Given the JSON node "id" should exist * Example: Then the JSON node "id" should exist * Example: And the JSON node "id" should exist * @@ -139,7 +138,6 @@ public function theJsonNodeShouldExist($name) /** * Checks, that given JSON node does not exist - * Example: Given the JSON node "Robin" should not exist * Example: Then the JSON node "Robin" should not exist * Example: And the JSON node "Robin" should not exist * diff --git a/src/Context/SystemContext.php b/src/Context/SystemContext.php index e8dca9d0..edf4036f 100644 --- a/src/Context/SystemContext.php +++ b/src/Context/SystemContext.php @@ -24,6 +24,7 @@ public static function getTranslationResources() /** * Changes directory to :directory requested * Example: Given I am in "/Users/bWayne/secretfiles/batman" + * Example: When I am in "/Users/bWayne/secretfiles/batman" * Example: And I am in "/Users/bWayne/secretfiles/batman" * * @Given I am in :dir directory @@ -51,7 +52,6 @@ public function iRun($command) /** * Uploads a file using the specified input field - * Example: Given I put the file "batman_profile.jpg" into "heroImage" * Example: When I put the file "batman_profile.jpg" into "heroImage" * Example: And I put the file "batman_profile.jpg" into "heroImage" * @@ -68,7 +68,6 @@ public function putFileIntoField($file, $field) /** * Execute a command - * Example: Given I execute "pwd" * Example: When I execute "pwd" * Example: And I execute "pwd" * @@ -85,7 +84,6 @@ public function iExecute($cmd) /** * Execute a command from project root - * Example: Given I execute "php ./openBatCave.php" from project root * Example: When I execute "php ./openBatCave.php" from project root * Example: And I execute "php ./openBatCave.php" from project root * @@ -99,13 +97,6 @@ public function iExecuteFromProjectRoot($cmd) /** * Creates a file via touch command - * Example: Given I create the file "batmansPasswords.txt" containing" - * """ - * Facebook: RIPMarthaThomas1927 - * Twitter: RIPTimothyDrake1986 - * Netflix: RIPDamianWayne2009 - * Google: DamnIveSeenSomeStuff - * """ * Example: When I create the file "batmansPasswords.txt" containing" * """ * Facebook: RIPMarthaThomas1927 @@ -136,7 +127,6 @@ public function iCreateTheFileContaining($filename, PyStringNode $string) /** * Prints the content of passed file - * Example: Given I print the content of "./batmansGreatestSecrets.txt" file * Example: When I print the content of "./batmansGreatestSecrets.txt" file * Example: Then I print the content of "./batmansGreatestSecrets.txt" file * diff --git a/src/Context/XmlContext.php b/src/Context/XmlContext.php index e999dccf..1f016319 100644 --- a/src/Context/XmlContext.php +++ b/src/Context/XmlContext.php @@ -23,7 +23,6 @@ public function theResponseShouldBeInXml() * Checks that the response is not correct XML * Example: Then the response should not be in XML * Example: And the response should not be in XML - * * @Then the response should not be in XML */ public function theResponseShouldNotBeInXml() @@ -38,11 +37,9 @@ public function theResponseShouldNotBeInXml() * Checks that the specified XML element exists * Example: Then the XML element "Vehicles" should exist * Example: And the XML element "Vehicles" should exist - * * @param string $element * @throws \Exception * @return \DomNodeList - * * @Then the XML element :element should exist(s) */ public function theXmlElementShouldExist($element) @@ -61,7 +58,6 @@ public function theXmlElementShouldExist($element) * Checks that the specified XML element does not exist * Example: Then the XML element "Suits" should not exist * Example: And the XML element "Suits" should exist - * * @Then the XML element :element should not exist(s) */ public function theXmlElementShouldNotExist($element) diff --git a/tests/features/browser.feature b/tests/features/browser.feature index 2908bb98..dae34386 100644 --- a/tests/features/browser.feature +++ b/tests/features/browser.feature @@ -1,8 +1,8 @@ Feature: Browser Feature - # If this scenari fails + # If this scenario fails # It's probably because your web environment is not properly setup - # You will find the necessery help in README.md + # You will find the necessary help in README.md @javascript Scenario: Testing simple web access Given I am on "/index.html" @@ -78,4 +78,19 @@ Feature: Browser Feature Scenario: Given I am on "/browser/elements.html" - Then i save the value of "today" in the "today" parameter + Then I save the value of "today" in the "today" parameter + + Scenario: Regression for new step definitions added by sajjadhossain on 6/5/15 + Given I am on "/" + And I am on a new session + And I set my browser window size to 15 inch MacBook Retina + And I set my browser window size to "500" x "500" + When I go to "https://github.com/Behatch/contexts" + And I scroll to the bottom + And I scroll to the top + When I go to "http://www.javascripter.net/faq/alert.htm" + And I press "Try it now" + And I confirm the popup + Then I should see "Alert: Modal Message Box" + + From dc5a0c583b33ad704bca29ad2ea11e94f472c2b0 Mon Sep 17 00:00:00 2001 From: Sajjad Hossain Date: Mon, 8 Jun 2015 17:18:08 -0400 Subject: [PATCH 5/5] removed other instances of improper Given use --- src/Context/BrowserContext.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Context/BrowserContext.php b/src/Context/BrowserContext.php index d4574db4..7058de76 100644 --- a/src/Context/BrowserContext.php +++ b/src/Context/BrowserContext.php @@ -34,7 +34,6 @@ public function closeBrowser() /** * Sets browser window to custom size - * Example: Given I set browser window size to "1900" x "1200" * Example: When I set browser window size to "800" x "400" * Example: And I set browser window size to "2880" x "1800" * @@ -46,7 +45,6 @@ public function iSetMyBrowserWindowSizeToX($width, $height) { } /** * Sets browser window to 1440 by 900 - * Example: Given I set my browser window size to MacBook Standard * Example: When I set my browser window size to MacBook Standard * Example: And I set my browser window size to MacBook Standard * @@ -59,7 +57,6 @@ public function iSetMyBrowserWindowSizeToMacbookStandard() /** * Sets browser window to 2880 by 1800 - * Example: Given I set my browser window size to 15 inch MacBook Retina * Example: When I set my browser window size to 15 inch MacBook Retina * Example: And I set my browser window size to 15 inch MacBook Retina * @@ -72,7 +69,6 @@ public function iSetMyBrowserWindowSizeTo15InchMacbookRetina() /** * Sets browser window to 2560 by 1600 - * Example: Given I set my browser window size to 13 inch MacBook Retina * Example: When I set my browser window size to 13 inch MacBook Retina * Example: And I set my browser window size to 13 inch MacBook Retina * @@ -85,7 +81,6 @@ public function iSetMyBrowserWindowSizeTo13InchMacbookRetina() /** * Sets browser window to 1280 by 1280 - * Example: Given I set my browser window size to Windows Standard * Example: When I set my browser window size to Windows Standard * Example: And I set my browser window size to Windows Standard * @@ -98,7 +93,6 @@ public function iSetMyBrowserWindowSizeToWindowsStandard() /** * Set login / password for next HTTP authentication - * Example: Given I set authentication with "bwayne" and "iLoveBats" * Example: When I set authentication with "bwayne" and "iLoveBats" * Example: And I set authentication with "bwayne" and "iLoveBats" * @@ -219,7 +213,6 @@ public function setPopupText($message) /** * Scrolls to the bottom of the given page - * Example: Given I scroll to the bottom * Example: When I scroll to the bottom * Example: And I scroll to the bottom * @@ -232,7 +225,6 @@ public function iScrollToBottom() { /** * Scrolls to the top of the given page - * Example: Given I scroll to the top * Example: When I scroll to the top * Example: And I scroll to the top *