2727 *
2828 * @package WebDriver
2929 */
30- final class Execute extends AbstractWebDriver
30+ class Execute extends AbstractWebDriver
3131{
3232 /**
3333 * {@inheritdoc}
@@ -48,7 +48,7 @@ public function async(array $jsonScript)
4848 {
4949 $ jsonScript ['args ' ] = $ this ->serializeArguments ($ jsonScript ['args ' ]);
5050
51- $ result = $ this ->curl ('POST ' , '/execute_async ' , $ jsonScript );
51+ $ result = $ this ->curl ('POST ' , '/async ' , $ jsonScript );
5252
5353 return $ this ->unserializeResult ($ result ['value ' ]);
5454 }
@@ -64,7 +64,7 @@ public function sync(array $jsonScript)
6464 {
6565 $ jsonScript ['args ' ] = $ this ->serializeArguments ($ jsonScript ['args ' ]);
6666
67- $ result = $ this ->curl ('POST ' , '/execute ' , $ jsonScript );
67+ $ result = $ this ->curl ('POST ' , '/sync ' , $ jsonScript );
6868
6969 return $ this ->unserializeResult ($ result ['value ' ]);
7070 }
@@ -78,7 +78,7 @@ public function sync(array $jsonScript)
7878 *
7979 * @return array
8080 */
81- private function serializeArguments (array $ arguments )
81+ protected function serializeArguments (array $ arguments )
8282 {
8383 foreach ($ arguments as $ key => $ value ) {
8484 switch (true ) {
@@ -110,7 +110,7 @@ private function serializeArguments(array $arguments)
110110 *
111111 * @return mixed
112112 */
113- private function unserializeResult ($ result )
113+ protected function unserializeResult ($ result )
114114 {
115115 $ element = is_array ($ result ) ? $ this ->webDriverElement ($ result ) : null ;
116116
@@ -136,29 +136,30 @@ private function unserializeResult($result)
136136 */
137137 protected function webDriverElement ($ value )
138138 {
139- $ basePath = preg_replace ('~/execute$~ ' , '' , $ this ->url );
140-
141139 if (array_key_exists (LegacyElement::LEGACY_ELEMENT_ID , $ value )) {
140+ $ identifier = $ value [LegacyElement::LEGACY_ELEMENT_ID ];
141+
142142 return new LegacyElement (
143- $ basePath . '/element/ ' . $ value [LegacyElement::LEGACY_ELEMENT_ID ], // url
144- $ value [LegacyElement::LEGACY_ELEMENT_ID ], // id
145- $ this ->legacy
143+ $ this ->getElementPath ('/element/ ' . $ identifier ),
144+ $ identifier
146145 );
147146 }
148147
149148 if (array_key_exists (Element::WEB_ELEMENT_ID , $ value )) {
149+ $ identifier = $ value [Element::WEB_ELEMENT_ID ];
150+
150151 return new Element (
151- $ basePath . '/element/ ' . $ value [Element::WEB_ELEMENT_ID ], // url
152- $ value [Element::WEB_ELEMENT_ID ], // id
153- $ this ->legacy
152+ $ this ->getElementPath ('/element/ ' . $ identifier ),
153+ $ identifier
154154 );
155155 }
156156
157157 if (array_key_exists (Shadow::SHADOW_ROOT_ID , $ value )) {
158+ $ identifier = $ value [Shadow::SHADOW_ROOT_ID ];
159+
158160 return new Shadow (
159- $ basePath . '/shadow/ ' . $ value [Shadow::SHADOW_ROOT_ID ], // url
160- $ value [Shadow::SHADOW_ROOT_ID ], // id
161- $ this ->legacy
161+ $ this ->getElementPath ('/shadow/ ' . $ identifier ),
162+ $ identifier
162163 );
163164 }
164165
@@ -168,8 +169,8 @@ protected function webDriverElement($value)
168169 /**
169170 * {@inheritdoc}
170171 */
171- protected function getElementPath ($ unused )
172+ protected function getElementPath ($ identifier )
172173 {
173- return $ this ->url ;
174+ return preg_replace ( ' ~/execute$~ ' , '' , $ this ->url ) . $ identifier ;
174175 }
175176}
0 commit comments