首页 文章

如何使用Gauge定义一次运行上下文步骤?

提问于
浏览
0

使用Gauge,我们可以在测试规范 Headers 之后使用Context Steps在每个场景之前重复一组步骤 . 例如:

Delete project
==============
* User log in as "mike"

Delete single project
---------------------
* Delete the "example" project
* Ensure "example" project has been deleted

Delete multiple projects
------------------------
* Delete all the projects in the list
* Ensure project list is empty

在上面的删除项目测试规范中,上下文步骤 User log in as "mike" 将执行两次,两次检测方案中的每一种都执行一次 .

如何定义在测试规范的所有场景之前运行一次的步骤?

1 回答

  • 1

    由于您无法通过spec文件运行一次,因此解决方法可能是使用套件存储 .

    public void loginAsMike(){
      if((boolean) DataStoreFactory.getSuiteDataStore().get('loggedIn')){
          //execute steps
          DataStoreFactory.getSuiteDataStore().put('loggedIn', true);
      }
    }
    

    这样它只会运行一次 . 这里唯一的问题是如果你要并行运行多个测试 . 但是,如果您只在一个spec文件中以mike身份登录,那么这是一个很好的解决方案 .

相关问题