我有3个文件,即conf.js,actionwords.js,project_test.js。Actionwords.js和project_test.js是由hiptest tool.So生成的文件,我需要使用这个结构来自动化测试用例。当我运行cmd时,我得到了错误。
我跑了:
protractor conf.js消息:失败:无法读取未定义的属性“theApplicationURL”
堆栈:TypeError:无法读取未定义的属性“theApplicationURL”
// conf.js
exports.config = {
 framework: 'jasmine2',
 directConnect: true,
 seleniumAddress: 'http://localhost:4444/wd/hub',
 specs:['path to/project_test.js'],
 capabilities: { 'browserName': 'chrome' }
 };//actionwords.js
var Actionwords = {
theApplicationURL: function () {
browser.get('localhost');
browser.driver.manage().window().maximize();
browser.sleep(5000);
   },
};//project_test.js
describe('Test', function () {
beforeEach(function () {
this.actionwords = Object.create(Actionwords);
});
it('Login_Test (uid:fe6d6670-a864-4d0f-a867-3faf9f51ff8d)', function () {
// Given the application URL
this.actionwords.theApplicationURL();
});
});有人能帮我吗?
发布于 2016-11-18 06:50:05
以这种方式改变它:
var actionwords = {
  theApplicationURL: function () {
    browser.get('localhost');
    browser.driver.manage().window().maximize();
    browser.sleep(5000);
  },
};
module.exports = actionwords;测试:
var actionwords = require("actionwords.js")
describe('Test', function () {
  it('Login_Test (uid:fe6d6670-a864-4d0f-a867-3faf9f51ff8d)', function () {
    // Given the application URL
    actionwords.theApplicationURL();
  });
});this**:**评论中的反应
可以在beforeEach中将其分配给此作用域。
var actionwords = require("actionwords.js")
describe('Test', function () {
  beforeEach(function () {
    this.actionwords = actionwords;
  });
  it('Login_Test (uid:fe6d6670-a864-4d0f-a867-3faf9f51ff8d)', function () {
    // Given the application URL
    this.actionwords.theApplicationURL();
  });
});发布于 2016-11-18 06:15:44
在beforeEach(...)中,this引用传递给它的匿名函数。it(...)也是如此。
在describe范围内声明变量的
describe('Test', function() {
    var actionwords = Object.create(Actionwords);
    it('Login_Test (uid:fe6d6670-a864-4d0f-a867-3faf9f51ff8d)', function() {
        actionwords.toApplicationURL();
    });
});发布于 2016-11-18 07:00:28
更新您的actionword.js如下,
var Actionwords = {
theApplicationURL: function () {
  browser.get('localhost');
  browser.driver.manage().window().maximize();
  browser.sleep(5000);
 },
};
module.exports = new Actionwords();你的project_test.js会像,
this.actionwords = require("actionword.js");
describe('Test', function () {
 it('Login_Test (uid:fe6d6670-a864-4d0f-a867-3faf9f51ff8d)', function () {
   this.actionwords.theApplicationURL();
 });
});https://stackoverflow.com/questions/40670357
复制相似问题