From 3909a74811d416d24250e0f250ba2e1ab5044fff Mon Sep 17 00:00:00 2001 From: Chris Calabro Date: Wed, 20 Jul 2016 18:53:36 -0700 Subject: [PATCH 1/3] Add FirstByCss finder to help support recursively defined components. --- dart/async/lib/src/annotations.dart | 13 ++++++++++++- dart/async/test/src/annotations.dart | 14 +++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/dart/async/lib/src/annotations.dart b/dart/async/lib/src/annotations.dart index 2c90b9d1..f66fcdda 100644 --- a/dart/async/lib/src/annotations.dart +++ b/dart/async/lib/src/annotations.dart @@ -95,6 +95,17 @@ class ByCss implements Finder { String toString() => '@ByCss("$_locator")'; } +/// Finds the first matching element, if there is one. +/// +/// Useful to match the root of some component defined recursively. +class FirstByCss extends ByCss { + const FirstByCss(String locator) : super(locator); + + @override + Stream findElements(PageLoaderElement context) => + super.findElements(context).take(1); +} + class ByClass implements Finder { final String _class; @@ -183,7 +194,7 @@ class All implements Finder { } /// Return the elements located by a series of finders and filters running in -/// sequence. For example, @ByChained(finderA, finderB, filterX) will find all +/// sequence. For example, @Chain(finderA, finderB, filterX) will find all /// elements that match B inside an element that matches A and then filter by X. /// Note: this does not de-dup elements. class Chain implements Finder { diff --git a/dart/async/test/src/annotations.dart b/dart/async/test/src/annotations.dart index 0bc9f0e8..9d67c561 100644 --- a/dart/async/test/src/annotations.dart +++ b/dart/async/test/src/annotations.dart @@ -30,6 +30,12 @@ void runTests() { await verifyRows(table.rows); }); + test('FirstByCss', () async { + PageForWithAttributeTest page = + await loader.getInstance(PageForFirstByCssTest); + expect(await page.element.visibleText, 'r1c1'); + }); + test('WithAttribute', () async { PageForWithAttributeTest page = await loader.getInstance(PageForWithAttributeTest); @@ -44,7 +50,7 @@ void runTests() { }); test( - 'chain', + 'Chain', () async { PageForChainTest page = await loader.getInstance(PageForChainTest); @@ -75,6 +81,12 @@ class TableForEnsureTag { List rows; } +@FirstByCss('td') +class PageForFirstByCssTest { + @root + PageLoaderElement element; +} + class PageForWithAttributeTest { @ByTagName('input') @WithAttribute('type', 'checkbox') From ad20f2f0b8b15a238b9e1ef19480cd06cd5424fc Mon Sep 17 00:00:00 2001 From: Chris Calabro Date: Wed, 20 Jul 2016 19:00:11 -0700 Subject: [PATCH 2/3] Fix comment. --- dart/async/lib/src/annotations.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dart/async/lib/src/annotations.dart b/dart/async/lib/src/annotations.dart index f66fcdda..f2ef869e 100644 --- a/dart/async/lib/src/annotations.dart +++ b/dart/async/lib/src/annotations.dart @@ -194,8 +194,9 @@ class All implements Finder { } /// Return the elements located by a series of finders and filters running in -/// sequence. For example, @Chain(finderA, finderB, filterX) will find all -/// elements that match B inside an element that matches A and then filter by X. +/// sequence. For example, @Chain(const [finderA, finderB, filterX]) will find +/// all elements that match B inside an element that matches A and then filter +/// by X. /// Note: this does not de-dup elements. class Chain implements Finder { final List _annotations; From f58c2d805236cc8909b7d3274e5c575a1d022993 Mon Sep 17 00:00:00 2001 From: Chris Calabro Date: Fri, 22 Jul 2016 01:16:51 -0700 Subject: [PATCH 3/3] Fix type error --- dart/async/test/src/annotations.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dart/async/test/src/annotations.dart b/dart/async/test/src/annotations.dart index 9d67c561..cdeef145 100644 --- a/dart/async/test/src/annotations.dart +++ b/dart/async/test/src/annotations.dart @@ -31,7 +31,7 @@ void runTests() { }); test('FirstByCss', () async { - PageForWithAttributeTest page = + PageForFirstByCssTest page = await loader.getInstance(PageForFirstByCssTest); expect(await page.element.visibleText, 'r1c1'); });