Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 1dfdeae

Browse files
committed
Add common interface for WebDriverNavigation classes to improve LSP
1 parent 9a9ab00 commit 1dfdeae

5 files changed

+52
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
1414
- Rename environment variable used to pass path to ChromeDriver executable from `webdriver.chrome.driver` to `WEBDRIVER_CHROME_DRIVER`. However the old one also still works to keep backward compatibility
1515
- If subdirectories in a path to screenshot destination does not exists (using `takeScreenshot()` or `takeElementScreenshot()` methods), they are automatically created.
1616
- When zip archive cannot be crated during file upload, throw exception instead of silently returning false.
17+
- `WebDriverNavigation` and `EventFiringWebDriverNavigation` now both implement new `WebDriverNavigationInterface`.
1718

1819
### Fixed
1920
- `WebDriverExpectedCondition::presenceOfElementLocated()` works correctly when used within `WebDriverExpectedCondition::not()`.

lib/Support/Events/EventFiringWebDriverNavigation.php

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
use Facebook\WebDriver\Exception\WebDriverException;
1919
use Facebook\WebDriver\WebDriverDispatcher;
20-
use Facebook\WebDriver\WebDriverNavigation;
20+
use Facebook\WebDriver\WebDriverNavigationInterface;
2121

22-
class EventFiringWebDriverNavigation
22+
class EventFiringWebDriverNavigation implements WebDriverNavigationInterface
2323
{
2424
/**
25-
* @var WebDriverNavigation
25+
* @var WebDriverNavigationInterface
2626
*/
2727
protected $navigator;
2828
/**
@@ -31,10 +31,10 @@ class EventFiringWebDriverNavigation
3131
protected $dispatcher;
3232

3333
/**
34-
* @param WebDriverNavigation $navigator
34+
* @param WebDriverNavigationInterface $navigator
3535
* @param WebDriverDispatcher $dispatcher
3636
*/
37-
public function __construct(WebDriverNavigation $navigator, WebDriverDispatcher $dispatcher)
37+
public function __construct(WebDriverNavigationInterface $navigator, WebDriverDispatcher $dispatcher)
3838
{
3939
$this->navigator = $navigator;
4040
$this->dispatcher = $dispatcher;
@@ -49,17 +49,13 @@ public function getDispatcher()
4949
}
5050

5151
/**
52-
* @return WebDriverNavigation
52+
* @return WebDriverNavigationInterface
5353
*/
5454
public function getNavigator()
5555
{
5656
return $this->navigator;
5757
}
5858

59-
/**
60-
* @throws WebDriverException
61-
* @return $this
62-
*/
6359
public function back()
6460
{
6561
$this->dispatch(
@@ -79,10 +75,6 @@ public function back()
7975
return $this;
8076
}
8177

82-
/**
83-
* @throws WebDriverException
84-
* @return $this
85-
*/
8678
public function forward()
8779
{
8880
$this->dispatch(
@@ -102,10 +94,6 @@ public function forward()
10294
return $this;
10395
}
10496

105-
/**
106-
* @throws WebDriverException
107-
* @return $this
108-
*/
10997
public function refresh()
11098
{
11199
try {
@@ -118,11 +106,6 @@ public function refresh()
118106
}
119107
}
120108

121-
/**
122-
* @param mixed $url
123-
* @throws WebDriverException
124-
* @return $this
125-
*/
126109
public function to($url)
127110
{
128111
$this->dispatch(

lib/WebDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function manage();
115115
* An abstraction allowing the driver to access the browser's history and to
116116
* navigate to a given URL.
117117
*
118-
* @return WebDriverNavigation
118+
* @return WebDriverNavigationInterface
119119
* @see WebDriverNavigation
120120
*/
121121
public function navigate();

lib/WebDriverNavigation.php

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,7 @@
1818
use Facebook\WebDriver\Remote\DriverCommand;
1919
use Facebook\WebDriver\Remote\ExecuteMethod;
2020

21-
/**
22-
* An abstraction allowing the driver to access the browser's history and to
23-
* navigate to a given URL.
24-
*
25-
* Note that they are all blocking functions until the page is loaded by
26-
* by default. It could be overridden by 'webdriver.load.strategy' in the
27-
* FirefoxProfile preferences.
28-
* https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#firefoxprofile-settings
29-
*/
30-
class WebDriverNavigation
21+
class WebDriverNavigation implements WebDriverNavigationInterface
3122
{
3223
protected $executor;
3324

@@ -36,49 +27,27 @@ public function __construct(ExecuteMethod $executor)
3627
$this->executor = $executor;
3728
}
3829

39-
/**
40-
* Move back a single entry in the browser's history, if possible.
41-
*
42-
* @return WebDriverNavigation The instance.
43-
*/
4430
public function back()
4531
{
4632
$this->executor->execute(DriverCommand::GO_BACK);
4733

4834
return $this;
4935
}
5036

51-
/**
52-
* Move forward a single entry in the browser's history, if possible.
53-
*
54-
* @return WebDriverNavigation The instance.
55-
*/
5637
public function forward()
5738
{
5839
$this->executor->execute(DriverCommand::GO_FORWARD);
5940

6041
return $this;
6142
}
6243

63-
/**
64-
* Refresh the current page.
65-
*
66-
* @return WebDriverNavigation The instance.
67-
*/
6844
public function refresh()
6945
{
7046
$this->executor->execute(DriverCommand::REFRESH);
7147

7248
return $this;
7349
}
7450

75-
/**
76-
* Navigate to the given URL.
77-
*
78-
* @see WebDriver::get()
79-
* @param string $url
80-
* @return WebDriverNavigation The instance.
81-
*/
8251
public function to($url)
8352
{
8453
$params = ['url' => (string) $url];

lib/WebDriverNavigationInterface.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Facebook\WebDriver;
4+
5+
/**
6+
* An abstraction allowing the driver to access the browser's history and to
7+
* navigate to a given URL.
8+
*/
9+
interface WebDriverNavigationInterface
10+
{
11+
/**
12+
* Move back a single entry in the browser's history, if possible.
13+
* This is equivalent to pressing the back button in the browser or invoking window.history.back.
14+
*
15+
* @return self
16+
*/
17+
public function back();
18+
19+
/**
20+
* Move forward a single entry in the browser's history, if possible.
21+
* This is equivalent to pressing the forward button in the browser or invoking window.history.back.
22+
*
23+
* @return self
24+
*/
25+
public function forward();
26+
27+
/**
28+
* Refresh the current page
29+
* This is equivalent to pressing the refresh button in the browser.
30+
*
31+
* @return self
32+
*/
33+
public function refresh();
34+
35+
/**
36+
* Navigate to the given URL
37+
*
38+
* @param string $url
39+
* @return self
40+
* @see WebDriver::get()
41+
*/
42+
public function to($url);
43+
}

0 commit comments

Comments
 (0)