0
我在mvc3 web應用程序上使用Watin和Specflow。我已經設置了一個幫助器來創建靜態瀏覽器以用於我的步驟測試方法。所有似乎設置正確,但是當我運行我的測試時,斷言(我的「然後」方法)瀏覽器標題屬性是空的。我也嘗試在頁面上搜索元素,而瀏覽器只是結束了超時。Watin瀏覽器標題屬性爲空
我試過調試,但似乎沒有幫助,因爲瀏覽器是靜態的。
還有什麼可能導致這種情況?
任何幫助,非常感謝!
BTY-瀏覽器打開並導航到我在第一步中請求的頁面。
更新:
我創建了另一個應用程序,試圖找到問題所在......同樣的問題。代碼如下所示。
App.Config中
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<!-- Valid values are STA,MTA. Others ignored. -->
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>
Specflow功能
Feature: TestMyWebApp
In order to test my web app
As a user
I want to navigate to the home page
@mytag
Scenario: Navigation to homepage
When I navigate to /Home
Then I should be on the home page
步文件
[Binding]
public class TestMyWebAppSteps
{
[When(@"I navigate to /Home")]
public void WhenINavigateToHome()
{
WebBrowser.Current.GoTo("http://localhost:57556/Home");
}
[Then(@"I should be on the home page")]
public void ThenIShouldBeOnTheHomePage()
{
Assert.AreEqual("Home", WebBrowser.Current.Title);
}
}
瀏覽器輔助
public static class WebBrowser
{
public static IE Current
{
get
{
string key = "browser";
if (!ScenarioContext.Current.ContainsKey(key))
{
ScenarioContext.Current[key] = new IE();
}
return ScenarioContext.Current[key] as IE;
}
}
}
任何想法如何找出問題?