2

我是量角器的新手。我按照https://www.protractortest.org/#/中提到的步骤 运行命令 protractor conf.js 时,浏览器会立即打开和关闭。我在命令行中收到以下错误:

[22:41:08] E/launcher - 进程退出,错误代码 100

我尝试通过在 conf.js 中添加功能在 Firefox 中执行

文件内容:

规范.js

import { element } from "protractor";

describe('angularjs homepage todo list', function() {
  it('should add a todo', async function() {
    await browser.get('https://angularjs.org');

    await element(by.model('todoList.todoText')).sendKeys('write first protractor test');
    await element(by.css('[value="add"]')).click();

    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(await todoList.count()).toEqual(3);
    expect(await todoList.get(2).getText()).toEqual('write first protractor test');

    // You wrote your first test, cross it off the list
    await todoList.get(2).element(by.css('input')).click();
    var completedAmount = element.all(by.css('.done-true'));
    expect(await completedAmount.count()).toEqual(2);
  });
});

conf.js

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['spec.js'],
    //useAllAngular2AppRoots: true,
    //directConnect=true,

    /* capabilities: {
        'browserName': 'firefox'
      } */
};
4

1 回答 1

1

正如我在评论中提到的,文档尚未更新以反映在最新版本中默认禁用控制流(以前用于处理量角器的异步性质)这一事实。现在有必要自己处理这些承诺,async/await风格是最简单的长期。

下面是主站点中使用 async/await 样式的示例。

describe('angularjs homepage todo list', function() {
    it('should add a todo', async function() {
      await browser.get('https://angularjs.org');

      await element(by.model('todoList.todoText')).sendKeys('write first protractor test');
      await element(by.css('[value="add"]')).click();

      var todoList = element.all(by.repeater('todo in todoList.todos'));
      expect(await todoList.count()).toEqual(3);
      expect(await todoList.get(2).getText()).toEqual('write first protractor test');

      // You wrote your first test, cross it off the list
      await todoList.get(2).element(by.css('input')).click();
      var completedAmount = element.all(by.css('.done-true'));
      expect(await completedAmount.count()).toEqual(2);
    });
  });

我不确定这是否是您的问题的原因,但这是开始故障排除的好地方。

注意:仅当您的量角器版本高于 6.0 时才会影响

于 2019-05-17T12:30:00.100 回答