Code Monkey home page Code Monkey logo

eslint-plugin-protractor's People

Contributors

alecxe avatar dependabot[bot] avatar dkadrioski13 avatar elrull avatar ext avatar gitter-badger avatar greenkeeperio-bot avatar rayners avatar ricardogobbosouza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eslint-plugin-protractor's Issues

Rule Proposal: recommend baseUrl

This is to warn if absolute URLs are used in browser.get(). Recommend setting baseUrl instead.

Invalid usage:

browser.get("https://google.com/search")

Valid usage:

browser.get("/search")

Unable to check some rules when css path is incomplete or incorrect

For examples, if I have the following locator and css in the page object:

country: this.$homeAddressPendingData.$('[data-e2e="country]')

The missing end quote breaks and prints out error message. I don't think that it is intentional but it is a good feature to have except it doesn't have line number.

It will be great to have a line number when we see breakage like that.

Rule Proposal: Warn if function used for filter() or map() does not have a return

Invalid usage:

element.all(by.css('.items li')).filter(function(elem, index) {
  elem.getText().then(function(text) {
    return text === 'Third';
  });
}).first().click();

Valid usage:

element.all(by.css('.items li')).filter(function(elem, index) {
  return elem.getText().then(function(text) {
    return text === 'Third';
  });
}).first().click();

This needs more real-life samples. Search through SO?..

use-first-last rule not working properly

I am using cucumber with protractor. When I apply use-first-last rule, I am getting the following error msg:

Warning: Cannot read property 'value' of undefined Use --force to continue.

I am not sure what is happening

Warn about the by.xpath usage

According to the Protractor's style guide using the by.xpath() is considered a bad practice. Let's add a warning if by.xpath locator is used.

Rule Proposal: Warn if custom functions are used for browser.wait

It is quite rare there is the need to write a custom function for browser.wait(). Much more often there is an existing Expected Condition for the problem. Sometimes, users just don't know that there is already a condition covering the use case.

Example of a violation:

browser.wait(function () {
    return browser.getCurrentUrl().then(function (url) {
        return url.indexOf("word") >= 0;
    });
}, 5000);

Correct usage:

browser.wait(protractor.ExpectedConditions.urlContains("word"), 5000);

Should probably turn the rule off by default.

Rule Proposal: Warn if "is" Protractor/WebDriverJS methods used inside the if conditions

Example:

if (elm.isDisplayed()) {
    // ...
}

The problem is - isDisplayed() returns promise which itself is always truthy regardless of the real displayedness state. The promise has to be resolved to obtain the real true/false value.

We, of course, cannot cover all the possible problem variations, but can work with simple cases like this. Methods we should support:

  • isDisplayed()
  • isEnabled()
  • isSelected()
  • ...

Rule Proposal: no executeScript

Initially proposed by Florent B. here in comments and I liked the idea as well.

executeScript() and executeAsyncScript() should never appear in specs and page objects and should rather be parts of helper and util modules. This rule would probably require a setting that defines glob patterns for specs and pos.

Rule Proposal: Warn if there are repetitive locators in a page object

Example of a violation:

var MyPage = function () {
   this.grids = element.all(by.css(".mygrid"));
   this.firstGrid = element.all(by.css(".mygrid")).first();
}

Valid version:

var MyPage = function () {
   this.grids = element.all(by.css(".mygrid"));
   this.firstGrid = this.grids.first();
}

Something wrong with `valid-locator-type` rule

See https://travis-ci.org/lucassus/angular-webpack-seed/builds/175647512
and https://github.com/lucassus/angular-webpack-seed/blob/eslint-plugin-protractor-bug/e2e/.eslintrc.json

/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint-plugin-protractor/lib/rules/valid-locator-type.js:60
  return node.arguments && node.arguments[0].type === 'Literal'
                                            ^

TypeError: Cannot read property 'type' of undefined
    at isArgumentLiteral (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint-plugin-protractor/lib/rules/valid-locator-type.js:60:45)
    at EventEmitter.CallExpression (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint-plugin-protractor/lib/rules/valid-locator-type.js:110:37)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at CommentEventGenerator.enterNode (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint/lib/util/comment-event-generator.js:97:23)
    at Controller.enter (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint/lib/eslint.js:925:36)
    at Controller.__execute (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/estraverse/estraverse.js:501:28)
    at Controller.Traverser.controller.traverse (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint/lib/util/traverser.js:36:33)
    at EventEmitter.module.exports.api.verify (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint/lib/eslint.js:922:23)
    at processText (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint/lib/cli-engine.js:264:31)
    at CLIEngine.executeOnText (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/eslint/lib/cli-engine.js:754:26)
    at verify (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/gulp-eslint/index.js:20:25)
    at Transform.util.transform [as _transform] (/Users/lucassus/Projects/OpenSource/angular-webpack-seed/node_modules/gulp-eslint/index.js:70:17)

Rule Proposal: repetitive CSS selectors

This is the follow-up to #25 but specific to CSS selectors (decided to make a separate rule):

Example - the locator of a parent element is repeated for multiple page object fields:

var MyPage = function () {
   this.parent = $(".container #parent");
   this.child1 = $(".container #parent div:first-of-type");
   this.child2 = $(".container #parent #subcontainer > .add-client");
}

The .container #parent part in this case is repeated and should be reused:

var MyPage = function () {
   this.parent = $(".container #parent");
   this.child1 = this.parent.$("div:first-of-type");
   this.child2 = this.parent.$("#subcontainer > .add-client");
}

NOTE: no violation should be reported if a direct parent-child relationship detected after a repetitive part. E.g. .container #parent > div:first-of-type instead of a .container #parent div:first-of-type in the example above

Rule Proposal: Recommend to pass promises to expect() directly if possible

There is a common anti-pattern in Protractor when something is explicitly resolved and then asserted instead of passing a promise directly to expect() which is patched to understand promises and resolve them implicitly before making an expectation.

This should issue a warning:

element(by.css("#myid")).getText().then(function (text) {
    expect(text).toEqual("My Text");
});

This should be used instead:

expect(element(by.css("#myid")).getText()).toEqual("My Text");

I can imagine that this would not of course catch all the violations of the type, but I think, at the very least, the rule should look that the promise resolution functions argument (text in this case) is not then passed to expect()..

Rule Proposal: Recommend using protractor.promise.all

This is to discourage nesting multiple promise resolution functions, e.g.:

elm1.getText().then(function (text1) {
  elm2.getText().then(function (text2) {
    elm3.getText().then(function (text3) {
      elm4.getText().then(function (text4) {
        // do smth with text1, text2, text3, text4
      });
    });
  });
});

Recommend using protractor.promise.all() instead:

protractor.promise.all([
  elm1.getText(),
  elm2.getText(),
  elm3.getText(),
  elm4.getText()
]).then(function (texts) {
   // do smth with texts
});

The rule should probably have the nestedness level configured.

Rule Proposal: Correct chaining

From time to time, I see the incorrect element, element.all chaining like in this topic.

Invalid usage:

var dates = $('#provider_details_view').element.all(by.repeater('repeater name');

Valid usage:

var dates = $('#provider_details_view').all(by.repeater('repeater name');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.