Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

[Step3] Protractor fail within #status test #142

Closed
@ComFreek

Description

@ComFreek

The tutorial advises to add this code (please don't add the title binding yet):

// test/e2e/scenarios.js
it('should display the current filter value within an element with id "status"',
      function() {
    var statusElement = element(by.id('status'));
    expect(statusElement.getText()).toMatch(/Current filter:\s*$/);

    element(by.model('query')).sendKeys('nexus');

    expect(statusElement.getText()).toMatch(/Current filter: nexus\s*$/);

    //alternative version of the last assertion that tests just the value of the binding
    expect(element(by.binding('query')).getText()).toMatch(/Current filter: nexus\s*$/);
});

// index.html
<div id="status">Current filter: {{query}}</div>

npm run protractor works fine.

However, adding the title binding - as suggested in the tutorial - results in Protractor failing:

// Try commenting out the title and re-running Protractor.
<title ng-bind-template="Google Phone Gallery: {{query}}">Google Phone Gallery</title>

// Note: ensure that you also moved ng-controller from <body> to <html>!
<html ng-app="phonecatApp" ng-controller="PhoneListCtrl">

The error seems to be located in line 39 (the line after the comment beginning with 'alternative') as the output of npm run protractor shows:

comfreek@comfreek-xxx:~/angular/angular-phonecat$ npm run protractor

> angular-phonecat@0.0.0 protractor /home/comfreek/angular/angular-phonecat
> protractor test/protractor-conf.js


------------------------------------
PID: 9540 (capability: chrome #1)
------------------------------------

Using ChromeDriver directly...
.warning: more than one element found for locator by.binding("query")- you may need to be more specific
F

Failures:

  1) PhoneCat App Phone list view should display the current filter value within an element with id "status"
   Message:
     Expected '' to match /Current filter: nexus\s*$/.
   Stacktrace:
     Error: Failed expectation
    at null.<anonymous> (/home/comfreek/angular/angular-phonecat/test/e2e/scenarios.js:39:52)

Finished in 6.252 seconds
2 tests, 6 assertions, 1 failure

[launcher] Runner Process Exited With Error Code: 1

npm ERR! angular-phonecat@0.0.0 protractor: `protractor test/protractor-conf.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the angular-phonecat@0.0.0 protractor script.
npm ERR! This is most likely a problem with the angular-phonecat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     protractor test/protractor-conf.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls angular-phonecat
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.11.0-19-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "run" "protractor"
npm ERR! cwd /home/comfreek/angular/angular-phonecat
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/comfreek/angular/angular-phonecat/npm-debug.log
npm ERR! not ok code 0
comfreek@comfreek-xxx:~/angular/angular-phonecat$ 

After a quick search in Protractor's API doc, I found the following solution:

// change from
expect(element(by.binding('query')).getText()).toMatch(/Current filter: nexus\s*$/);

// to
expect(element.all(by.binding('query')).last().getText()).toMatch(/Current filter: nexus\s*$/);

(Being an Angular beginner, I didn't know whether this solution is the most idiomatic/adequate one for the tutorial. Otherwise I would have provided a pull request.)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions