Skip to content

Commit

Permalink
Merge pull request #55 from goderbauer/master
Browse files Browse the repository at this point in the history
add blurAfter parameter to type function
  • Loading branch information
DrMarcII committed Dec 3, 2015
2 parents 57c3312 + 262a420 commit fb43b23
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
20 changes: 12 additions & 8 deletions dart/lib/async/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'dart:svg' show SvgElement;

import 'src/core.dart';
import 'src/interfaces.dart';

export 'src/interfaces.dart';

/// execute [fn] as a separate microtask and return a [Future] that completes
Expand Down Expand Up @@ -178,7 +179,7 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {
@override
String toString() => '$runtimeType<$node>';

Future type(String keys, {bool sync: true}) =>
Future type(String keys, {bool sync: true, bool blurAfter: true}) =>
loader.executeSynced(() => _fireKeyPressEvents(node, keys), sync);

// This doesn't work in Dartium due to:
Expand All @@ -197,7 +198,7 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {
Stream<String> get classes async* {}

@override
Future clear({bool sync: true}) async =>
Future clear({bool sync: true, bool blurAfter: true}) async =>
throw new PageLoaderException('$runtimeType.clear() is unsupported');

@override
Expand Down Expand Up @@ -275,7 +276,8 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement {
}

@override
Future type(String keys, {bool sync: true}) => loader.executeSynced(() async {
Future type(String keys, {bool sync: true, bool blurAfter: true}) =>
loader.executeSynced(() async {
await focus(sync: false);
await _fireKeyPressEvents(node, keys);
if (node is InputElement || node is TextAreaElement) {
Expand All @@ -285,18 +287,19 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement {
await _microtask(() => node.dispatchEvent(new TextEvent('input')));
await _microtask(() => node.dispatchEvent(new TextEvent('change')));
}
return blur(sync: false);
if (blurAfter) await blur(sync: false);
}, sync);

@override
Future clear({bool sync: true}) => loader.executeSynced(() async {
Future clear({bool sync: true, bool blurAfter: true}) =>
loader.executeSynced(() async {
if (node is InputElement || node is TextAreaElement) {
var node = this.node;
await focus(sync: false);
node.value = '';
await _microtask(() => node.dispatchEvent(new TextEvent('input')));
await _microtask(() => node.dispatchEvent(new TextEvent('change')));
return blur(sync: false);
if (blurAfter) await blur(sync: false);
} else {
throw new PageLoaderException('$this does not support clear.');
}
Expand Down Expand Up @@ -335,12 +338,13 @@ class _DocumentPageLoaderElement extends HtmlPageLoaderElement {
Future<bool> get displayed async => true;

@override
Future type(String keys, {bool sync: true}) => loader.executeSynced(() async {
Future type(String keys, {bool sync: true, bool blurAfter: true}) =>
loader.executeSynced(() async {
// TODO(DrMarcII) consider whether this should be sent to
// document.activeElement to more closely match WebDriver behavior.
await _microtask(() => document.body.focus());
await _fireKeyPressEvents(document.body, keys);
return _microtask(() => document.body.blur());
if (blurAfter) await _microtask(() => document.body.blur());
}, sync);
}

Expand Down
4 changes: 2 additions & 2 deletions dart/lib/async/src/interfaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ abstract class PageLoaderElement {

Stream<PageLoaderElement> getElementsByCss(String selector);

Future clear({bool sync: true});
Future clear({bool sync: true, bool blurAfter: true});
Future click({bool sync: true});
Future type(String keys, {bool sync: true});
Future type(String keys, {bool sync: true, bool blurAfter: true});
Future focus({bool sync: true});
Future blur({bool sync: true});
}
Expand Down
17 changes: 10 additions & 7 deletions dart/lib/async/webdriver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:webdriver/core.dart' as wd;

import 'src/core.dart';
import 'src/interfaces.dart';

export 'src/interfaces.dart';

class WebDriverPageLoader extends BasePageLoader {
Expand Down Expand Up @@ -144,15 +145,15 @@ abstract class WebDriverPageLoaderElement implements PageLoaderElement {
Stream<String> get classes async* {}

@override
Future clear({bool sync: true}) async =>
Future clear({bool sync: true, bool blurAfter: true}) async =>
throw new PageLoaderException('$runtimeType.clear() is unsupported');

@override
Future click({bool sync: true}) async =>
throw new PageLoaderException('$runtimeType.click() is unsupported');

@override
Future type(String keys, {bool sync: true}) async =>
Future type(String keys, {bool sync: true, bool blurAfter: true}) async =>
throw new PageLoaderException('$runtimeType.type() is unsupported');

@override
Expand Down Expand Up @@ -222,19 +223,21 @@ class _WebElementPageLoaderElement extends WebDriverPageLoaderElement {
}

@override
Future clear({bool sync: true}) => loader.executeSynced(() async {
Future clear({bool sync: true, bool blurAfter: true}) =>
loader.executeSynced(() async {
await focus(sync: false);
await context.clear();
return blur(sync: false);
if (blurAfter) await blur(sync: false);
}, sync);

@override
Future click({bool sync: true}) => loader.executeSynced(context.click, sync);
@override
Future type(String keys, {bool sync: true}) => loader.executeSynced(() async {
Future type(String keys, {bool sync: true, bool blurAfter: true}) =>
loader.executeSynced(() async {
await focus(sync: false);
await context.sendKeys(keys);
return blur(sync: false);
if (blurAfter) await blur(sync: false);
}, sync);

@override
Expand All @@ -255,7 +258,7 @@ class _WebDriverPageLoaderElement extends WebDriverPageLoaderElement {
@override
Future<String> get name async => '__document__';
@override
Future type(String keys, {bool sync: true}) =>
Future type(String keys, {bool sync: true, bool blurAfter: true}) =>
loader.executeSynced(() => context.keyboard.sendKeys(keys), sync);
@override
Future<bool> get displayed async => true;
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.9
version: 2.0.0-pre.10
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 fb43b23

Please sign in to comment.