Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Counting non-existing elements fails in Protractor 3.2.x #3079

Closed
szimek opened this issue Apr 1, 2016 · 0 comments
Closed

Counting non-existing elements fails in Protractor 3.2.x #3079

szimek opened this issue Apr 1, 2016 · 0 comments

Comments

@szimek
Copy link
Contributor

szimek commented Apr 1, 2016

Bug report

it('should return count for not existing elements', function() {
  browser.get('index.html#/form');
  var parent = element(by.css('not-existing-element'));
  var listItems = parent.all(by.css('li'));

  expect(listItems.count()).toBe(0);
});
  • Output from running the test
1) ElementFinder should return count for not existing elements
  Message:
    Failed: Class constructors cannot be invoked without 'new'
  Stack:
    TypeError: Class constructors cannot be invoked without 'new'
        at Object.NoSuchElementError (/Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/error.js:229:14)
        at /Users/szimek/Projects/src/protractor/built/element.js:343:37
        at Promise.invokeCallback_ (/Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
        at TaskQueue.execute_ (/Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
        at TaskQueue.executeNext_ (/Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
        at /Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
        at /Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
        at process._tickCallback (node.js:412:9)
    From: Task: Run it("should return count for not existing elements") in control flow
        at Object.<anonymous> (/Users/szimek/Projects/src/protractor/node_modules/jasminewd2/index.js:81:14)
        at /Users/szimek/Projects/src/protractor/node_modules/jasminewd2/index.js:18:5
        at Promise.invokeCallback_ (/Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
        at TaskQueue.execute_ (/Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
        at TaskQueue.executeNext_ (/Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
        at /Users/szimek/Projects/src/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
    From asynchronous test:
    Error
        at Suite.<anonymous> (/Users/szimek/Projects/src/protractor/spec/basic/elements_spec.js:7:3)
        at Object.<anonymous> (/Users/szimek/Projects/src/protractor/spec/basic/elements_spec.js:1:1)
        at Module._compile (module.js:413:34)
        at Object.Module._extensions..js (module.js:422:10)
        at Module.load (module.js:357:32)
        at Function.Module._load (module.js:314:12)
  • Steps to reproduce the bug
    1. try to find an element that doesn't exist in DOM and then call e.g. .all(by.css('li')).count() on it

Something like this works fine:

expect(element.all(by.css('not-existing-element li')).count()).toBe(0)

but this:

expect(element(by.css('not-existing-element')).all(by.css('li')).count()).toBe(0)

fails with the error message posted above. In Protractor 3.1.1 both versions worked fine. We're using page objects, so we're quite often chaining element selectors like in the failing example.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants