Skip to content

Commit

Permalink
fix(rules): fix 'no-get-inner-outer-html' false positives warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alecxe committed Jun 21, 2017
1 parent 3ede9fa commit 57092ca
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Rule | Default Error Level | Auto-fixable | Options
[no-array-finder-methods][] | 2 | |
[valid-locator-type][] | 2 | |
[no-compound-classes][] | 2 | |
[no-get-inner-outer-html][] | 2 | |
[no-get-raw-id][] | 2 | |
[missing-wait-message][] | 1 (Warning) | |
[no-browser-sleep][] | 1 | |
Expand All @@ -126,7 +127,6 @@ Rule | Default Error Level | Auto-fixable | Options
[no-execute-script][] | 1 | | requires plugin "settings"
[no-repetitive-locators][] | 1 | |
[no-repetitive-selectors][] | 1 | |
[no-get-inner-outer-html][] | 1 | |
[use-count-method][] | 1 | |
[valid-by-id][] | 1 | |
[valid-by-tagname][] | 1 | |
Expand Down
12 changes: 6 additions & 6 deletions docs/rules/no-get-inner-outer-html.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Warn about using deprecated `getInnerHtml()` and `getOuterHtml()` methods
# Warn about using removed `getInnerHtml()` and `getOuterHtml()` methods

Selenium [has deprecated `getInnerHtml()` and `getOuterHtml()` methods in version 2.53](https://github.com/SeleniumHQ/selenium/blob/96ed95a97405fa267eea09c4008cda9e7703e84d/javascript/node/selenium-webdriver/CHANGES.md#change-summary).
And, hence, Protractor itself _does not have these methods documented_ as a part of [public API](http://www.protractortest.org/#/api) anymore.
`Selenium` [has removed `getInnerHtml()` and `getOuterHtml()` methods from the API](https://github.com/SeleniumHQ/selenium/blob/427307d6e24000d7db68e8c36362fab05c477cce/javascript/node/selenium-webdriver/CHANGES.md#api-changes-4).
And, hence, [`Protractor` removed them as well in version 5.0.0](https://github.com/angular/protractor/blob/ea72d5588aef983aa84705abd1ad1afa36065be7/CHANGELOG.md#500).

## Rule details

Any use of the following patterns are considered warnings:
Any use of the following patterns are considered errors:

```js
expect(element(by.id("myid")).getInnerHtml()).toEqual("test");
Expand All @@ -22,6 +22,6 @@ The following patterns are not warnings:
expect(element(by.id("myid")).getText()).toEqual("test");
getInnerHtml();
var html = getOuterHtml();
elm.getInnerHTML();
elm.getOuterHTML();
elm.getInnerHtml();
elm.getOuterHtml();
```
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = {
'protractor/no-get-raw-id': 2,
'protractor/valid-locator-type': 2,
'protractor/no-compound-classes': 2,
'protractor/no-get-inner-outer-html': 2,
'protractor/missing-wait-message': 1,
'protractor/no-browser-sleep': 1,
'protractor/no-by-xpath': 1,
Expand All @@ -101,7 +102,6 @@ module.exports = {
'protractor/no-execute-script': 1,
'protractor/no-repetitive-locators': 1,
'protractor/no-repetitive-selectors': 1,
'protractor/no-get-inner-outer-html': 1,
'protractor/no-angular-attributes': 1,
'protractor/use-count-method': 1,
'protractor/valid-by-id': 1,
Expand Down
15 changes: 7 additions & 8 deletions lib/rules/no-get-inner-outer-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
* @author Alexander Afanasyev
*/

var isElementFinder = require('../is-element-finder')

module.exports = {
meta: {
schema: []
},

create: function (context) {
return {
'CallExpression': function (node) {
var object = node.callee.object
var property = node.callee.property
MemberExpression: function (node) {
var property = node.property

if (object && property) {
var isInnerHtml = property.name === 'getInnerHtml'
var isOuterHtml = property.name === 'getOuterHtml'
if (isInnerHtml || isOuterHtml) {
if (property && (property.name === 'getInnerHtml' || property.name === 'getOuterHtml')) {
if (node.object && isElementFinder(node.object)) {
context.report({
node: node,
node: property,
message: 'Unexpected "' + property.name + '()"'
})
}
Expand Down
12 changes: 10 additions & 2 deletions test/rules/no-get-inner-outer-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ eslintTester.run('no-get-inner-outer-html', rule, {
'expect(element(by.id("myid")).getText()).toEqual("test");',
'getInnerHtml();',
'var html = getOuterHtml();',
'elm.getInnerHTML();',
'elm.getOuterHTML();'
'elm.getInnerHtml();',
'elm.getOuterHtml();'
],

invalid: [
Expand All @@ -31,6 +31,14 @@ eslintTester.run('no-get-inner-outer-html', rule, {
}
]
},
{
code: 'element.all(by.css(".class")).get(1).getOuterHtml();',
errors: [
{
message: 'Unexpected "getOuterHtml()"'
}
]
},
{
code: 'element.all(by.css(".class")).first().getOuterHtml();',
errors: [
Expand Down
2 changes: 1 addition & 1 deletion test/rules/no-get-raw-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ eslintTester.run('no-get-raw-id', rule, {
'getRawId();',
'var html = getRawId();',
'elm.getRawId();',
'elm.getOuterHTML();'
'elm.getOuterHtml();'
],

invalid: [
Expand Down

0 comments on commit 57092ca

Please sign in to comment.