[英]How do i load/run an external .js script from Protractor
我正在运行 Protractor 测试,该测试将验证网站上的各种元素,但在此之前,我想使用 arguments 运行外部 JavaScript 脚本,该脚本将设置一些先决条件。 但是,我完全不知道如何从 protractor 运行“javascript_code.js”脚本。
我知道下面的 protractor 代码是完全错误的,我刚刚使用了 describe/it 布局来显示我想在哪里做什么以及在哪里做:
describe('Validate elements on website',function(){
// reference and run the javascript_code.js
require('C:\<file path>\Javascript_code.js');
Run "node javascript_code.js arg1 arg2 arg3"
it('Validate onscreen elements', function(){
<Do website verification>
});
});
该方法将取决于您在 js 文件中执行的操作。 如果您的代码是同步的,最简单的方法是让您的 javascript_code.js 成为 function,它接受参数然后导出它,就像这样
module.exports = function(arg1, arg2) {
console.log(arg1);
console.log(arg2);
};
然后require
并调用您的 function
let your_func = require('C:\<file path>\Javascript_code.js');
your_func(arg1, arg2);
describe('Validate elements on website',function(){
it('Validate onscreen elements', function(){
});
});
但是,如果您的 js 代码是异步的,则方法应该不同。 让我知道
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.