Skip to content

Commit

Permalink
Add new seleniumAttributes getter. (#89)
Browse files Browse the repository at this point in the history
- deprecate attributes getter.
- change all uses of attributes to seleniumAttributes.
  • Loading branch information
DrMarcII authored and staats-google committed Jan 11, 2017
1 parent 3caad83 commit 88f669a
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 55 deletions.
16 changes: 12 additions & 4 deletions dart/async/lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,12 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {
}

@override
@deprecated
PageLoaderAttributes get attributes => new _EmptyAttributes();

@override
PageLoaderAttributes get seleniumAttributes => new _EmptyAttributes();

@override
Future<bool> get isFocused async => document.activeElement == node;

Expand Down Expand Up @@ -249,13 +253,13 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {

class _ElementPageLoaderElement extends HtmlPageLoaderElement {
final Element node;
final PageLoaderAttributes attributes;
final PageLoaderAttributes seleniumAttributes;
final PageLoaderAttributes computedStyle;
final PageLoaderAttributes style;

_ElementPageLoaderElement(Element _node, HtmlPageLoader loader)
: this.node = _node,
this.attributes = new _ElementAttributes(_node),
this.seleniumAttributes = new _ElementSeleniumAttributes(_node),
this.computedStyle = new _ElementComputedStyle(_node),
this.style = new _ElementStyle(_node),
super._(loader);
Expand All @@ -271,6 +275,10 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement {
return this;
}

@deprecated
@override
PageLoaderAttributes get attributes => seleniumAttributes;

@override
Future<String> get name async => node.tagName.toLowerCase();
// TODO(DrMarcII): implement this to recurse up the tree to see if displayed
Expand Down Expand Up @@ -388,7 +396,7 @@ class _DocumentPageLoaderElement extends HtmlPageLoaderElement {
}, sync);
}

class _ElementAttributes extends PageLoaderAttributes {
class _ElementSeleniumAttributes extends PageLoaderAttributes {
static const _BOOLEAN_ATTRIBUTES = const [
'async',
'autofocus',
Expand Down Expand Up @@ -435,7 +443,7 @@ class _ElementAttributes extends PageLoaderAttributes {

final Element _node;

_ElementAttributes(this._node);
_ElementSeleniumAttributes(this._node);

/// Based on algorithm from:
/// https://dvcs.w3.org/hg/webdriver/raw-file/a9916dddac01/webdriver-spec.html#get-id-attribute
Expand Down
23 changes: 22 additions & 1 deletion dart/async/lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ class IsDisplayed extends ElementFilter {

/// Keeps only [PageLoaderElement]s that have the given attribute with the
/// given value.
///
/// Deprecated: use WithSeleniumAttribute instead.
@deprecated
class WithAttribute extends ElementFilter {
final String _attribute;
final String _value;
Expand All @@ -269,11 +272,29 @@ class WithAttribute extends ElementFilter {

@override
Future<bool> keep(PageLoaderElement element) async =>
(await element.attributes[_attribute]) == _value;
(await element.seleniumAttributes[_attribute]) == _value;

String toString() => '@WithAttribute($_attribute, $_value)';
}

/// Keeps only [PageLoaderElement]s that have the given attribute with the
/// given value.
///
/// Note: this is primarily inteaded for transition to separate WithAttribute
/// WithProperty Filters that differentiate between attributes/properties.
class WithSeleniumAttribute extends ElementFilter {
final String _attribute;
final String _value;

const WithSeleniumAttribute(this._attribute, this._value);

@override
Future<bool> keep(PageLoaderElement element) async =>
(await element.seleniumAttributes[_attribute]) == _value;

String toString() => '@WithSeleniumAttribute($_attribute, $_value)';
}

/// Keeps only [PageLoaderElement]s that correspond to the given tag.
class IsTag extends ElementFilter {
final String _name;
Expand Down
10 changes: 10 additions & 0 deletions dart/async/lib/src/interfaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,18 @@ abstract class PageLoaderElement {
Future<String> get name;

/// Attributes associated with this element.
///
/// Deprecated: Use seleniumAttributes
@deprecated
PageLoaderAttributes get attributes;

/// Attributes/properties associated with this element. This corresponds to the Selenium
/// WebDriver's get attribute endpoint.
///
/// Note: this intended primarily for transition to new attributes/properties implementations
/// that will accurately distinguish between attributes and properties.
PageLoaderAttributes get seleniumAttributes;

/// CSS properties of this element after applying the active stylesheets and
/// resolving any basic computation, such as converting a percentage into an
/// absolute length.
Expand Down
16 changes: 12 additions & 4 deletions dart/async/lib/webdriver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ abstract class WebDriverPageLoaderElement implements PageLoaderElement {
String toString() => '$runtimeType<${context.toString()}>';

@override
@deprecated
PageLoaderAttributes get attributes => new _EmptyAttributes();

@override
PageLoaderAttributes get seleniumAttributes => new _EmptyAttributes();

@override
Future<bool> get isFocused async {
if (context is wd.WebElement) {
Expand Down Expand Up @@ -206,14 +210,14 @@ abstract class WebDriverPageLoaderElement implements PageLoaderElement {

class _WebElementPageLoaderElement extends WebDriverPageLoaderElement {
final wd.WebElement context;
final PageLoaderAttributes attributes;
final PageLoaderAttributes seleniumAttributes;
final PageLoaderAttributes computedStyle;
final PageLoaderAttributes style;

_WebElementPageLoaderElement(
wd.WebElement _context, WebDriverPageLoader loader)
: this.context = _context,
this.attributes = new _ElementAttributes(_context),
this.seleniumAttributes = new _ElementSeleniumAttributes(_context),
this.computedStyle = new _ElementComputedStyle(_context),
this.style = new _ElementStyle(_context),
super._(loader);
Expand All @@ -233,6 +237,10 @@ class _WebElementPageLoaderElement extends WebDriverPageLoaderElement {
@override
Future<String> get name => context.name;

@override
@deprecated
PageLoaderAttributes get attributes => seleniumAttributes;

@override
Future<String> get innerText async => (await context.driver
.execute('return arguments[0].textContent;', [context]))
Expand Down Expand Up @@ -365,10 +373,10 @@ class _ShadowRootPageLoaderElement extends WebDriverPageLoaderElement {
}
}

class _ElementAttributes extends PageLoaderAttributes {
class _ElementSeleniumAttributes extends PageLoaderAttributes {
final wd.WebElement _node;

_ElementAttributes(this._node);
_ElementSeleniumAttributes(this._node);

@override
Future<String> operator [](String name) => _node.attributes[name];
Expand Down
14 changes: 7 additions & 7 deletions dart/async/test/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ void runTests() {
expect(await page.element.visibleText, 'r1c1');
});

test('WithAttribute', () async {
PageForWithAttributeTest page =
await loader.getInstance(PageForWithAttributeTest);
expect(await page.element.attributes['type'], 'checkbox');
test('WithSeleniumAttribute', () async {
PageForWithSeleniumAttributeTest page =
await loader.getInstance(PageForWithSeleniumAttributeTest);
expect(await page.element.seleniumAttributes['type'], 'checkbox');
});

test('WithClass', () async {
var page = await loader.getInstance(PageForWithClassTest);
expect(await page.element.attributes['type'], 'checkbox');
expect(await page.element.seleniumAttributes['type'], 'checkbox');
expect(await page.element.classes.toList(),
unorderedEquals(['with-class-test', 'class1', 'class2']));
});
Expand Down Expand Up @@ -87,9 +87,9 @@ class PageForFirstByCssTest {
PageLoaderElement element;
}

class PageForWithAttributeTest {
class PageForWithSeleniumAttributeTest {
@ByTagName('input')
@WithAttribute('type', 'checkbox')
@WithSeleniumAttribute('type', 'checkbox')
PageLoaderElement element;
}

Expand Down
56 changes: 28 additions & 28 deletions dart/async/test/src/attributes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,86 +33,86 @@ void runTests() {

test('checked', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.checkbox.attributes['checked'], isNull);
expect(await page.checkbox.seleniumAttributes['checked'], isNull);
await page.checkbox.click();
expect(await page.checkbox.attributes['checked'], 'true');
expect(await page.checkbox.seleniumAttributes['checked'], 'true');
});

test('disabled', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.readOnly.attributes['disabled'], 'true');
expect(await page.text.attributes['disabled'], isNull);
expect(await page.readOnly.seleniumAttributes['disabled'], 'true');
expect(await page.text.seleniumAttributes['disabled'], isNull);
});

test('not a property', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(
await page.table.attributes['non-standard'], 'a non standard attr');
await page.table.seleniumAttributes['non-standard'], 'a non standard attr');
});

test('option values', () async {
var page = await loader.getInstance(PageForAttributesTests);
// The expects below are according to the WebDriver spec, but currently
// fail
// expect(page.option1.attributes['value'], 'option 1');
// expect(page.option1.attributes['VaLuE'], 'option 1');
expect(await page.option2.attributes['value'], 'value 2');
expect(await page.option2.attributes['VaLuE'], 'value 2');
// expect(page.option1.seleniumAttributes['value'], 'option 1');
// expect(page.option1.seleniumAttributes['VaLuE'], 'option 1');
expect(await page.option2.seleniumAttributes['value'], 'value 2');
expect(await page.option2.seleniumAttributes['VaLuE'], 'value 2');
});

test('option selected', () async {
var page = await loader.getInstance(PageForAttributesTests);
await page.option2.click();
expect(await page.select1.attributes['value'], equals('value 2'));
expect(await page.select1.seleniumAttributes['value'], equals('value 2'));
});

test('selected on checkbox', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.checkbox.attributes['selected'], isNull);
expect(await page.checkbox.attributes['SeLeCtEd'], isNull);
expect(await page.checkbox.seleniumAttributes['selected'], isNull);
expect(await page.checkbox.seleniumAttributes['SeLeCtEd'], isNull);
await page.checkbox.click();
expect(await page.checkbox.attributes['selected'], 'true');
expect(await page.checkbox.attributes['SeLeCtEd'], 'true');
expect(await page.checkbox.seleniumAttributes['selected'], 'true');
expect(await page.checkbox.seleniumAttributes['SeLeCtEd'], 'true');
});

test('selected on radio', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.radio.attributes['selected'], isNull);
expect(await page.radio.attributes['SeLeCtEd'], isNull);
expect(await page.radio.seleniumAttributes['selected'], isNull);
expect(await page.radio.seleniumAttributes['SeLeCtEd'], isNull);
await page.radio.click();
expect(await page.radio.attributes['selected'], 'true');
expect(await page.radio.attributes['SeLeCtEd'], 'true');
expect(await page.radio.seleniumAttributes['selected'], 'true');
expect(await page.radio.seleniumAttributes['SeLeCtEd'], 'true');
});

test('href on a', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.anchor.attributes['href'], endsWith('/test.html'));
expect(await page.anchor.seleniumAttributes['href'], endsWith('/test.html'));
});

test('src on img', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.img.attributes['src'], endsWith('/test.png'));
expect(await page.img.seleniumAttributes['src'], endsWith('/test.png'));
});

test('class/className', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.table.attributes['class'], 'class1 class2 class3');
expect(await page.table.attributes['className'], 'class1 class2 class3');
expect(await page.table.seleniumAttributes['class'], 'class1 class2 class3');
expect(await page.table.seleniumAttributes['className'], 'class1 class2 class3');
});

test('readonly/readOnly', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.readOnly.attributes['readonly'], 'true');
expect(await page.readOnly.attributes['readOnly'], 'true');
expect(await page.text.attributes['readonly'], isNull);
expect(await page.text.attributes['readOnly'], isNull);
expect(await page.readOnly.seleniumAttributes['readonly'], 'true');
expect(await page.readOnly.seleniumAttributes['readOnly'], 'true');
expect(await page.text.seleniumAttributes['readonly'], isNull);
expect(await page.text.seleniumAttributes['readOnly'], isNull);
});

test('value on text', () async {
var page = await loader.getInstance(PageForAttributesTests);
expect(await page.text.attributes['value'], '');
expect(await page.text.seleniumAttributes['value'], '');
await page.text.type('some text');
expect(await page.text.attributes['value'], 'some text');
expect(await page.text.seleniumAttributes['value'], 'some text');
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions dart/async/test/src/html_pageloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void runTests() {
node.onInput.listen((event) {
handlerCalled.complete(true);
});
expect(await page.text.attributes['value'], '');
expect(await page.text.seleniumAttributes['value'], '');
await page.text.type('some text');
expect(await page.text.attributes['value'], 'some text');
expect(await page.text.seleniumAttributes['value'], 'some text');
expect(await handlerCalled.future, isTrue);
});

Expand Down
18 changes: 9 additions & 9 deletions dart/async/test/src/typing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ void runTests() {
PageForTextAreaTypingText page =
await loader.getInstance(PageForTextAreaTypingText);
await page.textArea.type('some');
expect(await page.textArea.attributes['value'], 'some');
expect(await page.textArea.seleniumAttributes['value'], 'some');
await page.textArea.type(' string');
expect(await page.textArea.attributes['value'], 'some string');
expect(await page.textArea.seleniumAttributes['value'], 'some string');
await page.textArea.clear();
expect(await page.textArea.attributes['value'], '');
expect(await page.textArea.seleniumAttributes['value'], '');
});

test('typing should append', () async {
PageForTypingTests page = await loader.getInstance(PageForTypingTests);
expect(await page.text.attributes['value'], '');
expect(await page.text.seleniumAttributes['value'], '');
await page.text.type('some text');
expect(await page.text.attributes['value'], 'some text');
expect(await page.text.seleniumAttributes['value'], 'some text');
await page.text.type(' and more text');
expect(await page.text.attributes['value'], 'some text and more text');
expect(await page.text.seleniumAttributes['value'], 'some text and more text');
});

test('value after clear', () async {
PageForTypingTests page = await loader.getInstance(PageForTypingTests);
expect(await page.text.attributes['value'], '');
expect(await page.text.seleniumAttributes['value'], '');
await page.text.type('some text');
expect(await page.text.attributes['value'], 'some text');
expect(await page.text.seleniumAttributes['value'], 'some text');
await page.text.clear();
expect(await page.text.attributes['value'], '');
expect(await page.text.seleniumAttributes['value'], '');
});
});
}
Expand Down

0 comments on commit 88f669a

Please sign in to comment.