diff --git a/README.md b/README.md index e36eeff..2577080 100644 --- a/README.md +++ b/README.md @@ -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 | | @@ -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 | | diff --git a/docs/rules/no-get-inner-outer-html.md b/docs/rules/no-get-inner-outer-html.md index b576967..52df98c 100644 --- a/docs/rules/no-get-inner-outer-html.md +++ b/docs/rules/no-get-inner-outer-html.md @@ -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"); @@ -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(); ``` diff --git a/index.js b/index.js index b46746e..b1eb147 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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, diff --git a/lib/rules/no-get-inner-outer-html.js b/lib/rules/no-get-inner-outer-html.js index 55fbfbc..fa794d4 100644 --- a/lib/rules/no-get-inner-outer-html.js +++ b/lib/rules/no-get-inner-outer-html.js @@ -5,6 +5,8 @@ * @author Alexander Afanasyev */ +var isElementFinder = require('../is-element-finder') + module.exports = { meta: { schema: [] @@ -12,16 +14,13 @@ module.exports = { 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 + '()"' }) } diff --git a/test/rules/no-get-inner-outer-html.js b/test/rules/no-get-inner-outer-html.js index af0ece7..157cba7 100644 --- a/test/rules/no-get-inner-outer-html.js +++ b/test/rules/no-get-inner-outer-html.js @@ -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: [ @@ -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: [ diff --git a/test/rules/no-get-raw-id.js b/test/rules/no-get-raw-id.js index de72274..17fd48a 100644 --- a/test/rules/no-get-raw-id.js +++ b/test/rules/no-get-raw-id.js @@ -11,7 +11,7 @@ eslintTester.run('no-get-raw-id', rule, { 'getRawId();', 'var html = getRawId();', 'elm.getRawId();', - 'elm.getOuterHTML();' + 'elm.getOuterHtml();' ], invalid: [