[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/behat/ -> behat_base.php (summary)

Base class of all steps definitions. This script is only called from Behat as part of it's integration in Moodle.

Copyright: 2012 David Monllaó
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 866 lines (36 kb)
Included or required: 44 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

behat_base:: (22 methods):
  locate_path()
  find()
  find_all()
  __call()
  escape()
  spin()
  get_selected_node()
  get_text_selector_node()
  get_node_in_container()
  transform_selector()
  transform_text_selector()
  running_javascript()
  ensure_element_exists()
  ensure_element_does_not_exist()
  ensure_node_is_visible()
  ensure_element_is_visible()
  ensure_editors_are_loaded()
  resize_window()
  wait_for_pending_js()
  look_for_exceptions()
  get_debug_text()
  execute()


Class: behat_base  - X-Ref

Steps definitions base class.

To extend by the steps definitions of the different Moodle components.

It can not contain steps definitions to avoid duplicates, only utility
methods shared between steps.

locate_path($path)   X-Ref
Locates url, based on provided path.
Override to provide custom routing mechanism.

param: string $path
return: string

find($selector, $locator, $exception = false, $node = false, $timeout = false)   X-Ref
Returns the first matching element.

param: string $selector The selector type (css, xpath, named...)
param: mixed $locator It depends on the $selector, can be the xpath, a name, a css locator...
param: Exception $exception Otherwise we throw exception with generic info
param: NodeElement $node Spins around certain DOM node instead of the whole page
param: int $timeout Forces a specific time out (in seconds).
return: NodeElement

find_all($selector, $locator, $exception = false, $node = false, $timeout = false)   X-Ref
Returns all matching elements.

Adapter to Behat\Mink\Element\Element::findAll() using the spin() method.

param: string $selector The selector type (css, xpath, named...)
param: mixed $locator It depends on the $selector, can be the xpath, a name, a css locator...
param: Exception $exception Otherwise we throw expcetion with generic info
param: NodeElement $node Spins around certain DOM node instead of the whole page
param: int $timeout Forces a specific time out (in seconds). If 0 is provided the default timeout will be applied.
return: array NodeElements list

__call($name, $arguments)   X-Ref
No description

escape($string)   X-Ref
Escapes the double quote character.

Double quote is the argument delimiter, it can be escaped
with a backslash, but we auto-remove this backslashes
before the step execution, this method is useful when using
arguments as arguments for other steps.

param: string $string
return: string

spin($lambda, $args = false, $timeout = false, $exception = false, $microsleep = false)   X-Ref
Executes the passed closure until returns true or time outs.

In most cases the document.readyState === 'complete' will be enough, but sometimes JS
requires more time to be completely loaded or an element to be visible or whatever is required to
perform some action on an element; this method receives a closure which should contain the
required statements to ensure the step definition actions and assertions have all their needs
satisfied and executes it until they are satisfied or it timeouts. Redirects the return of the
closure to the caller.

The closures requirements to work well with this spin method are:
- Must return false, null or '' if something goes wrong
- Must return something != false if finishes as expected, this will be the (mixed) value
returned by spin()

The arguments of the closure are mixed, use $args depending on your needs.

You can provide an exception to give more accurate feedback to tests writers, otherwise the
closure exception will be used, but you must provide an exception if the closure does not throw
an exception.

param: Function|array|string $lambda The function to execute or an array passed to call_user_func (maps to a class method)
param: mixed $args Arguments to pass to the closure
param: int $timeout Timeout in seconds
param: Exception $exception The exception to throw in case it time outs.
param: bool $microsleep If set to true it'll sleep micro seconds rather than seconds.
return: mixed The value returned by the closure

get_selected_node($selectortype, $element)   X-Ref
Gets a NodeElement based on the locator and selector type received as argument from steps definitions.

Use behat_base::get_text_selector_node() for text-based selectors.

param: string $selectortype
param: string $element
return: NodeElement

get_text_selector_node($selectortype, $element)   X-Ref
Gets a NodeElement based on the locator and selector type received as argument from steps definitions.

param: string $selectortype
param: string $element
return: NodeElement

get_node_in_container($selectortype, $element, $containerselectortype, $containerelement)   X-Ref
Gets the requested element inside the specified container.

param: mixed $selectortype The element selector type.
param: mixed $element The element locator.
param: mixed $containerselectortype The container selector type.
param: mixed $containerelement The container locator.
return: NodeElement

transform_selector($selectortype, $element)   X-Ref
Transforms from step definition's argument style to Mink format.

Mink has 3 different selectors css, xpath and named, where named
selectors includes link, button, field... to simplify and group multiple
steps in one we use the same interface, considering all link, buttons...
at the same level as css selectors and xpath; this method makes the
conversion from the arguments received by the steps to the selectors and locators
required to interact with Mink.

param: string $selectortype It can be css, xpath or any of the named selectors.
param: string $element The locator (or string) we are looking for.
return: array Contains the selector and the locator expected by Mink.

transform_text_selector($selectortype, $element)   X-Ref
Transforms from step definition's argument style to Mink format.

Delegates all the process to behat_base::transform_selector() checking
the provided $selectortype.

param: string $selectortype It can be css, xpath or any of the named selectors.
param: string $element The locator (or string) we are looking for.
return: array Contains the selector and the locator expected by Mink.

running_javascript()   X-Ref
Returns whether the scenario is running in a browser that can run Javascript or not.

return: boolean

ensure_element_exists($element, $selectortype)   X-Ref
Spins around an element until it exists

param: string $element
param: string $selectortype
return: void

ensure_element_does_not_exist($element, $selectortype)   X-Ref
No description

ensure_node_is_visible($node)   X-Ref
No description

ensure_element_is_visible($element, $selectortype)   X-Ref
No description

ensure_editors_are_loaded()   X-Ref
Ensures that all the page's editors are loaded.

return: void

resize_window($windowsize, $viewport = false)   X-Ref
Change browser window size.
- small: 640x480
- medium: 1024x768
- large: 2560x1600

param: string $windowsize size of window.
param: bool $viewport If true, changes viewport rather than window size

wait_for_pending_js()   X-Ref
Waits for all the JS to be loaded.

return: bool True or false depending whether all the JS is loaded or not.

look_for_exceptions()   X-Ref
Internal step definition to find exceptions, debugging() messages and PHP debug messages.

Part of behat_hooks class as is part of the testing framework, is auto-executed
after each step so no features will splicitly use it.


get_debug_text($html)   X-Ref
Converts HTML tags to line breaks to display the info in CLI

param: string $html
return: string

execute($contextapi, $params = array()   X-Ref
Helper function to execute api in a given context.

param: string $contextapi context in which api is defined.
param: array $params list of params to pass.



Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1