protractor - 量角器如何在我的量角器 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',
但是在我运行它之后,我得到了以下错误。
解决方案
推荐阅读
- hadoop - 使用 Flume 将本地文件源到 HDFS 接收器
- c# - 将多线程与 Async-await C# 结合使用
- python - protobuf,和tensorflow安装,选择哪个版本
- amazon-web-services - 为什么我在一个区域的 ec2 试图使用另一个区域的另一个 ec2 实例的私有 IP?
- mysql - 无法从子查询结果中选择计算值
- html - 在不离开父级的情况下覆盖 div
- c# - Elastic/Nest 中的滚动和分页 6+
- excel - 在 excel 中,如何搜索匹配多个列条目的文本?
- c# - UWP 启动 Sim 应用程序
- c++ - stable_sort() 是否也保留不相等元素的顺序?