Skip to content

Commit

Permalink
Merge branch '4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon committed Oct 6, 2023
2 parents ab2b05e + bb9ab51 commit 706a5be
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/lib/Browser/Element/Action/ActionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Behat\Browser\Element\Action;

use Ibexa\Behat\Browser\Element\ElementInterface;

interface ActionInterface
{
public function execute(ElementInterface $element): void;
}
29 changes: 29 additions & 0 deletions src/lib/Browser/Element/Action/ChainAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Behat\Browser\Element\Action;

use Ibexa\Behat\Browser\Element\ElementInterface;

class ChainAction implements ActionInterface
{
/** @var ActionInterface[] */
private array $actions;

public function __construct(array $actions)
{
$this->actions = $actions;
}

public function execute(ElementInterface $element): void
{
foreach ($this->actions as $action) {
$action->execute($element);
}
}
}
19 changes: 19 additions & 0 deletions src/lib/Browser/Element/Action/Click.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Behat\Browser\Element\Action;

use Ibexa\Behat\Browser\Element\ElementInterface;

class Click implements ActionInterface
{
public function execute(ElementInterface $element): void
{
$element->click();
}
}
19 changes: 19 additions & 0 deletions src/lib/Browser/Element/Action/MouseOver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Behat\Browser\Element\Action;

use Ibexa\Behat\Browser\Element\ElementInterface;

class MouseOver implements ActionInterface
{
public function execute(ElementInterface $element): void
{
$element->mouseOver();
}
}
24 changes: 24 additions & 0 deletions src/lib/Browser/Element/Action/MouseOverAndClick.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Behat\Browser\Element\Action;

use Ibexa\Behat\Browser\Element\ElementInterface;

class MouseOverAndClick implements ActionInterface
{
public function execute(ElementInterface $element): void
{
$action = new ChainAction([
new MouseOver(),
new Wait(50),
new Click(),
]);
$action->execute($element);
}
}
26 changes: 26 additions & 0 deletions src/lib/Browser/Element/Action/Wait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Behat\Browser\Element\Action;

use Ibexa\Behat\Browser\Element\ElementInterface;

class Wait implements ActionInterface
{
private int $timeMilliseconds;

public function __construct(int $timeMilliseconds)
{
$this->timeMilliseconds = $timeMilliseconds;
}

public function execute(ElementInterface $element): void
{
usleep(100 * $this->timeMilliseconds);
}
}
6 changes: 6 additions & 0 deletions src/lib/Browser/Element/Debug/Highlighting/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Behat\Mink\Session;
use Ibexa\Behat\Browser\Assert\ElementAssertInterface;
use Ibexa\Behat\Browser\Element\Action\ActionInterface;
use Ibexa\Behat\Browser\Element\ElementInterface;

final class Element extends BaseElement implements ElementInterface
Expand Down Expand Up @@ -105,4 +106,9 @@ public function scrollToBottom(Session $session): void
{
$this->element->scrollToBottom($session);
}

public function execute(ActionInterface $action): void
{
$this->element->execute($action);
}
}
6 changes: 6 additions & 0 deletions src/lib/Browser/Element/Debug/Interactive/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Exception;
use Ibexa\Behat\Browser\Assert\Debug\Interactive\ElementAssert as InteractiveElementAssert;
use Ibexa\Behat\Browser\Assert\ElementAssertInterface;
use Ibexa\Behat\Browser\Element\Action\ActionInterface;
use Ibexa\Behat\Browser\Element\ElementInterface;
use Ibexa\Behat\Core\Debug\InteractiveDebuggerTrait;

Expand Down Expand Up @@ -112,4 +113,9 @@ public function scrollToBottom(Session $session): void
{
$this->element->scrollToBottom($session);
}

public function execute(ActionInterface $action): void
{
$this->element->execute($action);
}
}
14 changes: 10 additions & 4 deletions src/lib/Browser/Element/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

use Behat\Mink\Element\NodeElement;
use Behat\Mink\Session;
use Facebook\WebDriver\Exception\NoSuchElementException;
use Facebook\WebDriver\Exception\StaleElementReferenceException;
use Ibexa\Behat\Browser\Assert\ElementAssert;
use Ibexa\Behat\Browser\Assert\ElementAssertInterface;
use Ibexa\Behat\Browser\Element\Action\ActionInterface;
use Ibexa\Behat\Browser\Element\Factory\ElementFactoryInterface;
use Ibexa\Behat\Browser\Locator\LocatorInterface;
use Webdriver\Exception\NoSuchElement;
use WebDriver\Exception\StaleElementReference;

final class Element extends BaseElement implements ElementInterface
{
Expand All @@ -33,9 +34,9 @@ public function isVisible(): bool
{
try {
return $this->decoratedElement->isVisible();
} catch (StaleElementReference $e) {
} catch (NoSuchElementException $element) {
return false;
} catch (NoSuchElement $element) {
} catch (StaleElementReferenceException $e) {
return false;
}
}
Expand Down Expand Up @@ -147,4 +148,9 @@ protected function isRadioGroup(): bool
{
return $this->decoratedElement->hasAttribute('type') && 'radio' === $this->decoratedElement->getAttribute('type');
}

public function execute(ActionInterface $action): void
{
$action->execute($this);
}
}
3 changes: 3 additions & 0 deletions src/lib/Browser/Element/ElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Behat\Mink\Session;
use Ibexa\Behat\Browser\Assert\ElementAssertInterface;
use Ibexa\Behat\Browser\Element\Action\ActionInterface;

interface ElementInterface extends BaseElementInterface
{
Expand Down Expand Up @@ -46,4 +47,6 @@ public function selectOption(string $option): void;
public function getXPath(): string;

public function scrollToBottom(Session $session): void;

public function execute(ActionInterface $action): void;
}

0 comments on commit 706a5be

Please sign in to comment.