是否有将量角器测试拆分为组件文件的工具?

Is there a tool to split Protractor tests into component files?

我正在使用量角器(angularJS/Jasmine 框架)构建一个可扩展的自动化测试套件。 只要我所有的变量和函数以及 jasmine 都在同一个文件中,它 运行 就没问题了。 但是我为将其分解为 export/require 所做的一切努力都是一场噩梦。 有没有一种工具可以找到我的测试部分并自动重新格式化并将其分解为单独的文件和文件夹,这样实际上 运行?

谢谢!

我不知道有什么工具可以满足您的需求。但是,如果我是你,我会继续使用节点共享文件的方式 (export/require)。一旦你理解了它,如果你保持它干净整洁,你可以以 "clean" 的方式发展你的应用程序。

编辑:

正如@MBielski 所说,页面对象模型在维护测试代码时也很有帮助。

Selenium 团队的定义:

Page Object is a Design Pattern which has become popular in test automation for enhancing test maintenance and reducing code duplication. A page object is an object-oriented class that serves as an interface to a page of your AUT. The tests then use the methods of this page object class whenever they need to interact with that page of the UI. The benefit is that if the UI changes for the page, the tests themselves don’t need to change, only the code within the page object needs to change. Subsequently all changes to support that new UI are located in one place.

现在是一个不使用页面对象的示例,然后是一个使用它的示例。

没有:

describe('angularjs homepage', function() {
  it('should greet the named user', function() {
    browser.get('http://www.angularjs.org');
    element(by.model('yourName')).sendKeys('Julie');
    var greeting = element(by.binding('yourName'));
    expect(greeting.getText()).toEqual('Hello Julie!');
  });
});

搭配:

var AngularHomepage = function() {
  var nameInput = element(by.model('yourName'));
  var greeting = element(by.binding('yourName'));

  this.get = function() {
    browser.get('http://www.angularjs.org');
  };

  this.setName = function(name) {
    nameInput.sendKeys(name);
  };

  this.getGreeting = function() {
    return greeting.getText();
  };
};


describe('angularjs homepage', function() {
  it('should greet the named user', function() {
    var angularHomepage = new AngularHomepage();
    angularHomepage.get();

    angularHomepage.setName('Julie');

    expect(angularHomepage.getGreeting()).toEqual('Hello Julie!');
  });
});

您还可以定义各种测试套件。看看这个配置文件:

exports.config = {

  seleniumAddress: 'http://localhost:4444/wd/hub',

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

  // Spec patterns are relative to the location of the spec file. They may
  // include glob patterns.
  suites: {
    homepage: 'tests/e2e/homepage/**/*Spec.js',
    search: ['tests/e2e/contact_search/**/*Spec.js',
      'tests/e2e/venue_search/**/*Spec.js']
  },

  jasmineNodeOpts: {
    showColors: true, // Use colors in the command line report.
  }
};