我需要帮助,如果有人能帮上忙,我会很感激的。
我需要在Cucumber功能文件中将场景名称作为步骤中的参数进行传递。
在后台步骤-我正在启动浏览器并登录到应用程序,这样我就不必在每个场景中重复相同的步骤。有一种JAVA方法可以为后台测试中使用的GUI启动视频录制-视频录制将用于各个场景-因此,如果功能文件中有10个场景,则视频录制需要提供10个输出,以显示这10个场景的自动化运行。视频录制捕获方法根据将要传递的参数保存文件名。
例如,我在功能文件中的场景是:
Feature: Do Something
Background:
Given I start the recording for the scenario "Pass the scenario name here"
And I navigate to the login page
When I submit username and password
Then I should be logged in
Scenario: Scenario Name
Given I start the test for "Scenario Name"
Then it should do something
And stop the recording
Scenario: Scenario Name 2
Given I start the test for "Scenario Name 2"
Then it should do something
And stop the recording
如何在步骤中将场景名称作为参数传递?
发布于 2019-11-01 00:54:00
开始记录测试执行不属于您的cucumber测试。正如你所发现的,要实现你想要的东西是非常困难的。
这是Cucumber Hooks可以提供帮助的地方:
@Binding
public class TestRecorder {
private final VideoRecorder videoRecorder;
public TestRecorder() {
this(new VideoRecorder(...));
}
public TestRecorder(VideoRecorder videoRecorder) {
this.videoRecorder = videoRecorder;
}
@Before
public void BeginRecording(Scenario scenario) {
String scenarioName = scenario.getName();
// do something with scenarioName and start recording...
videoRecorder.start();
}
@After
public void StopRecording(Scenario scenario) {
String scenarioName = scenario.getName();
// Stop recording, and use scenarioName to save to a file
videoRecorder.stop();
}
}
在场景开始之前,开始视频录制。TestRecorder类可以声明私有字段来保存对录像机的引用。传入之前和之后方案挂钩(BeginRecording和StopRecording)的Scenario
对象提供有关方案的信息,包括名称。这应该足以将视频录制保存到使用场景名称作为文件名的文件中。
由于这只是一个POJO,您也可以为视频录制功能编写一些单元测试(如果您真的想要的话)。
现在,您的cucumber测试可以专注于测试中的系统,而不是监视测试的系统:
Feature: Do Something
Background:
Given I navigate to the login page
When I submit username and password
Then I should be logged in
Scenario: Scenario Name
When I do the thing
Then it should do something
Scenario: Scenario Name 2
When I do the thing
Then it should do something
不需要从功能文件中传递场景名称。这一切都是在黄瓜钩的“幕后”完成的。
https://stackoverflow.com/questions/58632698
复制相似问题