@@ -42,23 +42,25 @@ final class Client extends BaseClient implements WebDriver
4242 */
4343 private $ webDriver ;
4444 private $ browserManager ;
45+ private $ baseUri ;
4546
4647 /**
4748 * @param string[]|null $arguments
4849 */
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
5051 {
51- return new self (new ChromeManager ($ chromeDriverBinary , $ arguments) );
52+ return new self (new ChromeManager ($ chromeDriverBinary , $ arguments, $ options ), $ baseUri );
5253 }
5354
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
5556 {
56- return new self (new SeleniumManager ($ host , $ capabilities ));
57+ return new self (new SeleniumManager ($ host , $ capabilities ), $ baseUri );
5758 }
5859
59- public function __construct (BrowserManagerInterface $ browserManager )
60+ public function __construct (BrowserManagerInterface $ browserManager, ? string $ baseUri = null )
6061 {
6162 $ this ->browserManager = $ browserManager ;
63+ $ this ->baseUri = $ baseUri ;
6264 }
6365
6466 public function __destruct ()
@@ -87,7 +89,7 @@ public function isFollowingRedirects(): bool
8789
8890 public function setMaxRedirects ($ maxRedirects ): void
8991 {
90- if ($ maxRedirects !== - 1 ) {
92+ if (- 1 !== $ maxRedirects ) {
9193 throw new \InvalidArgumentException ('There are no max redirects when using WebDriver. ' );
9294 }
9395 }
@@ -242,6 +244,11 @@ public function get($uri)
242244 {
243245 $ this ->start ();
244246
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+
245252 $ this ->request = $ this ->internalRequest = new Request ($ uri , 'GET ' );
246253 $ this ->webDriver ->get ($ uri );
247254 $ this ->response = $ this ->internalResponse = new Response ($ this ->webDriver ->getPageSource ());
0 commit comments