对我的小黄瓜感到困惑 - 网页之间的导航
我刚刚开始在一个 Web 项目上使用 BDD,使用 SpecFlow 和 WatiN 通过浏览器实现自动化,但我不太确定如何编写我的步骤。
我试图以 TDD 方式驱动测试中的所有内容,除非需要通过测试,否则不编写任何内容。 (我也在进行单元测试来驱动细节,但这个问题与此无关)。我感到困惑的一件事是页面之间的导航,以及是否/如何在规范中定义它。
第一个测试涉及输入一些详细信息并确保它们显示在列表中。我的第一次尝试是这样的:
场景:添加详细信息选项 1
鉴于我位于“主页”页面
当我点击“添加详细信息”时
我在“姓名”字段中输入“John Smith”
然后我点击“保存”
然后“John Smith”出现在列表中
但是,这涉及在几个页面之间导航,所以我不知道是否需要明确 - 否则,我只需假设我在正确的页面或步骤上显然与我所在的页面无关(例如,“当我单击添加详细信息时”)有断言来检查我所在的页面。
我们是否检查场景中具有明确步骤的页面?
场景:添加详细信息选项 2
鉴于我位于“主页”页面
当我点击“添加详细信息”时
我现在位于“添加详细信息”页面
我在“姓名”字段中输入“John Smith”
然后我点击“保存”
我在“主页”页面
然后“John Smith”出现在列表中
或者我们按照选项 1 中的步骤执行此操作,只是没有明确提及它?
例如,单击“添加详细信息”是否应该检查我们是否最终到达正确的页面?
public void WhenIClickAddDetils{
// syntax probably wrong, not important
Assert.That(IE.Button("AddDetails").exists);
IE.Button("AddDetails").click();
Assert.That(IE.PageTitle = "Add Details")); // do we check this here?
}
或者我们应该在输入详细信息之前检查我们是否在正确的页面上?
public void WhenIEnterDetils{
Assert.That(IE.PageTitle = "Add Details")); // do we check this here?
IE.TextField("Name").value = "John Smith";
// etc
}
或者,我们可以从
鉴于我位于“添加详细信息”页面
,只需执行该步骤,包括从主页开始并单击“添加详细信息按钮”即可访问该页面。尽管在我们单击“保存”后导航回主页仍然存在相同的问题。
有什么想法吗?
I'm just starting out with BDD on a web project, using SpecFlow and WatiN to automate things through the browser, and I'm not quite sure how to write my steps.
I'm trying to drive everything from the tests, and in a TDD manner, not write anything unless it's needed to make a test pass. (I am also doing unit tests to drive the detail, but this question isn't about that). One thing I'm confused about is navigation between pages, and if/how this should be defined in the specs.
The first test involves entering some details and ensuring they get displayed in a list. My first attempt goes something like this:
Scenario: Add Details Option 1
Given I am on the "Home" page
When I click "Add Details"
And I enter "John Smith" in the Name field
And I click "Save"
Then "John Smith" appears in the list
However, this involves navigating between a couple of pages, so I don't know if that needs to be explicit - otherwise, I just have to assume I'm on the right page, or steps which are apparently unrelated to which page I'm on (for example, 'When I click Add Details') have assertions to check which page I'm on.
Do we check the pages with explicit steps in the scenario?
Scenario: Add Details Option 2
Given I am on the "Home" page
When I click "Add Details"
And I am on the "Add Details" page
And I enter "John Smith" in the Name field
And I click "Save"
And I am on the "Home" page
Then "John Smith" appears in the list
Or do we do it in the steps from option 1, just not mentioning it explicitly?
For example, Should clicking on 'Add Details' check that we end up on the right page?
public void WhenIClickAddDetils{
// syntax probably wrong, not important
Assert.That(IE.Button("AddDetails").exists);
IE.Button("AddDetails").click();
Assert.That(IE.PageTitle = "Add Details")); // do we check this here?
}
Or should we check we are on the right page before entering the details?
public void WhenIEnterDetils{
Assert.That(IE.PageTitle = "Add Details")); // do we check this here?
IE.TextField("Name").value = "John Smith";
// etc
}
Alternatively, we could start with
Given I am on the "Add Details" page
And just make that step include starting on the home page and clicking the 'Add Details button' in order to get to that page. Although this still leaves the same issue with navigating back to the Home page after we click 'Save'.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说在这种情况下你不必检查它。基本上,测试是
Given-When-Then
(arrange-act-assert),而And I am on the "Add Details" page
实际上是一个Then
(assert) 在When
(act) 内,这对我来说看起来不正确。我的直觉是它应该看起来像这样:
I would say that you do not have to check it in this scenario. Basically, the test is
Given-When-Then
(arrange-act-assert), andAnd I am on the "Add Details" page
is actually aThen
(assert) insideWhen
(act), which does not look right to me.My gut feeling is that it should look like this instead: