Skip to content

Commit 52cf4e1

Browse files
committed
removeSession method implementation (W3C client)
1 parent 4c395af commit 52cf4e1

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/Client/W3CClient.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,30 @@ function (Throwable $rejectionReason) use ($sessionOpeningDeferred) {
184184
*/
185185
public function removeSession(string $sessionIdentifier): PromiseInterface
186186
{
187-
// todo: implementation
187+
$requestUri = sprintf(
188+
'http://%s:%d/wd/hub/session/%s',
189+
$this->_options['server']['host'],
190+
$this->_options['server']['port'],
191+
$sessionIdentifier
192+
);
188193

189-
return reject(new RuntimeException('Not implemented.'));
194+
$requestHeaders = [
195+
'Content-Type' => 'application/json; charset=UTF-8',
196+
];
197+
198+
$responsePromise = $this->httpClient->delete($requestUri, $requestHeaders);
199+
200+
$quitConfirmationPromise = $responsePromise
201+
->then(fn (ResponseInterface $response) => $this->onCommandConfirmation($response))
202+
->then(
203+
null,
204+
function (Throwable $rejectionReason) {
205+
throw new RuntimeException('Unable to close a session.', 0, $rejectionReason);
206+
}
207+
)
208+
;
209+
210+
return $quitConfirmationPromise;
190211
}
191212

192213
/**

src/SeleniumHubDriver.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ public function getSessionIdentifiers(): PromiseInterface
114114
*/
115115
public function removeSession(string $sessionIdentifier): PromiseInterface
116116
{
117-
// todo: implementation
117+
$quitConfirmationPromise = $this->hubClient->removeSession($sessionIdentifier);
118118

119-
return reject(new RuntimeException('Not implemented.'));
119+
return $this->timeoutInterceptor->applyTimeout(
120+
$quitConfirmationPromise,
121+
'Unable to complete a session remove command.'
122+
);
120123
}
121124

122125
/**

0 commit comments

Comments
 (0)