Home

Awesome

Web Driver for Elixir

Build Status

Current Version 0.8.2

This is an implementation of the WebDriver protocol client. It currently supports PhantomJS, FireFox, ChromeDriver and remote webdriver servers (e.g. Selenium).

Most of the basic functionality of the WebDriver JSON wire protocol works with all three browsers. Notable missing elements are touch events, local storage and session storage.

Installation

This library has been set up as a Mix application, so just add this to mix.exs deps:

{:webdriver, github: "stuart/elixir-webdriver"}

or if you do Hex.pm:

{:webdriver, "~>0.8.0"}

and make sure the application block of mix.exs includes: applications: [ :webdriver ] or call :application.start :webdriver in your code.

Generate documentation with mix docs. Run the tests with mix test. The tests will check if PhantomJS, ChromeDriver and Firefox are installed and only run the appropriate ones. It uses the :os.find_executable function to find the appropriate paths so check that if a browser is not found.

##Documentation

Usage

When the application starts it will fire up a supervision tree for the browsers to be run under.

You can start a browser instance with WebDriver.start_browser config where config is a WebDriver.Config record.

Currently the config is very simple it just consists of two or three fields:

You can then start up a session on the browser with

WebDriver.start_session browser_name, session_name

Once the session is started you can do commands on it, see the edoc documentation for more on specific commands.

An example session is shown here:

    iex(1)> config = %WebDriver.Config{name: :browser}
    %WebDriver.Config{browser: :phantomjs, name: :browser, root_url: ""}
    iex(2)> WebDriver.start_browser config
    {:ok, #PID<0.302.0>}
    iex(3)> WebDriver.start_session :browser, :session
    {:ok, #PID<0.306.0>}
    iex(4)> WebDriver.Session.url :session
    "about:blank"
    iex(5)> WebDriver.Session.url :session, "http://elixir-lang.org"
    {:ok,
     %WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{\"url\":\"http://elixir-lang.org\"}",
       headers: ["Content-Type": "application/json;charset=UTF-8",
        "Content-Length": 32], method: :POST,
       url: "http://localhost:56946/wd/hub/session/4dc12b20-2121-11e4-ace2-119365bfea27/url"},
      session_id: "4dc12b20-2121-11e4-ace2-119365bfea27", status: 0, value: [{}]}}
    iex(6)> element =  WebDriver.Session.element :session, :css, ".news"
    %WebDriver.Element{id: ":wdc:1407738793120", session: :session}
    iex(7)> WebDriver.Element.text element
    "News: Elixir v0.15.0 released"
    iex(8)> WebDriver.stop_browser :browser
    :ok

Requirements

You will need one or more of the following installed in the usual place for your OS:

Currently I have only tested extensively on OSX, and Ubuntu Linux. It should work on most UNIX like platforms. There is some rudimentary Windows support code in here, but I'm pretty sure that it won't work.

Support

Please report any issues you have with using this library in the Github issues for the project: https://github.com/stuart/elixir-webdriver/issues

Changelog