由于此错误“无法设置未定义的属性'wrapCompare'”,因此无法执行量角器脚本

时间:2019-04-29 10:49:32

标签: protractor

当我使用量角器执行测试脚本时,它将引发以下错误。 Error: TypeError: Cannot set property 'wrapCompare' of undefined

  

节点版本:6.4.1量角器版本:5.4.2浏览器:   Chrome74.0.3729.108操作系统和Windows版本

Conf.js:

exports.config = {

  //seleniumServerJar: '/usr/local/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.3.1.jar',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  //directConnect: true,

  capabilities: {
    'browserName':'chrome',
    'shardTestFiles': true,
    'maxInstances': 1,
  },

  // Framework to use. Jasmine is recommended.
  framework: 'jasmine',
  specs: ['spec.js'],
  //comment for suite
  // Options to be passed to Jasmine.
  jasmineNodeOpts: {
    defaultTimeoutInterval: 5000000
  }
};

Spec.js

describe('Enter GURU99 Name', function() {
  it('should add a Name as GURU99', function() {
  browser.driver.get('https://angularjs.org/');
  browser.sleep(20000);
  browser.element(by.model('yourName')).sendKeys('GURU99');
  var guru= driver.findElement(by.xpath('html/body/div[2]/div[1]/div[2]/div[2]/div/h1'));
  expect(guru.getText()).toEqual('Hello GURU99!');
  });
 });

跟踪:

15:54:08] E/launcher - Error: TypeError: Cannot set property 'wrapCompare' of undefined
    at Object.<anonymous> (C:\Users\..\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:258:43)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.exports.run (C:\Users\..\AppData\Roaming\npm\node_modules\protractor\built\frameworks\jasmine.js:66:3)
    at q.then.then.then.then (C:\Users\..\AppData\Roaming\npm\node_modules\protractor\built\runner.js:405:43)

3 个答案:

答案 0 :(得分:0)

尝试以下一个

describe('Enter GURU99 Name', function() {
  it('should add a Name as GURU99', async() => {
  await browser.get('https://angularjs.org/');
  await browser.waitForAngularEabled(true);
  await browser.sleep(20000);
  await element(by.model('yourName')).sendKeys('GURU99');
  const guru=element(by.xpath('html/body/div[2]/div[1]/div[2]/div[2]/div/h1'));
  expect(await guru.getText()).toEqual('Hello GURU99!');
  });
 });

如果您在编写测试之前先参考了基本示例测试,那就很好了

请参考https://www.protractortest.org/#/page-objects

答案 1 :(得分:0)

我以某种方式想出了解决方案。实际上问题出在安装上。我已经重新安装了软件包。现在工作正常。

  1. 卸载node.js
  2. 删除节点相关文件夹
  3. 安装node.js
  4. 安装量角器

答案 2 :(得分:0)

我遇到了同样的错误,我再次安装了量角器作为全局配置

sudo npm install -g protractor

它的作用

相关问题