Dart API ReferencewebdriverWebDriver

WebDriver class

class WebDriver extends WebDriverBase {

  WebDriver(host, port, path) : super(host, port, path);

  /**
   * Create a new session. The server will attempt to create a session that
   * most closely matches the desired and required capabilities. Required
   * capabilities have higher priority than desired capabilities and must be
   * set for the session to be created.
   *
   * The capabilities are:
   *
   * - browserName (String)  The name of the browser being used; should be one
   *   of chrome|firefox|htmlunit|internet explorer|iphone.
   *
   * - version (String) The browser version, or the empty string if unknown.
   *
   * - platform (String) A key specifying which platform the browser is
   *   running on. This value should be one of WINDOWS|XP|VISTA|MAC|LINUX|UNIX.
   *   When requesting a new session, the client may specify ANY to indicate
   *   any available platform may be used.
   *
   * - javascriptEnabled (bool) Whether the session supports executing user
   *   supplied JavaScript in the context of the current page.
   *
   * - takesScreenshot (bool) Whether the session supports taking screenshots
   *   of the current page.
   *
   * - handlesAlerts (bool) Whether the session can interact with modal popups,
   *   such as window.alert and window.confirm.
   *
   * - databaseEnabled (bool) Whether the session can interact database storage.
   *
   * - locationContextEnabled (bool) Whether the session can set and query the
   *   browser's location context.
   *
   * - applicationCacheEnabled (bool) Whether the session can interact with
   *   the application cache.
   *
   * - browserConnectionEnabled (bool) Whether the session can query for the
   *   browser's connectivity and disable it if desired.
   *
   * - cssSelectorsEnabled (bool) Whether the session supports CSS selectors
   *   when searching for elements.
   *
   * - webStorageEnabled (bool) Whether the session supports interactions with
   *   storage objects.
   *
   * - rotatable (bool) Whether the session can rotate the current page's
   *   current layout between portrait and landscape orientations (only applies
   *   to mobile platforms).
   *
   * - acceptSslCerts (bool) Whether the session should accept all SSL certs
   *   by default.
   *
   * - nativeEvents (bool) Whether the session is capable of generating native
   *   events when simulating user input.
   *
   * - proxy (proxy object) Details of any proxy to use. If no proxy is
   *   specified, whatever the system's current or default state is used.
   *
   * The format of the proxy object is:
   *
   * - proxyType (String) The type of proxy being used. Possible values are:
   *
   *   direct - A direct connection - no proxy in use,
   *
   *   manual - Manual proxy settings configured,
   *
   *   pac - Proxy autoconfiguration from a URL),
   *
   *   autodetect (proxy autodetection, probably with WPAD),
   *
   *   system - Use system settings
   *
   * - proxyAutoconfigUrl (String) Required if proxyType == pac, Ignored
   *   otherwise. Specifies the URL to be used for proxy autoconfiguration.
   *
   * - ftpProxy, httpProxy, sslProxy (String) (Optional, Ignored if
   *   proxyType != manual) Specifies the proxies to be used for FTP, HTTP
   *   and HTTPS requests respectively. Behaviour is undefined if a request
   *   is made, where the proxy for the particular protocol is undefined,
   *   if proxyType is manual.
   *
   * Potential Errors: SessionNotCreatedException (if a required capability
   * could not be set).
   */
  Future<WebDriverSession> newSession([
      browser = 'chrome', Map additional_capabilities]) {
    var completer = new Completer();
    if (additional_capabilities == null) {
      additional_capabilities = {};
    }

    additional_capabilities['browserName'] = browser;

    _serverRequest('POST', '${_path}/session', null, [ 302 ],
        customHandler: (r, v) {
          var url = r.headers.value(HttpHeaders.LOCATION);
          var session = new WebDriverSession.fromUrl(url);
          completer.complete(session);
        }, params: { 'desiredCapabilities': additional_capabilities });
    return completer.future;
  }

  /** Get the set of currently active sessions. */
  Future<List<WebDriverSession>> getSessions() {
    var completer = new Completer();
    _get('sessions', (result) {
      var _sessions = [];
      for (var session in result) {
        _sessions.add(new WebDriverSession.fromUrl(
          '${this._path}/session/${session["id"]}'));
      }
      completer.complete(_sessions);
    });
    return completer.future;
  }

