如何使用 specflow+excel 在 Specflow 中为测试保留单个会话

How to retain single session for the test in Specflow with specflow+excel

登录 google 系统后,我应该可以导航到所有菜单

@Login
Scenario: Successful Login to Google
 Given Google system launched
 When Login with XYZ
 Then Google main page displayed
@menuNavigate
Scenario Outline: Navigate to page from google menu 
    Given User navigates to <Tab> using the tabs
    When The Page is completely loaded with <Header>
    Then the result should be that a control with controlId <ControlId> is displayed on the screen

@source:menuNavigate.xlsx
Scenarios:
| Tab | Header  | ControlId |

@登录测试成功。执行@menuNavigate 测试时,它会启动单独的会话。

有什么方法可以使用相同的浏览器会话继续测试的其余部分

您可以通过在 [BeforeFeature] hook 中创建您的浏览器实例,然后在每个功能中使用它,以每个功能为基础执行此操作(即您可以在功能的所有场景中重复使用相同的浏览器)设想。只要您的 [beforeFeature[BeforeScenario] 挂钩在同一个 class 中,您就可以声明一个静态字段来保存您的浏览器实例并将其填充到 [BeforeFeature] 挂钩中并重用[BeforeScenario] 钩子中的字段。

但是考虑一下你是否真的想这样做。如果您的场景 运行 顺序不同,会发生什么情况?没有什么可以保证测试执行顺序。还是并行?

我非常怀疑这种方法从长远来看能否很好地扩展。

如果您想要一些共同的设置,那么 create a background or create a step to do the setup and call this from each scenario. You can even call other steps from this setup step 如果您希望设置步骤执行一些已经在另一个测试中使用过的操作。