0

I'm learning Mink, and want to find an API reference. I've dug into the Mink source code for answers, but am baffled.

The documentation gives examples of its use:

$session->getPage()->hasContent("bla");
$session->getPage()->find('css', 'title')->getText();

But nowhere in the source can I find these methods getPage, getText, find, hasContent. (Yet they seem to work).

Mink seems to make the most out of OOP patterns, and I'm obviously not bright enough to work out what on earth is going on! Can anyone give me a link to API reference, or help understanding where these methods are defined?

For example, I've been puzzling why this doesn't work:

$this->assertTrue($session->getPage()->find('css', 'title')->hasContent("Part of the page's Title"));

(I get the error Call to undefined method Behat\Mink\Element\NodeElement::hasContent())

But I can't find a glass called NodeElement, let alone what methods it has that I can use.

Jodes
  • 14,118
  • 26
  • 97
  • 156

3 Answers3

4

Well, never used Mink but the source is on github:

From https://github.com/minkphp/Mink/blob/master/src/Session.php:

/**
 * Returns page element.
 *
 * @return DocumentElement
 */
public function getPage()
{
    return $this->page;
}

Since getPage() returns a DocumentElement object, you can look at the DocumentElement class: https://github.com/minkphp/Mink/blob/master/src/Element/DocumentElement.php

Since DocumentElement extends TraversibleElement which extends Element, you'll eventually find the function find() in Element. This is where an IDE really helps you traverse the code base to find where the function called is actually located.

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
2

I hope I am referring to the same Mink. Check out the source code over at github.

For the getPage(), for instance, see this https://github.com/minkphp/Mink/blob/master/src/Session.php

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
2

First of all you should extend your FeatureContext class from MinkContext. MinkContext has lots of useful assert methods and methods which work with page elements. F.e.

$this-> assertElementContains('CSS_IDENTIFIER_EXAMPLE', 'Some text');

$this->fillField($field, $value);

Fills in form field with specified id|name|label|value.

The whole list of available methods check on GitHub MinkContext

Also here is a behat cheat sheet which shows basic info and methods which work with html elements.

Igor Lantushenko
  • 1,771
  • 10
  • 19