Skip to content

Commit

Permalink
Merge pull request #76 from trinarytree/add_annotation
Browse files Browse the repository at this point in the history
Add FirstByCss finder to help support recursively defined components.
  • Loading branch information
goderbauer authored Jul 22, 2016
2 parents 15a9cc3 + f58c2d8 commit 6bae14a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 14 additions & 2 deletions dart/async/lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<PageLoaderElement> findElements(PageLoaderElement context) =>
super.findElements(context).take(1);
}

class ByClass implements Finder {
final String _class;

Expand Down Expand Up @@ -183,8 +194,9 @@ 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
/// 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;
Expand Down
14 changes: 13 additions & 1 deletion dart/async/test/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ void runTests() {
await verifyRows(table.rows);
});

test('FirstByCss', () async {
PageForFirstByCssTest page =
await loader.getInstance(PageForFirstByCssTest);
expect(await page.element.visibleText, 'r1c1');
});

test('WithAttribute', () async {
PageForWithAttributeTest page =
await loader.getInstance(PageForWithAttributeTest);
Expand All @@ -44,7 +50,7 @@ void runTests() {
});

test(
'chain',
'Chain',
() async {
PageForChainTest page = await loader.getInstance(PageForChainTest);

Expand Down Expand Up @@ -75,6 +81,12 @@ class TableForEnsureTag {
List<Row> rows;
}

@FirstByCss('td')
class PageForFirstByCssTest {
@root
PageLoaderElement element;
}

class PageForWithAttributeTest {
@ByTagName('input')
@WithAttribute('type', 'checkbox')
Expand Down

0 comments on commit 6bae14a

Please sign in to comment.