Skip to content

Commit

Permalink
Merge pull request #20 from DrMarcII/mouse
Browse files Browse the repository at this point in the history
Add eventTarget to up and down methods on PageLoaderMouse.
  • Loading branch information
DrMarcII committed Jan 10, 2015
2 parents e0fd686 + 170bf3e commit 2ab741f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
16 changes: 11 additions & 5 deletions dart/lib/src/interfaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ abstract class PageLoader {
}

abstract class PageLoaderMouse {
/// Press [button] on the mouse at its current location.
void down(int button);

/// Release [button] on the mouse at its current location.
void up(int button);
/// Press [button] on the mouse at its current location. If [eventTarget} is
/// specified, PageLoader will attempt to fire the corresponding mouse events
/// on that target, otherwise it will fire the events on the target that is
/// under the current mouse location.
void down(int button, {PageLoaderElement eventTarget});

/// Release [button] on the mouse at its current location. If [eventTarget} is
/// specified, PageLoader will attempt to fire the corresponding mouse events
/// on that target, otherwise it will fire the events on the target that is
/// under the current mouse location.
void up(int button, {PageLoaderElement eventTarget});

/// Move the mouse to a location relative to [element].
void moveTo(PageLoaderElement element, int xOffset, int yOffset);
Expand Down
27 changes: 21 additions & 6 deletions dart/lib/webdriver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ class _WebDriverMouse implements PageLoaderMouse {
_WebDriverMouse(this.driver);

@override
void down(int button) {
driver.mouse.down(button);
void down(int button, {_WebElementPageLoaderElement eventTarget}) {
if (eventTarget == null) {
driver.mouse.down(button);
} else {
_fireEvent(eventTarget, 'mousedown', button);
}
}

@override
Expand All @@ -78,8 +82,19 @@ class _WebDriverMouse implements PageLoaderMouse {
}

@override
void up(int button) {
driver.mouse.up(button);
void up(int button, {_WebElementPageLoaderElement eventTarget}) {
if (eventTarget == null) {
driver.mouse.up(button);
} else {
_fireEvent(eventTarget, 'mousedown', button);
}
}

void _fireEvent(_WebElementPageLoaderElement eventTarget, String type,
int button) {
driver.execute(
"arguments[0].dispatchEvent(new MouseEvent(arguments[1], {'button' : arguments[2]}));",
[eventTarget.context, type, button]);
}
}

Expand Down Expand Up @@ -157,8 +172,8 @@ class _WebElementPageLoaderElement extends WebDriverPageLoaderElement {
String get name => context.name;

@override
String get innerText => context.driver.execute(
'return arguments[0].textContent;', [context]).trim();
String get innerText =>
context.driver.execute('return arguments[0].textContent;', [context]).trim();

@override
String get visibleText => context.text;
Expand Down
10 changes: 5 additions & 5 deletions dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: pageloader
version: 1.2.3
version: 1.2.4
author: Marc Fisher II
description: Supports the creation of page objects that can be shared between in-browser tests and WebDriver tests.
environment:
sdk: '>=1.8.0-dev.0.0 <2.0.0'
sdk: '>=1.9.0-dev.2.2 <2.0.0'
dependencies:
sync_webdriver:
path: ../../dart-sync-webdriver
dev_dependencies:
browser: '>=0.10.0+2 <0.11.0'
path: '>=1.3.0 <2.0.0'
unittest: '>=0.11.3 <0.12.0'
browser: '^0.10.0+2'
path: '^1.3.1'
unittest: '^0.11.4'
13 changes: 13 additions & 0 deletions dart/test/pageloader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,19 @@ void runTests() {
..up(0);
expect(page.element.visibleText, contains('MouseUp'));
});

test('mouse with event target', () {
PageForMouseTest page = loader.getInstance(PageForMouseTest);

// make sure mouse is not on element;
loader.mouse.moveTo(page.element, -10, -10);
loader.mouse.down(0, eventTarget: page.element);
expect(page.element.visibleText, contains('MouseDown'));
loader.mouse
..moveTo(page.element, 200, 200)
..up(0, eventTarget: page.element);
expect(page.element.visibleText, contains('MouseUp'));
});
});

group('waitFor()', () {
Expand Down

0 comments on commit 2ab741f

Please sign in to comment.