javascript – 如何在我的函数场景中使用标签Cucumber.js?

前端之家收集整理的这篇文章主要介绍了javascript – 如何在我的函数场景中使用标签Cucumber.js?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在我的功能场景中使用标签

如何知道调用我的函数的场景?

其实我有一个场景:

  1. Feature: create module feature
  2. As a admin
  3. I want to use create module
  4.  
  5. @createModule
  6. Given I am logged as 'ADMIN'
  7. And I am on "/admin/create"
  8. Then The "book_id" field should be empty

我想在我的函数中使用我的标签@createModule然后:

  1. this.Then(/^The "?([^"]*)"? field should be empty$/,function (el) {
  2.  
  3. if (myModule === @createModule) {
  4. ...
  5. } else if {
  6. ...
  7. }
  8.  
  9. return main_po.checkIsEmptyElement(this,el);
  10. });

我想得到我的标签@createModule,以指定所调用的场景,或者其他替代方案,我想知道调用我的函数的场景.

Solved :

我补充说:

  1. this.Before(function (scenario,callback) {
  2. var tags = scenario.getTags();
  3.  
  4. this.current_module = tags[0].getName();
  5.  
  6. callback();
  7. });

和我的功能

  1. this.Then(/^The "?([^"]*)"? field should be empty$/,function (el) {
  2.  
  3. if (this.current_module === @createModule) {
  4. ...
  5. } else if {
  6. ...
  7. }
  8.  
  9. return main_po.checkIsEmptyElement(this,el);
  10. });

解决方法

这是我用于获取黄瓜3.0.7的功能或场景的标签
  1. let myTags = feature.pickle.tags;
  2. myTags.forEach(element => {
  3. logger.info(`My Tags: ${element.name}`);
  4.  
  5. });

猜你在找的JavaScript相关文章