From 93a03971f2f73c72aa52222909494126af88fe5b Mon Sep 17 00:00:00 2001 From: Marc Fisher II Date: Wed, 28 Jan 2015 11:19:33 -0800 Subject: [PATCH 1/2] Fix .type() method in HtmlPageLoader to work with TextAreaElements. --- dart/lib/html.dart | 10 ++++++---- dart/lib/src/core.dart | 6 +++--- dart/pubspec.yaml | 2 +- dart/test/html_test.dart | 1 + dart/test/page_objects.dart | 5 +++++ dart/test/pageloader_test.dart | 7 +++++++ dart/test/test_page.html | 1 + 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/dart/lib/html.dart b/dart/lib/html.dart index 8e594767..717161c2 100644 --- a/dart/lib/html.dart +++ b/dart/lib/html.dart @@ -27,7 +27,7 @@ import 'dart:mirrors' hide Comment; /// A function that will be executed after [click] and [type] and during /// [waitFor] and [waitForValue] to allow events to be processed. For example -/// if using Angular's async test wrapper this should be function that calls +/// if using Angular's async test wrapper this should be a function that calls /// scope.apply() and clockTick. typedef void SyncActionFn(Duration interval); @@ -242,9 +242,11 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement { void type(String keys) { node.focus(); _fireKeyPressEvents(node, keys); - if (node is InputElement) { - var value = (node as InputElement).value + keys; - (node as InputElement).value = ''; + if (node is InputElement || node is TextAreaElement) { + // suppress warning by hiding field + var node = this.node; + var value = node.value + keys; + node.value = ''; node.dispatchEvent(new TextEvent('textInput', data: value)); } node.blur(); diff --git a/dart/lib/src/core.dart b/dart/lib/src/core.dart index b754f236..bd6871ba 100644 --- a/dart/lib/src/core.dart +++ b/dart/lib/src/core.dart @@ -309,9 +309,9 @@ abstract class _FieldInfo { } if (finder != null) { - var fieldInfo = isList ? - new _FinderListFieldInfo(name, finder, filters, type) : - new _FinderSingleFieldInfo(name, finder, filters, type, isOptional); + var fieldInfo = isList + ? new _FinderListFieldInfo(name, finder, filters, type) + : new _FinderSingleFieldInfo(name, finder, filters, type, isOptional); if (isFunction) { fieldInfo = new _FinderFunctionFieldInfo(fieldInfo); } diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml index 520cb8ec..fdad37f6 100644 --- a/dart/pubspec.yaml +++ b/dart/pubspec.yaml @@ -1,5 +1,5 @@ name: pageloader -version: 1.2.5 +version: 1.2.6 author: Marc Fisher II description: Supports the creation of page objects that can be shared between in-browser tests and WebDriver tests. environment: diff --git a/dart/test/html_test.dart b/dart/test/html_test.dart index 2103c8b2..b5ce9aca 100644 --- a/dart/test/html_test.dart +++ b/dart/test/html_test.dart @@ -57,6 +57,7 @@ void main() { +
outer div 1 diff --git a/dart/test/page_objects.dart b/dart/test/page_objects.dart index d84a8409..02596a0e 100644 --- a/dart/test/page_objects.dart +++ b/dart/test/page_objects.dart @@ -429,3 +429,8 @@ class NestedPageForGlobalTest { @Global(const ByTagName('table')) PageLoaderElement table; } + +class PageForTextAreaTypingText { + @ById('textarea') + PageLoaderElement textArea; +} diff --git a/dart/test/pageloader_test.dart b/dart/test/pageloader_test.dart index f31015c1..0dd86fba 100644 --- a/dart/test/pageloader_test.dart +++ b/dart/test/pageloader_test.dart @@ -346,6 +346,13 @@ void runTests() { PageForGlobalTest page = loader.getInstance(PageForGlobalTest); expect(page.nested.table, equals(page.table)); }); + + test('Type into textarea', () { + PageForTextAreaTypingText page = + loader.getInstance(PageForTextAreaTypingText); + page.textArea.type('some string'); + expect(page.textArea.attributes['value'], 'some string'); + }); }); group('waitFor()', () { diff --git a/dart/test/test_page.html b/dart/test/test_page.html index b0fcfb47..713f6499 100644 --- a/dart/test/test_page.html +++ b/dart/test/test_page.html @@ -50,6 +50,7 @@ +
outer div 1 From 3e32dcaa1dc5a1c20f4f0af788347e57d19770a5 Mon Sep 17 00:00:00 2001 From: Marc Fisher II Date: Thu, 29 Jan 2015 08:51:16 -0800 Subject: [PATCH 2/2] Fix clear method for TextAreaElement. Improve TextAreaElement typing test. --- dart/lib/html.dart | 5 +++-- dart/test/pageloader_test.dart | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/dart/lib/html.dart b/dart/lib/html.dart index 717161c2..cd222bdb 100644 --- a/dart/lib/html.dart +++ b/dart/lib/html.dart @@ -255,8 +255,9 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement { @override void clear() { - if (node is InputElement) { - (node as InputElement).value = ''; + if (node is InputElement || node is TextAreaElement) { + var node = this.node; + node.value = ''; node.dispatchEvent(new TextEvent('textInput', data: '')); } else { super.clear(); diff --git a/dart/test/pageloader_test.dart b/dart/test/pageloader_test.dart index 0dd86fba..0189c99a 100644 --- a/dart/test/pageloader_test.dart +++ b/dart/test/pageloader_test.dart @@ -350,8 +350,12 @@ void runTests() { test('Type into textarea', () { PageForTextAreaTypingText page = loader.getInstance(PageForTextAreaTypingText); - page.textArea.type('some string'); + page.textArea.type('some'); + expect(page.textArea.attributes['value'], 'some'); + page.textArea.type(' string'); expect(page.textArea.attributes['value'], 'some string'); + page.textArea.clear(); + expect(page.textArea.attributes['value'], ''); }); });