From d517fdcc5a9ce7a14a2061741a7b281a54a5ed12 Mon Sep 17 00:00:00 2001 From: Marc Fisher Date: Mon, 12 Jan 2015 09:50:50 -0800 Subject: [PATCH 1/2] Add @Global annotation. Fix bug in PageLoaderMouse.up() for WebDriver with EventTarget. --- dart/lib/src/annotations.dart | 13 +++++++++++++ dart/lib/webdriver.dart | 2 +- dart/test/page_objects.dart | 14 ++++++++++++++ dart/test/pageloader_test.dart | 15 ++++++++++----- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/dart/lib/src/annotations.dart b/dart/lib/src/annotations.dart index 69216064..f380a07f 100644 --- a/dart/lib/src/annotations.dart +++ b/dart/lib/src/annotations.dart @@ -306,3 +306,16 @@ class Chain implements Finder { @override String toString() => '@Chain($_annotations)'; } + +class Global implements Finder { + final Finder annotation; + + const Global(this.annotation); + + @override + List findElements(PageLoaderElement context) => + annotation.findElements(context.loader.globalContext); + + @override + String toString() => '@Global($annotation)'; +} \ No newline at end of file diff --git a/dart/lib/webdriver.dart b/dart/lib/webdriver.dart index fe613bec..9a54d135 100644 --- a/dart/lib/webdriver.dart +++ b/dart/lib/webdriver.dart @@ -86,7 +86,7 @@ class _WebDriverMouse implements PageLoaderMouse { if (eventTarget == null) { driver.mouse.up(button); } else { - _fireEvent(eventTarget, 'mousedown', button); + _fireEvent(eventTarget, 'mouseup', button); } } diff --git a/dart/test/page_objects.dart b/dart/test/page_objects.dart index f344d476..e21e8877 100644 --- a/dart/test/page_objects.dart +++ b/dart/test/page_objects.dart @@ -393,3 +393,17 @@ class PageForMouseTest { @ById('mouse') PageLoaderElement element; } + +class PageForGlobalTest { + + @ByTagName('table') + PageLoaderElement table; + + @ByCss('input[value=radio1]') + NestedPageForGlobalTest nested; +} + +class NestedPageForGlobalTest { + @Global(const ByTagName('table')) + PageLoaderElement table; +} diff --git a/dart/test/pageloader_test.dart b/dart/test/pageloader_test.dart index d467d1d9..4043da19 100644 --- a/dart/test/pageloader_test.dart +++ b/dart/test/pageloader_test.dart @@ -319,13 +319,13 @@ void runTests() { PageForMouseTest page = loader.getInstance(PageForMouseTest); loader.mouse.moveTo(page.element, 2, 2); - expect(page.element.visibleText, contains('MouseMove')); + loader.waitFor(() => page.element.visibleText, contains('MouseMove')); loader.mouse.down(0); - expect(page.element.visibleText, contains('MouseDown')); + loader.waitFor(() => page.element.visibleText, contains('MouseDown')); loader.mouse ..moveTo(page.element, 10, 10) ..up(0); - expect(page.element.visibleText, contains('MouseUp')); + loader.waitFor(() => page.element.visibleText, contains('MouseUp')); }); test('mouse with event target', () { @@ -334,11 +334,16 @@ void runTests() { // 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.waitFor(() => page.element.visibleText, contains('MouseDown')); loader.mouse ..moveTo(page.element, 200, 200) ..up(0, eventTarget: page.element); - expect(page.element.visibleText, contains('MouseUp')); + loader.waitFor(() => page.element.visibleText, contains('MouseUp')); + }); + + test('@Global', () { + PageForGlobalTest page = loader.getInstance(PageForGlobalTest); + expect(page.nested.table, equals(page.table)); }); }); From 3cf68703402ecb83591f0df592faf61eb1fae577 Mon Sep 17 00:00:00 2001 From: Marc Fisher Date: Mon, 12 Jan 2015 09:57:54 -0800 Subject: [PATCH 2/2] Add doc comment to the @Global definition. --- dart/lib/src/annotations.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dart/lib/src/annotations.dart b/dart/lib/src/annotations.dart index f380a07f..cdc719fa 100644 --- a/dart/lib/src/annotations.dart +++ b/dart/lib/src/annotations.dart @@ -307,6 +307,8 @@ class Chain implements Finder { String toString() => '@Chain($_annotations)'; } +/// Evaluates the nested annotation from the global context for the PageLoader +/// instance being used. class Global implements Finder { final Finder annotation;