Sessions

newSession(options)

Before we can send any command to the browser we drive we need to create a WebDriver session. This should be always the first step of interaction through the protocol. After executing this command the browser will be started and ready to receive the commands. As part of session creation we have to provide the url of WebDriver protocol compliant server. This can be a locally running browser driver server (Chromedriver, Geckodriver, etc.), Selenium Server or Grid or cloud provider url (BrowserStack, Sauce Labs, .etc.). Also we can set the browser and operating system parameters we want to interact with.

PARAMETERS

  • options: SessionOptions - Object with configuration for new session creation

RETURNS

Promise<Session>

EXAMPLES

import { newSession } from 'w3c-webdriver';

let session;

(async () => {
  try {
    session = await newSession({
      url: 'http://localhost:4444',
      capabilities: {
        alwaysMatch: {
          browserName: 'Chrome'
        }
      }
    });
  } catch (err) {
    console.log(err.stack);
  } finally {
    session.close();
  }
})();
const credentials = Buffer.from(['myusername', 'Password123'].join(':')).toString('base64');
const session = await newSession({
  headers: {
    Authorization: `Basic ${credentials}`
  }
});

SEE ALSO

status(url)

To be able to verify if the WebDriver server is ready for new session creation sometimes it can be useful to query it's status. This function queries the WebDriver server's current status. The status contains meta information about the WebDriver server and operating system.

PARAMETERS

  • url: string - Location of WebDriver API

RETURNS

Promise<Status>

EXAMPLES

import { status } from 'w3c-webdriver';

const status = await status('http://localhost:4444');
// status = {
//   build: { version: '1.2.0' },
//   os: { name: 'mac', version: 'unknown', arch: '64bit' }
// }

SEE ALSO

Session

This object represents a WebDriver session.

SEE ALSO

session.close()

Close the session.

RETURNS

Promise<void>

EXAMPLES

import { newSession } from 'w3c-webdriver';

let session;

(async () => {
  try {
    session = await newSession('http://localhost:4444', {
      desiredCapabilities: {
        browserName: 'Chrome'
      }
    });
  } catch (err) {
    console.log(err.stack);
  } finally {
    session.close();
  }
})();

SEE ALSO

SessionOptions

PROPERTIES

  • url: string - WebDriver server URL

  • capabilities: Capabilities - WebDriver capabilities

  • desiredCapabilities?: object - Legacy WebDriver capabilities. Can be used to enable the new W3C dialect

    • browserstack.use_w3c: boolean

  • headers?: Headers - Session creation request headers. Can be used for authorization.

Status

WebDriver status object

PROPERTIES

StatusOfOS

PROPERTIES

  • name: string - Name of operating system

  • version: string - Version of operating system

  • arch: string - Operating system architecture

StatusOfWebDriver

PROPERTIES

  • version: string - Version of driver

Last updated