  /** Query the server's current status. */
  Future<Map> getStatus() => _get('status');
}

Extends

WebDriverBase > WebDriver

Constructors

new WebDriver(host, port, path) #

WebDriver(host, port, path) : super(host, port, path);

Properties

final String path #

inherited from WebDriverBase
String get path => _path;

final String url #

inherited from WebDriverBase
String get url => _url;

Methods

Future<List<WebDriverSession>> getSessions() #

Get the set of currently active sessions.

Future<List<WebDriverSession>> getSessions() {
  var completer = new Completer();
  _get('sessions', (result) {
    var _sessions = [];
    for (var session in result) {
      _sessions.add(new WebDriverSession.fromUrl(
        '${this._path}/session/${session["id"]}'));
    }
    completer.complete(_sessions);
  });
  return completer.future;
}

Future<Map> getStatus() #

Query the server's current status.

Future<Map> getStatus() => _get('status');

Future<WebDriverSession> newSession([browser = 'chrome', Map additional_capabilities]) #

Create a new session. The server will attempt to create a session that most closely matches the desired and required capabilities. Required capabilities have higher priority than desired capabilities and must be set for the session to be created.

The capabilities are:

  • browserName (String) The name of the browser being used; should be one of chrome|firefox|htmlunit|internet explorer|iphone.

  • version (String) The browser version, or the empty string if unknown.

  • platform (String) A key specifying which platform the browser is running on. This value should be one of WINDOWS|XP|VISTA|MAC|LINUX|UNIX. When requesting a new session, the client may specify ANY to indicate any available platform may be used.

  • javascriptEnabled (bool) Whether the session supports executing user supplied JavaScript in the context of the current page.

  • takesScreenshot (bool) Whether the session supports taking screenshots of the current page.

  • handlesAlerts (bool) Whether the session can interact with modal popups, such as window.alert and window.confirm.

  • databaseEnabled (bool) Whether the session can interact database storage.

  • locationContextEnabled (bool) Whether the session can set and query the browser's location context.

  • applicationCacheEnabled (bool) Whether the session can interact with the application cache.

  • browserConnectionEnabled (bool) Whether the session can query for the browser's connectivity and disable it if desired.

  • cssSelectorsEnabled (bool) Whether the session supports CSS selectors when searching for elements.

  • webStorageEnabled (bool) Whether the session supports interactions with storage objects.

  • rotatable (bool) Whether the session can rotate the current page's current layout between portrait and landscape orientations (only applies to mobile platforms).

  • acceptSslCerts (bool) Whether the session should accept all SSL certs by default.

  • nativeEvents (bool) Whether the session is capable of generating native events when simulating user input.

  • proxy (proxy object) Details of any proxy to use. If no proxy is specified, whatever the system's current or default state is used.

The format of the proxy object is:

  • proxyType (String) The type of proxy being used. Possible values are:

direct - A direct connection - no proxy in use,

manual - Manual proxy settings configured,

pac - Proxy autoconfiguration from a URL),

autodetect (proxy autodetection, probably with WPAD),

system - Use system settings

  • proxyAutoconfigUrl (String) Required if proxyType == pac, Ignored otherwise. Specifies the URL to be used for proxy autoconfiguration.

  • ftpProxy, httpProxy, sslProxy (String) (Optional, Ignored if proxyType != manual) Specifies the proxies to be used for FTP, HTTP and HTTPS requests respectively. Behaviour is undefined if a request is made, where the proxy for the particular protocol is undefined, if proxyType is manual.

Potential Errors: SessionNotCreatedException (if a required capability could not be set).

Future<WebDriverSession> newSession([
    browser = 'chrome', Map additional_capabilities]) {
  var completer = new Completer();
  if (additional_capabilities == null) {
    additional_capabilities = {};
  }

  additional_capabilities['browserName'] = browser;

  _serverRequest('POST', '${_path}/session', null, [ 302 ],
      customHandler: (r, v) {
        var url = r.headers.value(HttpHeaders.LOCATION);
        var session = new WebDriverSession.fromUrl(url);
        completer.complete(session);
      }, params: { 'desiredCapabilities': additional_capabilities });
  return completer.future;
}