简体   繁体   English

'失败:未定义不是量角器中的函数'

[英]'Failed: undefined is not a function' in protractor

I have been through various posts but unable to find a solution. 我已经通过各种帖子但无法找到解决方案。

HTML: HTML:

<div class="col-xs-3" ng-repeat="post in posts track by $index">
    <div class="well">
        <h3 class="postTitle">
            <a ui-sref="singlePost({id:post.id,permalink:post.permalink})">
                {{post.title}}
            </a>
        </h3>
        <h5>By: {{post.author}} | {{post.datePublished}}</h5>
    </div>
</div>

scenario.js: scenario.js:

'use strict';

/* https://github.com/angular/protractor/blob/master/docs/toc.md */

describe('The Single Page Blogger E2E Test', function() {
  var ptor = browser; // browser === protractor.getInstance();
  // ptor.get('/'); //go to http://localhost:8000

  beforeEach(function() {
    ptor.get('app');
  });

 it('Should have 4 posts', function() {
   var posts = element.all(by.repeater('post in posts'));
   expect(posts.count()).toBe(4); // we have 4 hard coded posts
 });

it('Should redirect to #/posts/1/sample-title1', function() {
  var posts = element.all(by.repeater('post in posts'));

  posts.first().then(function(postElem) {
    postElem.findElement(by.tagName('a')).then(function(a) {
      a.click(); //click the title link of 1st post
      expect(ptor.getCurrentUrl()).toMatch('/posts/1/simple-title1');
    });
  });
 });
});

protractor.conf.js: protractor.conf.js:

exports.config = {
  allScriptsTimeout: 11000,

  specs: [
    'specs/*.js'
  ],

  capabilities: {
    'browserName': 'chrome'
  },

  baseUrl: 'http://localhost:8000',

  framework: 'jasmine2',

  jasmineNodeOpts: {
    onComplete: null,
    isVerbose: true,
    showColors: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 30000
  }
};

This is the log from the terminal: 这是来自终端的日志:

angular-seed@0.0.0 preprotractor /var/www/angularjs-seed
npm run update-webdriver


angular-seed@0.0.0 preupdate-webdriver /var/www/angularjs-seed
npm install


angular-seed@0.0.0 postinstall /var/www/angularjs-seed
bower install


angular-seed@0.0.0 update-webdriver /var/www/angularjs-seed
webdriver-manager update

selenium standalone is up to date.
chromedriver is up to date.

angular-seed@0.0.0 protractor /var/www/angularjs-seed
protractor test/e2e-tests/protractor.conf.js

Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://192.168.1.185:38493/wd/hub
Started
.F

Failures:
1) The Single Page Blogger E2E Test Should redirect to #/posts/1/sample-title1
Message:
  Failed: undefined is not a function
Stack:
TypeError: undefined is not a function
    at Object.<anonymous> (/var/www/angularjs-seed/test/e2e-tests/specs/scenarios.js:21:19)
    at runMicrotasksCallback (node.js:337:7)
    at process._tickCallback (node.js:355:11)
From: Task: Run it("Should redirect to #/posts/1/sample-title1") in control flow
    at attemptAsync (/var/www/angularjs-seed/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1819:24)
    at QueueRunner.run (/var/www/angularjs-seed/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1774:9)
    at /var/www/angularjs-seed/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1801:16
    at /var/www/angularjs-seed/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1745:9
    at Array.forEach (native)
From asynchronous test: 
Error
    at Suite.<anonymous> (/var/www/angularjs-seed/test/e2e-tests/specs/scenarios.js:18:3)
    at addSpecsToSuite (/var/www/angularjs-seed/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:743:25)
    at Env.describe (/var/www/angularjs-seed/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:713:7)
    at jasmineInterface.describe (/var/www/angularjs-seed/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:3219:18)
    at Object.<anonymous> (/var/www/angularjs-seed/test/e2e-tests/specs/scenarios.js:5:1)

2 specs, 1 failure
Finished in 1.679 seconds
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1

npm ERR! Linux 3.13.0-62-generic
npm ERR! argv "node" "/usr/local/bin/npm" "run" "protractor"
npm ERR! node v0.12.7
npm ERR! npm  v2.13.4
npm ERR! code ELIFECYCLE
npm ERR! angular-seed@0.0.0 protractor: `protractor test/e2e-tests/protractor.conf.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the angular-seed@0.0.0 protractor script 'protractor test/e2e-tests/protractor.conf.js'.
npm ERR! This is most likely a problem with the angular-seed package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     protractor test/e2e-tests/protractor.conf.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls angular-seed
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/angularjs-seed/npm-debug.log

Line 22:19 points to then in posts.first().then(function(postElem) {}); 线22:19点然后posts.first().then(function(postElem) {}); .

I am not understanding what's the mistake in the code as I have checked in one of the stack overflow posts and also through the protractor api guide that we can chain first().then <-- like this. 我不知道代码中的错误是什么,因为我已经检查了一个堆栈溢出帖子,也通过量角器api指南,我们可以链接first().then < - 像这样。 Can anyone please help me with this? 有人可以帮我这个吗?

There was a breaking change. 有一个突破性的变化。 There is no element.then() since 2.0.0 . 自2.0.0以来没有element.then()

Use instead: 改为使用:

posts.first().element(by.tagName('a')).click();
expect(browser.getCurrentUrl()).toMatch('/posts/1/simple-title1');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM