首页 > 解决方案 > 量角器如何在我的量角器 spec.js 文件的外部文件中调用已定义的 customerlocator.js

问题描述

根据https://www.protractortest.org/#/api?view=ProtractorBy.prototype.addLocator

我创建了 buttontextcusloc.js 并放置在 customlocators 文件夹中。文件内容如下。

var buttontxtcustomlocator = function() {


by.addLocator('buttonTextSimple',
        function(buttonText, opt_parentElement, opt_rootSelector) {
      // This function will be serialized as a string and will execute in the
      // browser. The first argument is the text for the button. The second
      // argument is the parent element, if any.
      var using = opt_parentElement || document,
      buttons = using.querySelectorAll('button');
      // Return an array of buttons with the text.
      return Array.prototype.filter.call(buttons, function(button) {
       return button.textContent === buttonText;

}); }

module.exports = new buttontxtcustomlocator();

这是我在 com/sam/scripts 中的 customloctestcase.spec.js

 describe('Custom Locator Script', function() {

  it("check customr locator ",function()
  {
      browser.driver.get("http://www.way2automation.com/angularjs-protractor/registeration/#/login");
    // Use the custom locator.
      element(by.buttonTextSimple('Go!')).click();
});

  });

在我的 config.js 中,我添加了如下

var cl = require('customlocators/buttontextcusloc.js');
exports.config = {
  directConnect: true,
  framework: 'jasmine',

但是在我运行它之后,我得到了以下错误。

在此处输入图像描述

项目结构如下。我以前运行的命令是量角器 defaultconfig.js 在此处输入图像描述

标签: protractor

解决方案


推荐阅读