Skip to content

Commit

Permalink
Merge pull request #32 from DrMarcII/master
Browse files Browse the repository at this point in the history
Change normalization of visibleText with   in HtmlPageLoader
  • Loading branch information
DrMarcII committed Feb 25, 2015
2 parents e959b3f + 1f23e44 commit eabb9fd
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 4 deletions.
28 changes: 27 additions & 1 deletion dart/lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {

// TODO(DrMarcII) consider normalizing string
@override
String get visibleText => _elementText(node).trim();
String get visibleText => _normalize(_elementText(node));

@override
List<HtmlPageLoaderElement> getElementsByCss(String selector) =>
Expand Down Expand Up @@ -487,6 +487,32 @@ String _elementText(n) {
return _elementText(n.nodes);
}

final _nonBreaking = new RegExp(r'^[\S\xa0]$');

String _normalize(String string) {
var skipWS = true;
var addWS = false;
var buffer = new StringBuffer();
for (int i = 0; i < string.length; i++) {
var char = string[i];
if (char.contains(_nonBreaking)) {
if (addWS) {
buffer.write(' ');
}
if (char == '\xa0') {
buffer.write(' ');
} else {
buffer.write(char);
}
skipWS = false;
} else if (!skipWS) {
addWS = true;
skipWS = true;
}
}
return buffer.toString();
}

class _SyncActionClock extends FakeClock {
final SyncActionFn syncActionFn;

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: 1.3.1
version: 1.3.2
author: Google Inc.
description: >
Supports the creation of page objects that can be shared between in-browser tests
Expand Down
3 changes: 2 additions & 1 deletion dart/test/html_no_shadow_dom_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ void main() {
</a-custom-tag>
<a-custom-tag id="button-2">
<button id="inner">some button 2</button>
</a-custom-tag>''';
</a-custom-tag>
<p id="nbsp"> &nbsp; &nbsp; </p>''';

var div = body.querySelectorAll('div[id=testdocument]');
if (div.length == 1) {
Expand Down
3 changes: 2 additions & 1 deletion dart/test/html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ void main() {
</a-custom-tag>
<a-custom-tag id="button-2">
button 2
</a-custom-tag>''';
</a-custom-tag>
<p id="nbsp"> &nbsp; &nbsp; </p>''';

var templateHtml = '<button id="inner">some <content></content></button>';

Expand Down
5 changes: 5 additions & 0 deletions dart/test/page_objects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,8 @@ class PageForTextAreaTypingText {
@ById('textarea')
PageLoaderElement textArea;
}

class PageForNbspTest {
@ById('nbsp')
PageLoaderElement span;
}
6 changes: 6 additions & 0 deletions dart/test/pageloader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ void runTests() {
page.textArea.clear();
expect(page.textArea.attributes['value'], '');
});

solo_test('nbsp in text', () {
PageForNbspTest page = loader.getInstance(PageForNbspTest);
expect(page.span.visibleText, ' ');
expect(page.span.innerText, '');
});
});

group('waitFor()', () {
Expand Down
2 changes: 2 additions & 0 deletions dart/test/webdriver_no_shadow_dom_test_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@
<a-custom-tag id="button-2">
<button id="inner">some button 2</button>
</a-custom-tag>
<p id="nbsp"> &nbsp;
&nbsp; </p>
</body>
</html>
2 changes: 2 additions & 0 deletions dart/test/webdriver_test_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
<a-custom-tag id="button-2">
button 2
</a-custom-tag>
<p id="nbsp"> &nbsp;
&nbsp; </p>
<template id="button-template">
<button id="inner">some <content></content></button>
</template>
Expand Down

0 comments on commit eabb9fd

Please sign in to comment.