Selenium webdriver 量角器辅助数据挂钩属性错误

Selenium webdriver 量角器辅助数据挂钩属性错误,selenium-webdriver,protractor,cucumberjs,Selenium Webdriver,Protractor,Cucumberjs,我试图使用量角器帮助器(var helpers=require('dragrator-helpers')访问数据挂钩属性,但由于某些原因,我得到以下错误: [12:06:50] E/launcher - Error: ReferenceError: beforeEach is not defined at C:\Users\xyz\node_modules\protractor-helpers\dist\protractor-helpers.js:258:2 at Object.

我试图使用量角器帮助器(var helpers=require('dragrator-helpers')访问数据挂钩属性,但由于某些原因,我得到以下错误:

[12:06:50] E/launcher - Error: ReferenceError: beforeEach is not defined
    at C:\Users\xyz\node_modules\protractor-helpers\dist\protractor-helpers.js:258:2
    at Object.<anonymous> (C:\Users\xyz\node_modules\protractor-helpers\dist\protractor-helpers.js:498:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\xyz\ProtractorWorkspace\Protractor\pos\Test.js:11:15)
有人能帮忙吗

如果您使用的是量角器jasmine框架(这是量角器中的默认框架),那么应该使用jasmine的钩子-beforeach、beforeAll等

如果您使用的是量角器cucumber框架,那么应该使用cucumberjs的钩子/事件处理程序-BeforeCasenario、beforeFeature等

有关量角器-茉莉花钩,请查看此链接-

我看到您使用的是
量角器cumber framework
,因此我将在这里介绍如何使用cucumberjs内置挂钩

首先,您需要在项目中使用cucumberjs节点模块以及量角器cucumber框架模块

cucumber的当前版本是2.0(rc-8),其语法与旧版本完全不同。因此,如果您想在每个场景之前启动浏览器url,您必须执行以下操作-

/* Cucumber 2.0 syntax **/

var {defineSupportCode} = require('cucumber');

defineSupportCode(function({Before}) {

Before(function () {
browser.get(url);
 });

// You can also specify cucumber tags for scenarios, This hook will be executed before scenarios tagged with @foo
Before({tags: "@foo"}, function () {
browser.get(url)
});
});
你可以在这里找到完整的列表示例和挂钩-

你可以查看我的回购协议以获取更多示例-

  • -->Cumber版本1.3.1(旧版本)不同的语法
  • -->cucumber 2.0(rc-8)最新版本新语法

看起来该软件包是为Jasmine设计的,因为源代码在每个(函数(){Jasmine.addMatchers({…)之前都有
。看起来它不支持cucumber,但我对此不肯定。你也可以显示你的测试吗?它在require语句中失败,下面是代码片段。var clickFn=require('../common/ClickFunctions.js');var-SelectDropDown=require('../common/dropdowntfunctions.js');var-helpers=require('../common/dropdowntfunctions.js');var-startQuote=function(){}感谢Ram的帮助,但它没有重新考虑cucumber钩子,它是关于dom中的数据钩子属性的,请参阅下面的dom内容感谢Ram的帮助,但它不是关于cucumber钩子,它是关于dom中的数据钩子属性的,请参阅下面的dom内容有select标记,我想选择为'element'(by.dataHook('sometext'))。单击()'为此,我们需要使用npm包'Gradurator helpers',如下链接中所述,但遇到'var helpers'代码时,我会收到错误。没有使用
by.dataHook
的元素查找程序,而应该使用css选择器来查找此类元素。请尝试-
element(by.css('select[data hook=“quoting.finance.product”]”)。单击()
,您也可以使用.cssContainingText的
查看此链接,了解如何处理量角器中的选定属性-非常感谢ram,这对我们有很大帮助,我们可以使用npm软件包“量角器帮助器”进行cucumber framework?如果是,那么它会很好。我不确定,因为我没有使用过他们用黄瓜!
/* Cucumber 2.0 syntax **/

var {defineSupportCode} = require('cucumber');

defineSupportCode(function({Before}) {

Before(function () {
browser.get(url);
 });

// You can also specify cucumber tags for scenarios, This hook will be executed before scenarios tagged with @foo
Before({tags: "@foo"}, function () {
browser.get(url)
});
});