Skip to content

Commit

Permalink
Fix small tests errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jorikfon committed Jan 15, 2025
1 parent 403833e commit b59ae15
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tests/AdminCabinet/Lib/Traits/FormInteractionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ trait FormInteractionTrait
/**
* Wait timeout for dropdown menu to become visible (in seconds)
*/
private const DROPDOWN_MENU_TIMEOUT = 10;
private const int DROPDOWN_MENU_TIMEOUT = 10;

/**
* Additional delay after dropdown click before continuing (in milliseconds)
*/
private const DROPDOWN_CLICK_DELAY = 500;
private const int DROPDOWN_CLICK_DELAY = 500;

/**
* Form field types mapping
Expand Down Expand Up @@ -387,14 +387,13 @@ protected function selectDropdownItem(string $name, string $value, bool $skipIfN
// Click to open dropdown
$this->scrollIntoView($dropdown);
$dropdown->click();
usleep(self::DROPDOWN_CLICK_DELAY * 1000);

// Wait for dropdown menu to be visible
$this->waitForDropdownMenu();

// Select item from visible menu
$menuXpath = '//div[contains(@class, "menu") and contains(@class, "visible")]' .
'//div[contains(@class, "item") and (@data-value="%s" or normalize-space(text())="%s")]';
'//div[contains(@class, "item") and (@data-value="%s" or contains(normalize-space(text()),"%s"))]';

$menuXpath = sprintf($menuXpath, $value, $value);

Expand Down Expand Up @@ -441,15 +440,14 @@ protected function checkIfElementExistOnDropdownMenu(string $name, string $value
// Click to open dropdown
$this->scrollIntoView($dropdown);
$dropdown->click();
usleep(self::DROPDOWN_CLICK_DELAY * 1000);

// Wait for dropdown menu to be visible
$this->waitForDropdownMenu();

// Look for item by both data-value and text content
$menuXpath = sprintf(
'//div[contains(@class, "menu") and contains(@class, "visible")]' .
'//div[contains(@class, "item") and (@data-value="%s" or normalize-space(text())="%s")]',
'//div[contains(@class, "item") and (@data-value="%s" or contains(normalize-space(text()),"%s"))]',
$value,
$value
);
Expand Down Expand Up @@ -516,10 +514,11 @@ private function findDropdownAndCheckState(string $name, bool $skipIfNotExist):
/**
* Wait for dropdown menu to become visible
*
* @throws \Facebook\WebDriver\Exception\TimeoutException
* @throws \Facebook\WebDriver\Exception\TimeoutException|NoSuchElementException
*/
private function waitForDropdownMenu(): void
{
usleep(self::DROPDOWN_CLICK_DELAY * 1000);
self::$driver->wait(self::DROPDOWN_MENU_TIMEOUT)->until(
WebDriverExpectedCondition::visibilityOfElementLocated(
WebDriverBy::xpath('//div[contains(@class, "menu") and contains(@class, "visible")]')
Expand Down

0 comments on commit b59ae15

Please sign in to comment.