Skip to content

Commit

Permalink
Merge pull request #56 from goderbauer/addOffset
Browse files Browse the repository at this point in the history
add offset and getBoundingClientRect
  • Loading branch information
goderbauer committed Dec 8, 2015
2 parents fb43b23 + 9cecf59 commit 73c71b6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
16 changes: 16 additions & 0 deletions dart/lib/async/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ library pageloader.async.html;

import 'dart:async';
import 'dart:html';
import 'dart:math';
import 'dart:mirrors' hide Comment;
import 'dart:svg' show SvgElement;

Expand Down Expand Up @@ -197,6 +198,14 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {
@override
Stream<String> get classes async* {}

@override
Future<Rectangle> getBoundingClientRect() => throw new PageLoaderException(
'$runtimeType.getBoundingClientRect() is unsupported');

@override
Future<Rectangle> get offset =>
throw new PageLoaderException('$runtimeType.offset is unsupported');

@override
Future clear({bool sync: true, bool blurAfter: true}) async =>
throw new PageLoaderException('$runtimeType.clear() is unsupported');
Expand Down Expand Up @@ -257,6 +266,13 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement {
@override
Stream<String> get classes => new Stream.fromIterable(node.classes);

@override
Future<Rectangle> getBoundingClientRect() async =>
node.getBoundingClientRect();

@override
Future<Rectangle> get offset async => node.offset;

@override
Future click({bool sync: true}) => loader.executeSynced(() {
if (node is OptionElement) {
Expand Down
4 changes: 4 additions & 0 deletions dart/lib/async/src/interfaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
library pageloader.async.interfaces;

import 'dart:async';
import 'dart:math';

typedef Future<T> SyncedExecutionFn<T>(Future<T> fn());

Expand Down Expand Up @@ -61,6 +62,9 @@ abstract class PageLoaderElement {
Future<bool> get displayed;
Stream<String> get classes;

Future<Rectangle> get offset;
Future<Rectangle> getBoundingClientRect();

Stream<PageLoaderElement> getElementsByCss(String selector);

Future clear({bool sync: true, bool blurAfter: true});
Expand Down
31 changes: 31 additions & 0 deletions dart/lib/async/webdriver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
library pageloader.async.webdriver;

import 'dart:async';
import 'dart:math';

import 'package:webdriver/core.dart' as wd;

Expand Down Expand Up @@ -144,6 +145,14 @@ abstract class WebDriverPageLoaderElement implements PageLoaderElement {
@override
Stream<String> get classes async* {}

@override
Future<Rectangle> getBoundingClientRect() => throw new PageLoaderException(
'$runtimeType.getBoundingClientRect() is unsupported');

@override
Future<Rectangle> get offset =>
throw new PageLoaderException('$runtimeType.offset is unsupported');

@override
Future clear({bool sync: true, bool blurAfter: true}) async =>
throw new PageLoaderException('$runtimeType.clear() is unsupported');
Expand Down Expand Up @@ -222,6 +231,28 @@ class _WebElementPageLoaderElement extends WebDriverPageLoaderElement {
}
}

@override
Future<Rectangle> getBoundingClientRect() async {
var rect = await context.driver
.execute('return arguments[0].getBoundingClientRect();', [context]);
return new Rectangle(
rect['left'], rect['top'], rect['width'], rect['height']);
}

@override
Future<Rectangle> get offset async {
var rect = await context.driver.execute(
'''return {
left: arguments[0].offsetLeft,
top: arguments[0].offsetTop,
width: arguments[0].offsetWidth,
height: arguments[0].offsetHeight
}''',
[context]);
return new Rectangle(
rect['left'], rect['top'], rect['width'], rect['height']);
}

@override
Future clear({bool sync: true, bool blurAfter: true}) =>
loader.executeSynced(() async {
Expand Down
2 changes: 1 addition & 1 deletion dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pageloader
version: 2.0.0-pre.10
version: 2.0.0-pre.11
author: Marc Fisher II <[email protected]>
description: >
Supports the creation of page objects that can be shared between in-browser tests
Expand Down

0 comments on commit 73c71b6

Please sign in to comment.