Skip to content

Commit

Permalink
Merge pull request #29 from stuart/feature/hex_dependencies
Browse files Browse the repository at this point in the history
Feature/hex dependencies
  • Loading branch information
stuart committed Aug 18, 2014
2 parents 6ba73ce + ebc74ef commit b3575ff
Show file tree
Hide file tree
Showing 23 changed files with 277 additions and 167 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"

before_script: "export PATH=$PATH:`pwd`/vendor/elixir/bin"
before_script:
- "export PATH=$PATH:`pwd`/vendor/elixir/bin"
- mix local.hex --force;

script: "MIX_ENV=test mix do deps.get, deps.compile, test"
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Web Driver for Elixir
[![Build Status](https://travis-ci.org/stuart/elixir-webdriver.png?branch=master)](https://travis-ci.org/stuart/elixir-webdriver)

[Current Version 0.5.0](https://github.com/stuart/elixir-webdriver/tree/0.5.0)
[Current Version 0.6.0](https://github.com/stuart/elixir-webdriver/tree/0.6.0)

This is an implementation of the WebDriver protocol client.
It currently supports PhantomJS, FireFox, ChromeDriver and remote webdriver
Expand Down Expand Up @@ -100,7 +100,22 @@ 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

* 2014-08-18
- Version 0.6.0
- Changed JSON library to Jazz
- Converted responses to be maps rather than Keywords
- Use hex.pm dependencies as much as possible
- Stability fixes to tests
- Documentation updates and cleanup.

* 2014-08-17
- Version 0.5.2
- Moved webdriver.xpi out of hex accessed path
Expand Down
4 changes: 2 additions & 2 deletions lib/webdriver/browser.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule WebDriver.Browser do
@moduledoc """
This is the basic skeleton for a Browser port to control a browser.
Implementations will need to use this and then implement the other required
functions.
Implementations for specific browsers will need to use this
and then implement the other required functionality.
"""
defmacro __using__(_opts) do
quote do
Expand Down
3 changes: 2 additions & 1 deletion lib/webdriver/browser_sup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ defmodule WebDriver.BrowserSup do
the running of browser instances and their associated session supervisors.
If a browser crashes for any reason this will restart the browser and the
sessions that connect to it.
sessions that connect to it. Of course those sessions will have lost their
state.
"""

@browsers [ firefox: WebDriver.Firefox.Port,
Expand Down
16 changes: 10 additions & 6 deletions lib/webdriver/cookie.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ defmodule WebDriver.Cookie do
A module for querying and manipulation of cookies.
Cookies are defined in a struct with the following fields:
- name
- value
- path
- domain
- secure
- expiry
* `name`
* `value`
* `path`
* `domain`
* `secure`
* `expiry`
"""

@doc """
Creates a cookie struct from a webdriver response.
"""
def from_response cookie do
struct(WebDriver.Cookie, Enum.map(cookie, fn({k,v}) -> {String.to_atom(k),v} end))
end
Expand Down
33 changes: 14 additions & 19 deletions lib/webdriver/element.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ defmodule WebDriver.Element do
They all take an WebDriver.Element struct as the first argument.
The WebDriver.Element struct is supposed to be an opaque data type and
is not meant to be manipulated.
is not meant to be manipulated. It contains the internal id of the element
used by the webdriver client and a the session name.
Elements are associated with a particular session and have no meaning
outside that WedDriver session.
Expand Down Expand Up @@ -51,10 +52,10 @@ defmodule WebDriver.Element do
https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/value
Parameters: [value: String]
Parameters: %{value: String}
"""
def value element, value do
cmd element, :value, [value: String.codepoints value]
cmd element, :value, %{value: String.codepoints value}
end

@doc """
Expand All @@ -77,7 +78,7 @@ defmodule WebDriver.Element do

@doc """
Returns a boolean denoting if the element is selected or not.
Returns :element_not_selectable if it is not able to be selected.
Returns {:element_not_selectable, response} if it is not able to be selected.
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/selected
"""
Expand Down Expand Up @@ -131,16 +132,16 @@ defmodule WebDriver.Element do
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/location
Returns [x: x, y: y]
Returns %{x: x, y: y}
"""
def location element do
case get_value element, :location do
# Bug with Python Selenium
# http://code.google.com/p/selenium/source/detail?r=bbcfab457b13
[{"toString",_},{"x",x},{"y",y}] ->
[x: x, y: y]
[{"x",x},{"y",y}] ->
[x: x, y: y]
%{"toString" => _,"x" => x,"y" => y} ->
%{x: x, y: y}
%{"x" => x, "y" => y} ->
%{x: x, y: y}
response -> # Pass error responses through.
response
end
Expand All @@ -151,7 +152,7 @@ defmodule WebDriver.Element do
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/location_in_view
Returns [x: x, y: y]
Returns %{x: x, y: y}
"""
def location_in_view element do
do_location_in_view(get_value(element, :location))
Expand All @@ -164,18 +165,15 @@ defmodule WebDriver.Element do
defp do_location_in_view response do
# Bugfix
# http://code.google.com/p/selenium/source/detail?r=bbcfab457b13
resp = Enum.into response, HashDict.new
{:ok, x} = HashDict.fetch(resp,"x")
{:ok, y} = HashDict.fetch(resp,"y")
[x: x, y: y]
%{x: response["x"], y: response["y"]}
end

@doc """
Returns size in pixels of the specified element.
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/size
Returns [width: w, height: h]
Returns %{width: w, height: h}
"""
def size element do
do_size(get_value(element, :size))
Expand All @@ -186,10 +184,7 @@ defmodule WebDriver.Element do
end

defp do_size response do
resp = Enum.into response, HashDict.new
{:ok, h} = HashDict.fetch(resp,"height")
{:ok, w} = HashDict.fetch(resp,"width")
[width: w, height: h]
%{width: response["width"], height: response["height"]}
end

@doc """
Expand Down
27 changes: 26 additions & 1 deletion lib/webdriver/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,32 @@ defmodule WebDriver.Error do
The codes that can be returned are:
* :success
* :no_such_driver
* :no_such_element
* :no_such_frame
* :unknown_command
* :stale_element_reference
* :element_not_visible
* :invalid_element_state
* :unknown_error
* :element_not_selectable
* :javascript_error
* :x_path_lookup_error
* :timeout
* :no_such_window
* :invalid_cookie_domain
* :unable_to_set_cookie
* :unexpected_alert_open
* :no_alert_open_error
* :script_timeout
* :invalid_element_coordinates
* :ime_not_available
* :ime_engine_activation_failed
* :invalid_selector
* :session_not_created_exception
* :move_target_out_of_bounds
"""

defmodule ErrorMessage do
Expand Down
3 changes: 0 additions & 3 deletions lib/webdriver/http/http.ex

This file was deleted.

65 changes: 65 additions & 0 deletions lib/webdriver/keys.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
defmodule WebDriver.Keys do
@moduledoc """
This provides symbols to represent various non-printable keystrokes that
can be sent to a web browser.
The codes are defined in: https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value
"""
@non_text_keys [
{ :key_null, "\x{e000}" },
{ :key_cancel, "\x{e001}"},
Expand Down Expand Up @@ -73,6 +80,64 @@ defmodule WebDriver.Keys do
Key codes that are available:
```Elixir
{ :key_null, "\x{e000}"},
{ :key_cancel, "\x{e001}"},
{ :key_help, "\x{e002}"},
{ :key_back_space,"\x{e003}"},
{ :key_tab, "\x{e004}"},
{ :key_clear, "\x{e005}"},
{ :key_return, "\x{e006}"},
{ :key_enter, "\x{e007}"},
{ :key_shift, "\x{e008}"},
{ :key_control, "\x{e009}"},
{ :key_alt, "\x{e00a}"},
{ :key_pause, "\x{e00b}"},
{ :key_escape, "\x{e00c}"},
{ :key_space, "\x{e00d}"},
{ :key_page_up, "\x{e00e}"},
{ :key_page_down, "\x{e00f}"},
{ :key_end, "\x{e010}"},
{ :key_home, "\x{e011}"},
{ :key_left, "\x{e012}"},
{ :key_up, "\x{e013}"},
{ :key_right, "\x{e014}"},
{ :key_down, "\x{e015}"},
{ :key_insert, "\x{e016}"},
{ :key_delete, "\x{e017}"},
{ :key_semicolon, "\x{e018}"},
{ :key_equals, "\x{e019}"},
{ :key_numpad_0, "\x{e01a}"},
{ :key_numpad_1, "\x{e01b}"},
{ :key_numpad_2, "\x{e01c}"},
{ :key_numpad_3, "\x{e01d}"},
{ :key_numpad_4, "\x{e01e}"},
{ :key_numpad_5, "\x{e01f}"},
{ :key_numpad_6, "\x{e020}"},
{ :key_numpad_7, "\x{e021}"},
{ :key_numpad_8, "\x{e022}"},
{ :key_numpad_9, "\x{e023}"},
{ :key_multiply, "\x{e024}"},
{ :key_add, "\x{e025}"},
{ :key_separator, "\x{e026}"},
{ :key_subtract, "\x{e027}"},
{ :key_decimal, "\x{e028}"},
{ :key_divide, "\x{e029}"},
{ :key_f1, "\x{e031}"},
{ :key_f2, "\x{e032}"},
{ :key_f3, "\x{e033}"},
{ :key_f4, "\x{e034}"},
{ :key_f5, "\x{e035}"},
{ :key_f6, "\x{e036}"},
{ :key_f7, "\x{e037}"},
{ :key_f8, "\x{e038}"},
{ :key_f9, "\x{e039}"},
{ :key_f10, "\x{e03a}"},
{ :key_f11, "\x{e03b}"},
{ :key_f12, "\x{e03c}"},
{ :key_meta, "\x{e03d}"}
```
"""
def key key_code do
Keyword.fetch(@non_text_keys, key_code)
Expand Down
16 changes: 11 additions & 5 deletions lib/webdriver/mouse.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule WebDriver.Mouse do
"""
def move_to element, offsetx \\ 0, offsety \\ 0 do
id = URI.decode element.id
cmd element.session, :move_to, [element: id, xoffset: offsetx, yoffset: offsety]
cmd element.session, :move_to, %{element: id, xoffset: offsetx, yoffset: offsety}
end

@doc """
Expand All @@ -28,7 +28,7 @@ defmodule WebDriver.Mouse do
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/click
"""
def click session, button \\ :left do
cmd session, :mouse_click, [button: button_number(button)]
cmd session, :mouse_click, %{button: button_number(button)}
end


Expand All @@ -39,10 +39,13 @@ defmodule WebDriver.Mouse do
session : The session server process to send the event to.
button: The button to press, one of :left, :middle or :right
You will get an error if you fire a button down event on a button that is
already down (on some browsers).
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttondown
"""
def button_down session, button \\ :left do
cmd session, :mouse_button_down, [button: button_number(button)]
cmd session, :mouse_button_down, %{button: button_number(button)}
end

@doc """
Expand All @@ -52,10 +55,13 @@ defmodule WebDriver.Mouse do
session : The session server process to send the event to.
button: The button to raise, one of :left, :middle or :right
You will get an error if you fire a button up event on a mouse
button that has not recieved a button down event previously.
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttonup
"""
def button_up session, button \\ :left do
cmd session, :mouse_button_up, [button: button_number(button)]
cmd session, :mouse_button_up, %{button: button_number(button)}
end

@doc """
Expand All @@ -68,7 +74,7 @@ defmodule WebDriver.Mouse do
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/doubleclick
"""
def double_click session, button \\ :left do
cmd session, :mouse_double_click, [button: button_number(button)]
cmd session, :mouse_double_click, %{button: button_number(button)}
end

# Send a command to the server
Expand Down
2 changes: 1 addition & 1 deletion lib/webdriver/phantomjs/port.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule WebDriver.PhantomJS.Port do

def normal_termination state do
# Send a shutdown signal to the PhantomJS process.
#HTTPotion.get "#{state.root_url}/shutdown"
HTTPotion.get "#{state.root_url}/shutdown"
Port.close state.port
:ok
end
Expand Down
Loading

0 comments on commit b3575ff

Please sign in to comment.