1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:08:10 +00:00

LibWeb+WebDriver: Begin processing and matching WebDriver capabilities

Still some TODOs here:
* We don't handle all capabilities (e.g. proxy)
* We don't match the capabilities against the running browser

But this will parse the capabilities JSON object received from the
WebDriver client.
This commit is contained in:
Timothy Flynn 2022-11-17 12:57:14 -05:00 committed by Linus Groh
parent 5b5b563968
commit e0c7b5747d
4 changed files with 321 additions and 4 deletions

View file

@ -11,6 +11,7 @@
#include <AK/Debug.h>
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <LibWeb/WebDriver/Capabilities.h>
#include <WebDriver/Client.h>
namespace WebDriver {
@ -73,7 +74,7 @@ void Client::close_session(unsigned session_id)
// 8.1 New Session, https://w3c.github.io/webdriver/#dfn-new-sessions
// POST /session
Web::WebDriver::Response Client::new_session(Web::WebDriver::Parameters, JsonValue)
Web::WebDriver::Response Client::new_session(Web::WebDriver::Parameters, JsonValue payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session");
@ -90,10 +91,12 @@ Web::WebDriver::Response Client::new_session(Web::WebDriver::Parameters, JsonVal
// FIXME: 3. If the maximum active sessions is equal to the length of the list of active sessions,
// return error with error code session not created.
// FIXME: 4. Let capabilities be the result of trying to process capabilities with parameters as an argument.
auto capabilities = JsonObject {};
// 4. Let capabilities be the result of trying to process capabilities with parameters as an argument.
auto capabilities = TRY(Web::WebDriver::process_capabilities(payload));
// FIXME: 5. If capabilitiess is null, return error with error code session not created.
// 5. If capabilitiess is null, return error with error code session not created.
if (capabilities.is_null())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::SessionNotCreated, "Could not match capabilities"sv);
// 6. Let session id be the result of generating a UUID.
// FIXME: Actually create a UUID.