我有3个文件,即conf.js,actionwords.js,project_test.js。 Actionwords.js和project_test.js是从hiptest工具生成的文件。所以我需要使用这个结构来自动化测试用例。当我浏览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();
});
});
任何人都可以帮助我吗?
答案 0 :(得分:3)
以这种方式改变:
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();
});
});
答案 1 :(得分:0)
在try .. except
中,beforeEach(...)
指向传递给它的匿名函数。 this
也是如此。
声明it(...)
describe
答案 2 :(得分:0)
如下所示更新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();
});
});