Skip to content

Commit

Permalink
Merge pull request #38 from DrMarcII/master
Browse files Browse the repository at this point in the history
More minor cleanup.
  • Loading branch information
DrMarcII committed Apr 10, 2015
2 parents 302a286 + 13b2083 commit d462f9f
Show file tree
Hide file tree
Showing 25 changed files with 1,371 additions and 1,210 deletions.
23 changes: 13 additions & 10 deletions dart/lib/async/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,16 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {
factory HtmlPageLoaderElement(Node node, HtmlPageLoader loader) {
if (node is Element) {
return new _ElementPageLoaderElement(node, loader);
} else if (node is Document) {
}
if (node is Document) {
return new _DocumentPageLoaderElement(node, loader);
} else if (node is ShadowRoot) {
}
if (node is ShadowRoot) {
if (loader.useShadowDom) {
return new _ShadowRootPageLoaderElement(node, loader);
} else {
throw new PageLoaderException(
'Cannot create element for ShadowRoot when useShadowDom is false');
}
throw new PageLoaderException(
'Cannot create element for ShadowRoot when useShadowDom is false');
}
throw new PageLoaderException(
'Unable to create PageLoaderElement for $node');
Expand Down Expand Up @@ -208,7 +209,7 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {

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

@override
PageLoaderAttributes get style => new _EmptyAttributes();
Expand All @@ -230,10 +231,12 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement {
@override
Future<PageLoaderElement> get shadowRoot async {
if (loader.useShadowDom) {
return new HtmlPageLoaderElement(node.shadowRoot, loader);
} else {
return this;
if (node.shadowRoot != null) {
return new HtmlPageLoaderElement(node.shadowRoot, loader);
}
throw new PageLoaderException('$this does not have a shadowRoot');
}
return this;
}

@override
Expand Down Expand Up @@ -283,7 +286,7 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement {
node.value = '';
node.dispatchEvent(new TextEvent('textInput', data: ''));
} else {
super.clear();
throw new PageLoaderException('$this does not support clear.');
}
await loader.sync();
}
Expand Down
4 changes: 3 additions & 1 deletion dart/lib/async/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class _Optional {
String toString() => '@optional';
}

/// Used to annotate PageLoader-type fields that should have the instance of PageLoader
/// injected.
const inject = const _Inject();
class _Inject {
const _Inject();
Expand All @@ -38,7 +40,7 @@ class _Inject {
String toString() => '@inject';
}

/// By default PageLoader ensure that all elements are displayed.
/// By default PageLoader ensures that all elements are displayed.
/// Adding @disableDisplayedCheck to an annotated field or class will disable this check from this
/// point onwards.
const disableDisplayedCheck = const _DisableDisplayedCheck();
Expand Down
4 changes: 4 additions & 0 deletions dart/lib/async/src/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class _ClassInfo {
'${type.simpleName} has Filter annotations but no Finder annotation');
}
}
if (finder == root && filters.isEmpty) {
throw new PageLoaderException(
'Useless @root annotation of ${type.simpleName}');
}

return new _ClassInfo._(
type, _fieldInfos(type), finder, filters, displayCheck);
Expand Down
12 changes: 8 additions & 4 deletions dart/lib/async/webdriver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ abstract class WebDriverPageLoaderElement implements PageLoaderElement {
wd.SearchContext context, WebDriverPageLoader loader) {
if (context is wd.WebDriver) {
return new _WebDriverPageLoaderElement(context, loader);
} else if (context is wd.WebElement) {
}
if (context is wd.WebElement) {
return new _WebElementPageLoaderElement(context, loader);
}
throw new PageLoaderException(
Expand Down Expand Up @@ -171,10 +172,13 @@ class _WebElementPageLoaderElement extends WebDriverPageLoaderElement {
@override
Future<WebDriverPageLoaderElement> get shadowRoot async {
if (loader.useShadowDom) {
return new _ShadowRootPageLoaderElement(context, loader);
} else {
return this;
if ((await context.driver.execute(
'arguments[0].shadowRoot != null', [context]))) {
return new _ShadowRootPageLoaderElement(context, loader);
}
throw new PageLoaderException('$this does not have a shadowRoot');
}
return this;
}

@override
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.1
version: 2.0.0-pre.2
author: Google, Inc.
description: >
Supports the creation of page objects that can be shared between in-browser tests
Expand Down
117 changes: 6 additions & 111 deletions dart/test/async/html_no_shadow_dom_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,132 +13,27 @@
library pageloader.async.test.html_no_shadow_dom;

import 'dart:async';
import 'dart:html' as html;

import 'package:pageloader/async/html.dart';
import 'package:unittest/html_enhanced_config.dart'
show useHtmlEnhancedConfiguration;
import 'package:unittest/unittest.dart';

import 'page_objects.dart';
import '../data/html_no_shadow_dom_setup.dart' as html_setup;
import 'pageloader_test.dart' as plt;
import 'src/html_test.dart' as html_test;
import 'src/shared.dart' as shared;

void main() {
useHtmlEnhancedConfiguration();

setUp(() {
var body = html.document.getElementsByTagName('body').first;
const bodyHtml = '''
<style>
.class1 { background-color: #00FF00; }
</style>
<table id='table1' non-standard='a non standard attr'
class='class1 class2 class3' style='color: #800080;'>
<tr>
<td>r1c1</td>
<td>r1c2</td>
</tr>
<tr>
<td>r2c1</td>
<td>r2c2</td>
</tr>
</table>
<div id='div' style='display: none; background-color: red;'>
some not displayed text</div>
<div id='mouse'>area for mouse events</div>
<input type='text' id='text' />
<input type='text' readonly id='readonly' disabled />
<input type='checkbox' class='with-class-test class1 class2' />
<input type='radio' name='radio' value='radio1' />
<input type='radio' name='radio' value='radio2' />
<a href="test.html" id="anchor">test</a>
<img src="test.png">
<select id='select1'>
<option id='option1' value='value 1'>option 1</option>
<option id='option2' value='value 2'>option 2</option>
</select>
<textarea id='textarea'></textarea>
<div class="outer-div">
outer div 1
<a-custom-tag><button id="inner">some </button></a-custom-tag>
</div>
<div class="outer-div">
outer div 2
<div class="inner-div">
inner div 1
</div>
<div class="inner-div special">
inner div 2
</div>
</div>
<a-custom-tag id="button-1">
<button id="inner">some button 1</button>
</a-custom-tag>
<a-custom-tag id="button-2">
<button id="inner">some button 2</button>
</a-custom-tag>
<p id="nbsp"> &nbsp; &nbsp; </p>''';

var div = body.querySelectorAll('div[id=testdocument]');
if (div.length == 1) {
div = div[0];
} else {
div = new html.DivElement();
div.id = 'testdocument';
body.append(div);
}
div.setInnerHtml(bodyHtml, validator: new NoOpNodeValidator());

var displayedDiv = html.document.getElementById('mouse');
displayedDiv.onMouseDown.listen((evt) {
displayedDiv.text = displayedDiv.text +
" MouseDown: ${evt.client.x}, ${evt.client.y}; "
"${evt.screen.x}, ${evt.screen.y}";
});
displayedDiv.onMouseUp.listen((evt) {
displayedDiv.text = displayedDiv.text +
" MouseUp: ${evt.client.x}, ${evt.client.y}; "
"${evt.screen.x}, ${evt.screen.y}";
});
displayedDiv.onMouseMove.listen((evt) {
displayedDiv.text = displayedDiv.text +
" MouseMove: ${evt.client.x}, ${evt.client.y}; "
"${evt.screen.x}, ${evt.screen.y}";
});

plt.loader = new HtmlPageLoader(div, syncFn, useShadowDom: false);
});

group('html specific tests', () {
test('value on text', () async {
var page = await plt.loader.getInstance(PageForAttributesTests);
var handlerCalled = new Completer<bool>();
var node = (page.text as HtmlPageLoaderElement).node as html.InputElement;
node.onInput.listen((event) {
handlerCalled.complete(true);
});
expect(await page.text.attributes['value'], '');
await page.text.type('some text');
expect(await page.text.attributes['value'], 'some text');
expect(await handlerCalled.future, isTrue);
});

test('keypress events', () async {
var data = 'my data';
var list = [];
html.document.body.onKeyPress.listen((evt) => list.add(evt.charCode));
await plt.loader.globalContext.type(data);
expect(new String.fromCharCodes(list), equals(data));
});
var div = html_setup.setUp();
shared.loader = new HtmlPageLoader(div, syncFn, useShadowDom: false);
});

plt.runTests();
}

class NoOpNodeValidator implements html.NodeValidator {
bool allowsAttribute(
html.Element element, String attributeName, String value) => true;
bool allowsElement(html.Element element) => true;
html_test.runTests();
}

Future syncFn() async {
Expand Down
Loading

0 comments on commit d462f9f

Please sign in to comment.