-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): add 'no-get-raw-id' rule
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Warn about using deprecated `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. | ||
|
||
## Rule details | ||
|
||
Any use of the following patterns are considered warnings: | ||
|
||
```js | ||
expect(element(by.id("myid")).getInnerHtml()).toEqual("test"); | ||
expect(element(by.id("myid")).getOuterHtml()).toEqual("test"); | ||
element.all(by.css(".class")).first().getOuterHtml(); | ||
element(by.id("id")).all(by.css(".class")).last().getInnerHtml(); | ||
$$(".class").first().getOuterHtml(); | ||
$(".class").getInnerHtml().then(function (html) { console.log(html) }); | ||
``` | ||
|
||
The following patterns are not warnings: | ||
|
||
```js | ||
expect(element(by.id("myid")).getText()).toEqual("test"); | ||
getInnerHtml(); | ||
var html = getOuterHtml(); | ||
elm.getInnerHTML(); | ||
elm.getOuterHTML(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
/** | ||
* @fileoverview Warn about using `getInnerHtml()` and `getOuterHtml()` methods | ||
* @author Alexander Afanasyev | ||
*/ | ||
|
||
module.exports = { | ||
meta: { | ||
schema: [] | ||
}, | ||
|
||
create: function (context) { | ||
return { | ||
'CallExpression': function (node) { | ||
var object = node.callee.object | ||
var property = node.callee.property | ||
|
||
if (object && property) { | ||
var isInnerHtml = property.name === 'getInnerHtml' | ||
var isOuterHtml = property.name === 'getOuterHtml' | ||
if (isInnerHtml || isOuterHtml) { | ||
context.report({ | ||
node: node, | ||
message: 'Unexpected "' + property.name + '()"' | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict' | ||
|
||
var rule = require('../../lib/rules/no-get-inner-outer-html') | ||
var RuleTester = require('eslint').RuleTester | ||
|
||
var eslintTester = new RuleTester() | ||
|
||
eslintTester.run('no-get-inner-outer-html', rule, { | ||
valid: [ | ||
'expect(element(by.id("myid")).getText()).toEqual("test");', | ||
'getInnerHtml();', | ||
'var html = getOuterHtml();', | ||
'elm.getInnerHTML();', | ||
'elm.getOuterHTML();' | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: 'expect(element(by.id("myid")).getInnerHtml()).toEqual("test");', | ||
errors: [ | ||
{ | ||
message: 'Unexpected "getInnerHtml()"' | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'expect(element(by.id("myid")).getOuterHtml()).toEqual("test");', | ||
errors: [ | ||
{ | ||
message: 'Unexpected "getOuterHtml()"' | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'element.all(by.css(".class")).first().getOuterHtml();', | ||
errors: [ | ||
{ | ||
message: 'Unexpected "getOuterHtml()"' | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'element(by.id("id")).all(by.css(".class")).last().getInnerHtml();', | ||
errors: [ | ||
{ | ||
message: 'Unexpected "getInnerHtml()"' | ||
} | ||
] | ||
}, | ||
{ | ||
code: '$$(".class").first().getOuterHtml();', | ||
errors: [ | ||
{ | ||
message: 'Unexpected "getOuterHtml()"' | ||
} | ||
] | ||
}, | ||
{ | ||
code: '$(".class").getInnerHtml().then(function (html) { console.log(html) });', | ||
errors: [ | ||
{ | ||
message: 'Unexpected "getInnerHtml()"' | ||
} | ||
] | ||
} | ||
] | ||
}) |