Selenium webdriver 与两个要素文件相比,只有两个步骤不同。(爪哇)

Selenium webdriver 与两个要素文件相比,只有两个步骤不同。(爪哇),selenium-webdriver,ui-automation,cucumber-java,Selenium Webdriver,Ui Automation,Cucumber Java,我在学黄瓜。我有两种情况。由于公司的政策,我不能说确切的数字。第一步文件如下 Scenario 1: Flow with attachments Given Login to APP When User chooses "country" And clicks "Yes" And attaches "files" And Go to location page And add comments Then Submit Scenario

我在学黄瓜。我有两种情况。由于公司的政策,我不能说确切的数字。第一步文件如下

Scenario 1: Flow with attachments
Given Login to APP
When User chooses "country"
And clicks "Yes"
And attaches "files"
And Go to location page
And add comments
Then Submit

Scenario2: Flow without attachments
Given Login to APP
When User chooses "country"
And clicks "Yes"
And add players manually
And User picks players
And User clicks on a player
And does the settings
And Go to location page
And add comments
Then Submit

我是否需要在场景2中再次编写所有步骤,或者我可以做些什么,以便绕过在功能文件中编写所有步骤。 我的意思是,我可以在第二个特性中只维护不同的步骤,就像我们编写步骤文件或胶水代码那样。
如果是,如何执行,使其运行前面的所有步骤。请帮助

而不是按照用户在系统上执行的小动作(如“转到页面”、“单击此项”、“提交该项”)编写所有步骤,思考用户试图实现的目标,并创建一个对用户有意义的步骤(即“从文件添加玩家”),或“手动添加玩家”)。该步骤的步骤定义将包含系统上的所有这些操作(单击此项、填充此项等)。您还可以使用我们称之为“帮助器方法”的方法“根据您的步骤定义;例如,创建一个将导航到某个页面的方法,并使用要从各种步骤定义转到的相关页面调用该方法

这样,您的场景将描述系统的预期行为,或者应该允许用户做(或不做)什么

此外,从您提供的示例来看,我不清楚您正在测试/断言什么。我总是发现,使用“给定/和”设置系统的原始状态、“何时/和”执行要测试结果的操作,以及“然后/和”来验证预期结果都很有帮助。 场景的标题应该清楚地描述场景测试的目的

从您的示例中,我假设您正在测试用户是否能够从文件或手动添加播放器。在这种情况下,场景可能如下所示:

Scenario: User is able to add players from a file
Given a user who is logged in
And the user has selected "country"
When the user attaches "files"
And adds a comment about location
Then the players are added
And the comment is saved

Scenario: user is able to add players manually
Given a user who is logged in
And the user has selected "country"
When the user adds players manually
And adds a comment about location
Then the players are added
And the comment is saved
在上述示例中,我还假设以下步骤:

And add players manually
And User picks players
And User clicks on a player
And does the settings
实际上(总是)需要手动添加玩家,因此所有这些操作都将在“手动添加玩家”的一个步骤中执行(或者在一个步骤中实现所有这些操作,或者在该步骤中调用多个助手方法)

通过描述这样的行为,可以更清楚地了解您在每个场景中测试的内容以及系统的预期行为


此外,这将减少“步骤”的重复(我相信这是你最初的问题)。

没有。没有任何方法可以做到这一点(至少我不知道)。而且它对黄瓜来说是完全不存在的。作为一种良好的实践,两种场景应尽可能相互独立。请阅读以下内容:听起来你在寻找
背景
关键字。背景-。。。但我的意图也是关于后台阶@拉胡拉伊:谢谢你的链接。我遵循与saidAh Background相同的方法,但它们在您的案例中与将在功能文件开始之前或每个场景中执行的内容中的背景无关。您所说的步骤可能在场景中的任何位置。我希望你现在清楚这一点。干杯感谢大家分享的知识。是的,我同意这一点。谢谢你让我了解更多关于行为驱动测试的内容,不客气。您可以在此处找到更多信息:如果您有更多问题,请加入Cucumber支持渠道之一(即Slack):)