|
16 | 16 | */ |
17 | 17 | trait WaitContext |
18 | 18 | { |
19 | | - private const DEFAULT_TIMEOUT_MS = 10000; |
| 19 | + private const DEFAULT_TIMEOUT_MS = 12000; |
20 | 20 | private const DEFAULT_POLL_INTERVAL_MS = 100; |
21 | 21 |
|
22 | 22 | /** |
@@ -69,6 +69,42 @@ public function pressButtonAndWaitToSee(string $button, string $text, ?string $t |
69 | 69 | $this->waitToSeeText($text, $timeout); |
70 | 70 | } |
71 | 71 |
|
| 72 | + #[When('/^I follow the button of tooltip "(?P<tooltip>[^"]*)" and wait until I see "(?P<text>[^"]*)"(?:| within (?P<timeout>\d+)ms)$/')] |
| 73 | + public function clickLinkOfTooltipAndWaitToSee(string $tooltip, string $text, ?string $timeout = null): void |
| 74 | + { |
| 75 | + $link = $this->minkContext->getSession()->getPage()->find('css', sprintf('a[data-tooltip="%s"]', $tooltip)); |
| 76 | + |
| 77 | + if (null === $link) { |
| 78 | + throw new ExpectationException( |
| 79 | + sprintf('Link of tooltip "%s" not found', $tooltip), |
| 80 | + $this->minkContext->getSession()->getDriver(), |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + $session = $this->minkContext->getSession(); |
| 85 | + |
| 86 | + if ($session->getDriver() instanceof \Behat\Mink\Driver\PantherDriver) { |
| 87 | + $href = $link->getAttribute('href'); |
| 88 | + $session->executeScript(sprintf('window.location.href = %s;', json_encode($href))); |
| 89 | + |
| 90 | + $timeoutMs = $timeout !== null ? (int) $timeout : self::DEFAULT_TIMEOUT_MS; |
| 91 | + $this->waitForCondition( |
| 92 | + fn() => str_contains($session->getPage()->getContent(), $text), |
| 93 | + sprintf( |
| 94 | + 'Text "%s" did not appear within %dms. Current URL: %s. Page excerpt: %s', |
| 95 | + $text, |
| 96 | + $timeoutMs, |
| 97 | + $session->getCurrentUrl(), |
| 98 | + substr(strip_tags($session->getPage()->getContent()), 0, 500), |
| 99 | + ), |
| 100 | + $timeoutMs, |
| 101 | + ); |
| 102 | + } else { |
| 103 | + $link->click(); |
| 104 | + $this->waitToSeeText($text, $timeout); |
| 105 | + } |
| 106 | + } |
| 107 | + |
72 | 108 | /** |
73 | 109 | * Generic wait-for-condition method that polls until timeout. |
74 | 110 | * |
|
0 commit comments