Skip to content

Commit

Permalink
Merge pull request #21 from DrMarcII/global
Browse files Browse the repository at this point in the history
Add @global annotation.
  • Loading branch information
DrMarcII committed Jan 12, 2015
2 parents 2ab741f + 3cf6870 commit 023eec4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
15 changes: 15 additions & 0 deletions dart/lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,18 @@ class Chain implements Finder {
@override
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;

const Global(this.annotation);

@override
List<PageLoaderElement> findElements(PageLoaderElement context) =>
annotation.findElements(context.loader.globalContext);

@override
String toString() => '@Global($annotation)';
}
2 changes: 1 addition & 1 deletion dart/lib/webdriver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _WebDriverMouse implements PageLoaderMouse {
if (eventTarget == null) {
driver.mouse.up(button);
} else {
_fireEvent(eventTarget, 'mousedown', button);
_fireEvent(eventTarget, 'mouseup', button);
}
}

Expand Down
14 changes: 14 additions & 0 deletions dart/test/page_objects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 10 additions & 5 deletions dart/test/pageloader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand All @@ -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));
});
});

Expand Down

0 comments on commit 023eec4

Please sign in to comment.