Protractor 当我试图运行多个规范文件时,如何在配置文件中使用On Prepare函数

Protractor 当我试图运行多个规范文件时,如何在配置文件中使用On Prepare函数,protractor,Protractor,在配置文件中,我使用On Prepare函数将属性数据测试id指定为值 但是,对于第一个spec文件执行,将在prepare上执行 但是在规范的下一次执行中,on prepare函数没有被使用 import { Config } from "protractor/built/config"; import { by } from "protractor"; // import { encode } from "punycode"; function encode(file) { var

在配置文件中,我使用On Prepare函数将属性数据测试id指定为值 但是,对于第一个spec文件执行,将在prepare上执行 但是在规范的下一次执行中,on prepare函数没有被使用

import { Config } from "protractor/built/config";
import { by } from "protractor";
// import { encode } from "punycode";

function encode(file) {
    var stream = require('fs').readFileSync(file);
    return new Buffer(stream).toString('base64');
}

export let config: Config = {
    // The address of a running selenium server.
   //seleniumAddress: 'http://localhost:4444/wd/hub',
   directConnect:true,
  allScriptsTimeout:1500000,

    // Capabilities to be passed to the webdriver instance.
    capabilities: {
      browserName: 'chrome',
       'chromeOptions': {
        'extensions': [encode('C:/Users/koanand/Documents/Protractor/ASR/2.2.9_0.crx')]
       }
    },



    onPrepare: function () {
      by.addLocator('testId', function(value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[data-test-id]');
        return Array.prototype.filter.call(nodes, function(node) {
          return (node.getAttribute('data-test-id') === value);
        });
      });
    },



    // Spec patterns are relative to the configuration file location passed
    // to protractor (in this example conf.js).
    // They may include glob patterns.
    specs: ['C:/Users/anand/Documents/Protractor/ASR/TS-Output/specs/directasr.js',
    'C:/Users/anand/Documents/Protractor/ASR/TS-Output/specs/products.js'
    ],


    // Options to be passed to Jasmine-node.
    jasmineNodeOpts: {
      showColors: true, // Use colors in the command line report.
      defaultTimeoutInterval : 150000
    }



  };

i am observing the below error

Message:
    Failed: protractor_1.by.testID is not a function
  Stack:
    TypeError: protractor_1.by.testID is not a function
        at new productlist (C:\Users\koanand\Documents\Protractor\ASR\pageobject\productlist.ts:19:45)
        at product.selectingproductlist (C:\Users\koanand\Documents\Protractor\ASR\specs\classproductlist.ts:14:32)
        at UserContext.<anonymous> (C:\Users\koanand\Documents\Protractor\ASR\specs\products.ts:21:21)
        at C:\Users\koanand\Documents\Protractor\ASR\node_modules\jasminewd2\index.js:108:15
        at new ManagedPromise (C:\Users\koanand\Documents\Protractor\ASR\node_modules\selenium-webdriver\lib\promise.js:1077:7)
        at ControlFlow.promise (C:\Users\koanand\Documents\Protractor\ASR\node_modules\selenium-webdriver\lib\promise.js:2505:12)
        at schedulerExecute (C:\Users\koanan
从“progrator/build/Config”导入{Config};
从“量角器”导入{by};
//从“punycode”导入{encode};
函数编码(文件){
var stream=require('fs').readFileSync(文件);
返回新的缓冲区(stream).toString('base64');
}
导出let配置:配置={
//正在运行的selenium服务器的地址。
//赛琳娜的裙子:'http://localhost:4444/wd/hub',
directConnect:没错,
全部预算:1500000,
//要传递给webdriver实例的功能。
能力:{
browserName:“chrome”,
“颜色选项”:{
“扩展名”:[encode('C:/Users/koanand/Documents/dragrator/ASR/2.2.9_0.crx')]
}
},
onPrepare:function(){
by.addLocator('testId',函数(值,parentElement){
parentElement=parentElement | |文档;
var nodes=parentElement.querySelectorAll(“[data test id]”);
返回数组.原型.过滤器.调用(节点,函数(节点){
返回值(node.getAttribute('data-test-id')==值);
});
});
},
//等级库模式与传递的配置文件位置相关
//到量角器(在本例中为conf.js)。
//它们可能包括glob模式。
规格:['C:/Users/anand/Documents/dragrator/ASR/TS Output/specs/directasr.js',
'C:/Users/anand/Documents/dragrator/ASR/TS Output/specs/products.js'
],
//要传递给Jasmine节点的选项。
茉莉花:{
showColors:true,//在命令行报告中使用颜色。
defaultTimeoutInterval:150000
}
};
我正在观察下面的错误
信息:
失败:量角器_1.by.testID不是函数
堆栈:
TypeError:量角器_1.by.testID不是函数
在新产品列表中(C:\Users\koanand\Documents\dragrator\ASR\pageobject\productlist.ts:19:45)
在product.selectingproductlist(C:\Users\koanand\Documents\dragrator\ASR\specs\classproductlist.ts:14:32)
在UserContext。(C:\Users\koanand\Documents\dragrator\ASR\specs\products.ts:21:21)
在C:\Users\koanand\Documents\dragrator\ASR\node\u modules\jasminewd2\index.js:108:15
在新的ManagedPromise上(C:\Users\koanand\Documents\Drugator\ASR\node\U modules\selenium webdriver\lib\promise.js:1077:7)
在ControlFlow.promise(C:\Users\koanand\Documents\dragrator\ASR\node\u modules\selenium webdriver\lib\promise.js:2505:12)
在schedulerExecute(C:\Users\koanan

d\Docume

在每个规范文件中使用BeforeAll(),并在每个规范开始之前编写您想要执行的任何内容

在每个规范文件中使用BeforeAll(),并在每个规范开始之前编写您想要执行的任何内容

以下链接可能会帮助您消除对onPrepare的疑虑,以及在规范开始之前使用什么


以下链接可能会帮助您消除对onPrepare的疑虑,以及在onPrepare中使用什么