当我尝试运行多个Spec文件时,如何在配置文件中使用“准备中”功能

时间:2019-07-02 14:15:42

标签: protractor

在配置文件中,我正在使用“准备中”功能,目的是将属性数据测试ID分配为值 但是对于第一个spec文件执行,on prepare被拾取 但在下一次执行Spec时,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

d \文档

2 个答案:

答案 0 :(得分:0)

在每个规格文件中使用BeforeAll()并在每个规格开始之前编写要执行的任何操作

答案 1 :(得分:0)

可能的以下链接可帮助您清除对onPrepare的怀疑以及如何使用它。

OnPrepare function in Protractor