pub async fn start_session<C>(
    conn: Arc<dyn RemoteConnectionAsync>,
    capabilities: C,
) -> WebDriverResult<(SessionId, serde_json::Value)>
where
    C: Serialize,
{
    let caps = serde_json::to_value(capabilities)?;
    let v = match conn.execute(&SessionId::null(), Command::NewSession(&caps)).await {
        Ok(x) => Ok(x),
        Err(e) => {
            // Selenium sometimes gives a bogus 500 error "Chrome failed to start".
            // Retry if we get a 500. If it happens twice in a row then the second error
            // will be returned.
            if let WebDriverError::UnknownError(x) = &e {
                if x.status == 500 {
                    conn.execute(&SessionId::null(), Command::NewSession(&caps)).await
                } else {
                    Err(e)
                }
            } else {
                Err(e)
            }
        }
    }?;

    #[derive(Debug, Deserialize)]
    struct ConnectionData {
        #[serde(default, rename(deserialize = "sessionId"))]
        session_id: String,
        #[serde(default)]
        capabilities: serde_json::Value,
    }

    #[derive(Debug, Deserialize)]
    struct ConnectionResp {
        #[serde(default)]
        session_id: String,
        value: ConnectionData,
    }

    let resp: ConnectionResp = serde_json::from_value(v)?;
    let data = resp.value;
    let session_id = SessionId::from(if resp.session_id.is_empty() {
        data.session_id
    } else {
        resp.session_id
    });

    // Set default timeouts.
    let timeout_config = TimeoutConfiguration::new(
        Some(Duration::new(60, 0)),
        Some(Duration::new(60, 0)),
        Some(Duration::new(30, 0)),
    );
    conn.execute(&session_id, Command::SetTimeouts(timeout_config)).await?;

    Ok((session_id, data.capabilities))
}
/// Start a new WebDriver session, returning the session id and the
/// capabilities JSON that was received back from the server.
Start a new WebDriver session, returning the session id and the
capabilities JSON that was received back from the server.
Start a new WebDriver session returning the session id and the capabilities JSON that was received back from the server .
pub async fn start_session<C>(
    conn: Arc<dyn RemoteConnectionAsync>,
    capabilities: C,
) -> WebDriverResult<(SessionId, serde_json::Value)>
where
    C: Serialize,
{
    let caps = serde_json::to_value(capabilities)?;
    let v = match conn.execute(&SessionId::null(), Command::NewSession(&caps)).await {
        Ok(x) => Ok(x),
        Err(e) => {
            // Selenium sometimes gives a bogus 500 error "Chrome failed to start".
            // Retry if we get a 500. If it happens twice in a row then the second error
            // will be returned.
            if let WebDriverError::UnknownError(x) = &e {
                if x.status == 500 {
                    conn.execute(&SessionId::null(), Command::NewSession(&caps)).await
                } else {
                    Err(e)
                }
            } else {
                Err(e)
            }
        }
    }?;
    #[derive(Debug, Deserialize)]
    struct ConnectionData {
        #[serde(default, rename(deserialize = "sessionId"))]
        session_id: String,
        #[serde(default)]
        capabilities: serde_json::Value,
    }
    #[derive(Debug, Deserialize)]
    struct ConnectionResp {
        #[serde(default)]
        session_id: String,
        value: ConnectionData,
    }
    let resp: ConnectionResp = serde_json::from_value(v)?;
    let data = resp.value;
    let session_id = SessionId::from(if resp.session_id.is_empty() {
        data.session_id
    } else {
        resp.session_id
    });
    // Set default timeouts.
    let timeout_config = TimeoutConfiguration::new(
        Some(Duration::new(60, 0)),
        Some(Duration::new(60, 0)),
        Some(Duration::new(30, 0)),
    );
    conn.execute(&session_id, Command::SetTimeouts(timeout_config)).await?;
    Ok((session_id, data.capabilities))
}
pub async fn start_session < C > ( conn : Arc < dyn RemoteConnectionAsync > , capabilities : C , ) -> WebDriverResult < ( SessionId , serde_json :: Value ) > where C : Serialize , { let caps = serde_json :: to_value ( capabilities ) ? ; let v = match conn . execute ( & SessionId :: null ( ) , Command :: NewSession ( & caps ) ) . await { Ok ( x ) => Ok ( x ) , Err ( e ) => { // Selenium sometimes gives a bogus 500 error "Chrome failed to start". // Retry if we get a 500. If it happens twice in a row then the second error // will be returned. if let WebDriverError :: UnknownError ( x ) = & e { if x . status == 500 { conn . execute ( & SessionId :: null ( ) , Command :: NewSession ( & caps ) ) . await } else { Err ( e ) } } else { Err ( e ) } } } ? ; # [ derive ( Debug Deserialize ) ] struct ConnectionData { # [ serde ( default rename ( deserialize " " ) ) ] session_id : String , # [ serde ( default ) ] capabilities : serde_json :: Value , } # [ derive ( Debug Deserialize ) ] struct ConnectionResp { # [ serde ( default ) ] session_id : String , value : ConnectionData , } let resp : ConnectionResp = serde_json :: from_value ( v ) ? ; let data = resp . value ; let session_id = SessionId :: from ( if resp . session_id . is_empty ( ) { data . session_id } else { resp . session_id } ) ; // Set default timeouts. let timeout_config = TimeoutConfiguration :: new ( Some ( Duration :: new ( 60 , 0 ) ) , Some ( Duration :: new ( 60 , 0 ) ) , Some ( Duration :: new ( 30 , 0 ) ) , ) ; conn . execute ( & session_id , Command :: SetTimeouts ( timeout_config ) ) . await ? ; Ok ( ( session_id , data . capabilities ) ) }
Start a new WebDriver session, returning the session id and the
capabilities JSON that was received back from the server.
Start a new WebDriver session returning the session id and the capabilities JSON that was received back from the server .
conn
Arc<dyn RemoteConnectionAsync>
capabilities
C