[英]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.