-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added support for move_mouse_to WebDriver command and implemented move_mouse_by function that supplements hover * Added support for click-based mouse WebDriver commands: click (at the current mouse position), double_click (at the current mouse position), button_down, button_up
- Loading branch information
1 parent
c0ad66f
commit 2678b5d
Showing
19 changed files
with
798 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule Wallaby.Integration.Browser.ButtonDownTest do | ||
use Wallaby.Integration.SessionCase, async: true | ||
import Wallaby.Browser | ||
|
||
setup %{session: session} do | ||
{:ok, page: visit(session, "mouse_down_and_up.html")} | ||
end | ||
|
||
describe "button_down/2" do | ||
test "clicks and holds left mouse button at the current cursor position", %{page: page} do | ||
button_down_test(page, :left, "Left") | ||
end | ||
|
||
test "clicks and holds middle mouse button at the current cursor position", %{page: page} do | ||
button_down_test(page, :middle, "Middle") | ||
end | ||
|
||
test "clicks and holds right mouse button at the current cursor position", %{page: page} do | ||
button_down_test(page, :right, "Right") | ||
end | ||
end | ||
|
||
defp button_down_test(page, button, expected_log_prefix) do | ||
refute page | ||
|> visible?(Query.text("#{expected_log_prefix} Down")) | ||
|
||
assert page | ||
|> hover(Query.text("Button 1")) | ||
|> button_down(button) | ||
|> visible?(Query.text("#{expected_log_prefix} Down")) | ||
|
||
refute page | ||
|> visible?(Query.text("#{expected_log_prefix} Up")) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
defmodule Wallaby.Integration.Browser.ButtonUpTest do | ||
use Wallaby.Integration.SessionCase, async: true | ||
import Wallaby.Browser | ||
|
||
setup %{session: session} do | ||
{:ok, page: visit(session, "mouse_down_and_up.html")} | ||
end | ||
|
||
describe "button_down/2 releases previously held mouse button at the current cursor position" do | ||
test "for left button", %{page: page} do | ||
button_up_test(page, :left, "Left") | ||
end | ||
|
||
test "for middle button", %{page: page} do | ||
button_up_test(page, :middle, "Middle") | ||
end | ||
|
||
test "for right button", %{page: page} do | ||
button_up_test(page, :right, "Right") | ||
end | ||
end | ||
|
||
describe "button_down/2 releases previously held mouse button if cursor is moved from the position where the buton was pressed" do | ||
test "for left button", %{page: page} do | ||
move_cursor_then_button_up_test(page, :left, "Left") | ||
end | ||
|
||
test "for middle button", %{page: page} do | ||
move_cursor_then_button_up_test(page, :middle, "Middle") | ||
end | ||
|
||
test "for right button", %{page: page} do | ||
move_cursor_then_button_up_test(page, :right, "Right") | ||
end | ||
end | ||
|
||
defp button_up_test(page, button, expected_log_prefix) do | ||
refute page | ||
|> visible?(Query.text("#{expected_log_prefix} Up")) | ||
|
||
assert page | ||
|> hover(Query.text("Button 1")) | ||
|> button_down(button) | ||
|> button_up(button) | ||
|> visible?(Query.text("#{expected_log_prefix} Up")) | ||
|
||
refute page | ||
|> visible?(Query.text("#{expected_log_prefix} Down")) | ||
end | ||
|
||
defp move_cursor_then_button_up_test(page, button, expected_log_prefix) do | ||
refute page | ||
|> visible?(Query.text("#{expected_log_prefix} Up")) | ||
|
||
assert page | ||
|> hover(Query.text("Button 1")) | ||
|> button_down(button) | ||
|> hover(Query.text("Button 2")) | ||
|> button_up(button) | ||
|> visible?(Query.text("#{expected_log_prefix} Up")) | ||
|
||
refute page | ||
|> visible?(Query.text("#{expected_log_prefix} Down")) | ||
end | ||
end |
41 changes: 41 additions & 0 deletions
41
integration_test/cases/browser/click_mouse_button_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule Wallaby.Integration.Browser.ClickMouseButtonTest do | ||
use Wallaby.Integration.SessionCase, async: true | ||
|
||
setup %{session: session} do | ||
page = visit(session, "click.html") | ||
|
||
{:ok, %{page: page}} | ||
end | ||
|
||
describe "click/2 for clicking at current mouse position" do | ||
test "clicks left button", %{page: page} do | ||
refute page | ||
|> visible?(Query.text("Left")) | ||
|
||
assert page | ||
|> hover(Query.text("Click")) | ||
|> click(:left) | ||
|> visible?(Query.text("Left")) | ||
end | ||
|
||
test "clicks middle button", %{page: page} do | ||
refute page | ||
|> visible?(Query.text("Middle")) | ||
|
||
assert page | ||
|> hover(Query.text("Click")) | ||
|> click(:middle) | ||
|> visible?(Query.text("Middle")) | ||
end | ||
|
||
test "clicks right button", %{page: page} do | ||
refute page | ||
|> visible?(Query.text("Right")) | ||
|
||
assert page | ||
|> hover(Query.text("Click")) | ||
|> click(:right) | ||
|> visible?(Query.text("Right")) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Wallaby.Integration.Browser.DoubleClickTest do | ||
use Wallaby.Integration.SessionCase, async: true | ||
|
||
setup %{session: session} do | ||
page = visit(session, "click.html") | ||
|
||
{:ok, %{page: page}} | ||
end | ||
|
||
describe "double_click/1" do | ||
test "double-clicks left mouse button at the current cursor position", %{page: page} do | ||
refute page | ||
|> visible?(Query.text("Double")) | ||
|
||
assert page | ||
|> hover(Query.text("Click")) | ||
|> double_click() | ||
|> visible?(Query.text("Double")) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule Wallaby.Integration.Browser.MoveMouseByTest do | ||
use Wallaby.Integration.SessionCase, async: true | ||
import Wallaby.Browser | ||
|
||
setup %{session: session} do | ||
{:ok, page: visit(session, "move_mouse.html")} | ||
end | ||
|
||
describe "move_mouse_by/3" do | ||
test "moves mouse cursor by the given offset from the current position", %{page: page} do | ||
refute page | ||
|> visible?(Query.text("B")) | ||
|
||
assert page | ||
|> hover(Query.text("A")) | ||
|> move_mouse_by(40, 68) | ||
|> visible?(Query.text("B")) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Code.require_file "../tests.exs", __DIR__ | ||
|
||
# Additional test cases supported by selenium | ||
Code.require_file "../cases/browser/double_click_test.exs", __DIR__ | ||
Code.require_file "../cases/browser/hover_test.exs", __DIR__ | ||
Code.require_file "../cases/element/hover_test.exs", __DIR__ | ||
Code.require_file "../cases/browser/move_mouse_by_test.exs", __DIR__ | ||
Code.require_file "../cases/browser/window_handles_test.exs", __DIR__ | ||
Code.require_file "../cases/browser/window_position_test.exs", __DIR__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
|
||
<body> | ||
|
||
<button id="button" ondblclick="doubleClick()" oncontextmenu="event.preventDefault();">Click</button> | ||
<p id="log"></p> | ||
|
||
<script> | ||
function doubleClick() { | ||
document.querySelector('#log').textContent = "Double"; | ||
} | ||
|
||
let button = document.querySelector('#button'); | ||
let log = document.querySelector('#log'); | ||
button.addEventListener('mouseup', logMouseButton); | ||
|
||
function logMouseButton(e) { | ||
if (typeof e === 'object') { | ||
switch (e.button) { | ||
case 0: | ||
log.textContent = 'Left'; | ||
break; | ||
case 1: | ||
log.textContent = 'Middle'; | ||
break; | ||
case 2: | ||
log.textContent = 'Right'; | ||
break; | ||
default: | ||
log.textContent = `Unknown`; | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.