Skip to content

Commit

Permalink
Merge pull request #218 from aik099/waitfor-callback-arg-change
Browse files Browse the repository at this point in the history
Provide original, instead of wrapped, object for "waitFor" method callback
  • Loading branch information
aik099 committed Feb 16, 2024
2 parents b9196a7 + 71fe613 commit bab42e7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,7 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
...

### Changed
...
- The `WebElement::waitFor` method now provide `WebElement` class (or used subclass, like `AbstractElementContainer`, etc.) instance to the callback instead of a Mink's `NodeElement` class instance.
- The `Page::waitFor` method now provide `Page` class (or used subclass, like `TypifiedPage`, `BEMPage`, etc.) instance to the callback instead of a Mink's `DocumentElement` class instance.

### Fixed
...
Expand Down
7 changes: 6 additions & 1 deletion library/QATools/QATools/PageObject/TWrappedElement.php
Expand Up @@ -54,7 +54,12 @@ public function findAll($selector, $locator)
*/
public function waitFor($timeout, $callback)
{
return $this->_wrappedElement->waitFor($timeout, $callback);
$container = $this;
$wrapped_callback = function () use ($container, $callback) {
return call_user_func($callback, $container);
};

return $this->_wrappedElement->waitFor($timeout, $wrapped_callback);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/QATools/QATools/PageObject/Element/WebElementTest.php
Expand Up @@ -103,15 +103,19 @@ public function testFindAll()
*/
public function testWaitFor()
{
$element_inside_callback = null;
$element = $this->createElement();

$start = microtime(true);

$element->waitFor(1, function () {
$element->waitFor(1, function ($callback_element) use (&$element_inside_callback) {
$element_inside_callback = $callback_element;

return false;
});

$this->assertGreaterThanOrEqual(1, microtime(true) - $start);
$this->assertSame($element, $element_inside_callback, 'Incorrect element passed to the callback.');
$this->assertGreaterThanOrEqual(1, microtime(true) - $start, 'No waiting happened.');
}

public function testNonExistingMethodForwardingError()
Expand Down
19 changes: 19 additions & 0 deletions tests/QATools/QATools/PageObject/PageTest.php
Expand Up @@ -161,6 +161,25 @@ public function testOpened()
$this->assertEquals('OK', $this->page->opened());
}

/**
* @medium
*/
public function testWaitFor()
{
$page_inside_callback = null;

$start = microtime(true);

$this->page->waitFor(1, function ($callback_page) use (&$page_inside_callback) {
$page_inside_callback = $callback_page;

return false;
});

$this->assertSame($this->page, $page_inside_callback, 'Incorrect page passed to the callback.');
$this->assertGreaterThanOrEqual(1, microtime(true) - $start, 'No waiting happened.');
}

/**
* Creates an empty mocked url builder.
*
Expand Down

0 comments on commit bab42e7

Please sign in to comment.