@@ -56,22 +56,19 @@ class RemoteWebDriver implements WebDriver, JavaScriptExecutor, WebDriverHasInpu
5656 /**
5757 * @param HttpCommandExecutor $commandExecutor
5858 * @param string $sessionId
59- * @param WebDriverCapabilities|null $capabilities
59+ * @param WebDriverCapabilities $capabilities
6060 * @param bool $isW3cCompliant false to use the legacy JsonWire protocol, true for the W3C WebDriver spec
6161 */
6262 protected function __construct (
6363 HttpCommandExecutor $ commandExecutor ,
6464 $ sessionId ,
65- WebDriverCapabilities $ capabilities = null ,
65+ WebDriverCapabilities $ capabilities ,
6666 $ isW3cCompliant = false
6767 ) {
6868 $ this ->executor = $ commandExecutor ;
6969 $ this ->sessionID = $ sessionId ;
7070 $ this ->isW3cCompliant = $ isW3cCompliant ;
71-
72- if ($ capabilities !== null ) {
73- $ this ->capabilities = $ capabilities ;
74- }
71+ $ this ->capabilities = $ capabilities ;
7572 }
7673
7774 /**
@@ -147,6 +144,8 @@ public static function create(
147144 * @param int|null $connection_timeout_in_ms Set timeout for the connect phase to remote Selenium WebDriver server
148145 * @param int|null $request_timeout_in_ms Set the maximum time of a request to remote Selenium WebDriver server
149146 * @param bool $isW3cCompliant True to use W3C WebDriver (default), false to use the legacy JsonWire protocol
147+ * @param WebDriverCapabilities|null $existingCapabilities Provide capabilities of the existing previously created
148+ * session. If not provided, we will attempt to read them, but this will only work when using Selenium Grid.
150149 * @return static
151150 */
152151 public static function createBySessionID (
@@ -157,6 +156,7 @@ public static function createBySessionID(
157156 ) {
158157 // BC layer to not break the method signature
159158 $ isW3cCompliant = func_num_args () > 4 ? func_get_arg (4 ) : true ;
159+ $ existingCapabilities = func_num_args () > 5 ? func_get_arg (5 ) : null ;
160160
161161 $ executor = new HttpCommandExecutor ($ selenium_server_url , null , null );
162162 if ($ connection_timeout_in_ms !== null ) {
@@ -170,7 +170,13 @@ public static function createBySessionID(
170170 $ executor ->disableW3cCompliance ();
171171 }
172172
173- return new static ($ executor , $ session_id , null , $ isW3cCompliant );
173+ if ($ existingCapabilities === null ) {
174+ throw new UnknownErrorException (
175+ 'Existing capabilities must be provided when reusing previous session. '
176+ );
177+ }
178+
179+ return new static ($ executor , $ session_id , $ existingCapabilities , $ isW3cCompliant );
174180 }
175181
176182 /**
0 commit comments