w3c-webdriver
  • Introduction
  • Capabilities
  • Sessions
  • Timeouts
  • Navigation
  • Contexts
  • Elements
  • Document
  • Cookies
  • Actions
  • User prompts
  • Screen capture
  • Examples
    • Cucumber Functional Tests
  • Resources
    • GitHub
    • WebDriver spec
    • MDN docs
Powered by GitBook
On this page
  • newSession(options)
  • status(url)
  • Session
  • session.close()
  • SessionOptions
  • Status
  • StatusOfOS
  • StatusOfWebDriver

Was this helpful?

Sessions

PreviousCapabilitiesNextTimeouts

Last updated 3 years ago

Was this helpful?

newSession(options)

Before we can send any command to the browser we drive we need to create a 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 (, , etc.), or cloud provider url (, , .etc.). Also we can set the browser and operating system parameters we want to interact with.

PARAMETERS

  • options: - Object with configuration for new session creation

RETURNS

Promise<>

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

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

  • 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

  • message: string

  • ready: boolean

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

Promise<>

capabilities: - WebDriver capabilities

os:

build:

WebDriver spec
WebDriver spec
Actions
Contexts
Cookies
Document
Elements
Navigation
Screen capture
Timeouts
User prompts
WebDriver spec
WebDriver
Chromedriver
Geckodriver
Selenium Server or Grid
BrowserStack
Sauce Labs
SessionOptions
Session
Status
StatusOfOS
StatusOfWebDriver
Capabilities