1

我想在一个功能的每个场景之后执行一些操作(清除 cookie、清除数据库等),但是 after.each_feature 在 aloe_django 中不可用。你是如何处理这个问题的。处理此问题的任何建议。以下钩子在 aloe_django 中不可用。

@before.each_scenario def setup_some_scenario(scenario): populate_test_database()

我需要这个,因为我想在一个功能中有几个场景,当第一个功能完成时,我从管理员注销并需要在下一个场景中再次登录(不注销没有帮助),但在下一个场景中它给出一个错误,告诉我我的凭据无效(在第一种情况下它是有效的)。当我将这些场景作为不同的功能并重置我的数据库并迁移时,它工作正常。

我认为当它在功能中从一个场景跳转到另一个场景时,它会弄乱数据库或使用不同的场景,所以我需要 after.each_scenario() 挂钩来重置和迁移我的数据库。

4

2 回答 2

1

我在 Aloe_django 中使用了 before/after.each_example() 钩子。您将这段代码放入您的 terrain.py 文件中。

@before.each_example def before_each_example(scenario,outline,steps): call_command(#your command#)

于 2015-12-04T07:58:24.050 回答
0
You could use @After tag, 

Example:

@Clean up
Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples:
    | start | eat | left |
    |  12   |  5  |  7   |
    |  20   |  5  |  15  |

In step definition,

@After("Clean up")
public void cleanup(){

System.out.println("CLEAN UP RUNNING ");

}


After every scenario, Your test will call this after function and do cleaning job.
于 2015-12-02T17:43:06.160 回答