ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript-量角器中的“失败:未定义不是函数”

2019-11-19 21:34:24  阅读:238  来源: 互联网

标签:angularjs protractor end-to-end javascript


我经历过各种职位,但找不到解决方案.

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>

censing.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:

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
  }
};

这是来自终端的日志:

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

第22:19行在posts.first().then(function(postElem){});中指向.

我不了解代码中的错误,因为我已经在堆栈溢出帖子之一中以及通过量角器api指南检查了代码,我们可以将first()链接起来,然后<--这样.谁能帮我这个忙吗?

解决方法:

发生了重大变化.没有element.then() since 2.0.0.

改用:

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

标签:angularjs,protractor,end-to-end,javascript
来源: https://codeday.me/bug/20191119/2039331.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有