edmondscommerce/behat-html-context

0.0.1 2018-03-14 15:11 UTC

This package is auto-updated.

Last update: 2024-11-09 01:08:11 UTC


README

By Edmonds Commerce

Codacy Badge

A simple Behat Context for working with HTML and navigation

Installation

Install via composer

"edmondscommerce/behat-html-context": "0.0.1"

Include Context in Behat Configuration

default:
    # ...
    suites:
        default:
            # ...
            contexts:
                - # ...
                - EdmondsCommerce\BehatHtmlContext\HTMLContext
                - EdmondsCommerce\BehatHtmlContext\RedirectionContext

EdmondsCommerce\BehatHtmlContext\RedirectionContext is no longer supported and marked as deprecated.

Helper Methods

You will need to load the HTML context as part of your own suite of contexts using @BeforeScenario to access the helper methods

All helpers accept a custom message to use with the exception

// Instantiate context class, 
$args = [
    'args' => [
        '--disable-gpu',
        '--window-size=1920,1080',
        '--start-maximised',
    ],
];

$driver = new Selenium2Driver('chrome', $args);
$session = new Behat\Mink\Session($driver);
$mink = new Mink(['selenium2' => $session]);

$htmlContext = new HTMLContext();
$htmlContext->setMink($mink);

//Find a node and return it or throw an exception
$htmlContext->findOneOrFail($selector, $locator, $message = null)

//Find multiple nodes and return an array of them or throw an exception if none are found
$htmlContext->findAllOrFail($selector, $locator, $message = null)

//Same as findOrFail but searches from the context of another node, can be useful for chaining
$htmlContext->findOrFailFromNode(\Behat\Mink\Element\NodeElement $element, $selector, $locator, $message = null)

Developer dependencies

edmondscommerce/phpqa

Simple PHP QA pipeline and scripts, that helps achieving high quality of code. Click here for more details.

edmondscommerce/mock-server

PHP Built-in web server. Click here for more details.

behat/mink-goutte-driver

Goutte driver. Click here for more details.

behat/mink-selenium2-driver

Selenium2 driver. Click here for more details.