@@ -42,23 +42,25 @@ final class Client extends BaseClient implements WebDriver
42
42
*/
43
43
private $ webDriver ;
44
44
private $ browserManager ;
45
+ private $ baseUri ;
45
46
46
47
/**
47
48
* @param string[]|null $arguments
48
49
*/
49
- public static function createChromeClient (?string $ chromeDriverBinary = null , ?array $ arguments = null ): self
50
+ public static function createChromeClient (?string $ chromeDriverBinary = null , ?array $ arguments = null , array $ options = [], ? string $ baseUri = null ): self
50
51
{
51
- return new self (new ChromeManager ($ chromeDriverBinary , $ arguments) );
52
+ return new self (new ChromeManager ($ chromeDriverBinary , $ arguments, $ options ), $ baseUri );
52
53
}
53
54
54
- public static function createSeleniumClient (?string $ host = null , ?WebDriverCapabilities $ capabilities = null ): self
55
+ public static function createSeleniumClient (?string $ host = null , ?WebDriverCapabilities $ capabilities = null , ? string $ baseUri = null ): self
55
56
{
56
- return new self (new SeleniumManager ($ host , $ capabilities ));
57
+ return new self (new SeleniumManager ($ host , $ capabilities ), $ baseUri );
57
58
}
58
59
59
- public function __construct (BrowserManagerInterface $ browserManager )
60
+ public function __construct (BrowserManagerInterface $ browserManager, ? string $ baseUri = null )
60
61
{
61
62
$ this ->browserManager = $ browserManager ;
63
+ $ this ->baseUri = $ baseUri ;
62
64
}
63
65
64
66
public function __destruct ()
@@ -87,7 +89,7 @@ public function isFollowingRedirects(): bool
87
89
88
90
public function setMaxRedirects ($ maxRedirects ): void
89
91
{
90
- if ($ maxRedirects !== - 1 ) {
92
+ if (- 1 !== $ maxRedirects ) {
91
93
throw new \InvalidArgumentException ('There are no max redirects when using WebDriver. ' );
92
94
}
93
95
}
@@ -242,6 +244,11 @@ public function get($uri)
242
244
{
243
245
$ this ->start ();
244
246
247
+ // Prepend the base URI to URIs without a host
248
+ if (null !== $ this ->baseUri && (false !== $ components = \parse_url ($ uri )) && !isset ($ components ['host ' ])) {
249
+ $ uri = $ this ->baseUri .$ uri ;
250
+ }
251
+
245
252
$ this ->request = $ this ->internalRequest = new Request ($ uri , 'GET ' );
246
253
$ this ->webDriver ->get ($ uri );
247
254
$ this ->response = $ this ->internalResponse = new Response ($ this ->webDriver ->getPageSource ());
0 commit comments