|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Magento\Navigators; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Facebook\WebDriver\WebDriverElement; |
|
7
|
|
|
use Magium\Actions\WaitForPageLoaded; |
|
8
|
|
|
use Magium\Magento\Themes\NavigableThemeInterface; |
|
9
|
|
|
use Magium\Util\Log\Logger; |
|
10
|
|
|
use Magium\WebDriver\ExpectedCondition; |
|
11
|
|
|
use Magium\WebDriver\WebDriver; |
|
12
|
|
|
|
|
13
|
|
|
class BaseMenu |
|
14
|
|
|
{ |
|
15
|
|
|
const NAVIGATOR = 'BaseMenu'; |
|
16
|
|
|
protected $webdriver; |
|
17
|
|
|
protected $themeConfiguration; |
|
18
|
|
|
protected $loaded; |
|
19
|
|
|
protected $logger; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct( |
|
22
|
|
|
NavigableThemeInterface $theme, |
|
23
|
|
|
WebDriver $webdriver, |
|
24
|
|
|
WaitForPageLoaded $loaded, |
|
25
|
|
|
Logger $logger |
|
26
|
|
|
) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->themeConfiguration = $theme; |
|
29
|
|
|
$this->webdriver = $webdriver; |
|
30
|
|
|
$this->loaded = $loaded; |
|
31
|
|
|
$this->logger = $logger; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function pathAction($path) |
|
35
|
|
|
{ |
|
36
|
|
|
$xpath = $this->themeConfiguration->getNavigationBaseXPathSelector(); |
|
37
|
|
|
usleep(500000); // Give the UI some time to update |
|
38
|
|
|
$xpath .= '/descendant::' . $this->themeConfiguration->getNavigationChildXPathSelector($path); |
|
39
|
|
|
|
|
40
|
|
|
$element = $this->webdriver->byXpath($xpath . '/a'); |
|
41
|
|
|
|
|
42
|
|
|
$this->execute($element); |
|
43
|
|
|
|
|
44
|
|
|
return $element; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function execute(WebDriverElement $element) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->webdriver->getMouse()->mouseMove($element->getCoordinates()); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function navigateTo($path) |
|
53
|
|
|
{ |
|
54
|
|
|
$paths = explode('/', $path); |
|
55
|
|
|
$xpath = $this->themeConfiguration->getNavigationBaseXPathSelector(); |
|
56
|
|
|
|
|
57
|
|
|
$this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($xpath))); |
|
58
|
|
|
|
|
59
|
|
|
$element = null; |
|
60
|
|
|
|
|
61
|
|
|
foreach ($paths as $p) { |
|
62
|
|
|
$element = $this->pathAction($p); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($element instanceof WebDriverElement) { |
|
66
|
|
|
$element->click(); |
|
67
|
|
|
$this->loaded->execute($element); |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: