NUnit, TestDriven.NET, WatiN and Specflow

本文关键字:and Specflow WatiN NET TestDriven NUnit | 更新日期: 2023-09-27 18:25:12

我正在尝试使用Specflow、NUnit和WatiN进行一些BDD测试。我正在使用TestDriven.NEt运行测试。这是我的第一个测试:

[Binding]
    [TestFixture, RequiresSTA]
    public class RegisterUserSteps
    {
        private IE _ie = new IE();
        [When(@"the user visits the registration page")]
        public void WhenTheUserVisitsTheRegistrationPage()
        {
            _ie.GoTo("http://localhost:1064/Register/"); 
        }

        [When(@"enter the following information")]
        public void WhenEnterTheFollowingInformation(Table table)
        {
            foreach(var tableRow in table.Rows)
            {
                var field = _ie.TextField(Find.ByName(tableRow["Field"])); 
                if(!field.Exists)
                {
                    Assert.Fail("Field does not exists!");
                }
                field.TypeText(tableRow["Value"]);
            }
        }
        [When(@"click the ""Register"" button")]
        public void WhenClickTheRegisterButton()
        {
            ScenarioContext.Current.Pending();
        }
        [Then(@"the user should be registered")]
        public void ThenTheUserShouldBeRegistered()
        {
            ScenarioContext.Current.Pending();
        }
    }

问题是它永远不会进入

 [When(@"enter the following information")]
            public void WhenEnterTheFollowingInformation(Table table)

它只是启动浏览器并执行第一步。我是不是错过了什么?

NUnit, TestDriven.NET, WatiN and Specflow

如果不看测试,您似乎错过了一个重要的步骤(Given)。通常是这样的:

Given I go to some page
And all the set up data are available - optional
When I enter the following info
And I click "Register" button
Then I see something

基本上,步骤是GWT(Given,When,Then)。这是小黄瓜语言,所以如果你在谷歌上搜索,你会看到更多信息。当给定步骤有多个内容时,必须使用And,例如When ...... And.......,而不是When...... When........