我正在使用NUnit測試運行器的specflow。當我寫我的特徵文件,並要求specflow生成步驟,它輸出以下代碼:如何獲得被測試應用程序的參考?
using System;
using TechTalk.SpecFlow;
using Xamarin.UITest.Android;
namespace UITest1
{
[Binding]
public class CategoryPagerSteps
{
[Given(@"The (.*)st category is selected")]
public void GivenTheStCategoryIsSelected(int p0)
{
ScenarioContext.Current.Pending();
}
[When(@"I swipe left")]
public void WhenISwipeLeft()
{
ScenarioContext.Current.Pending();
}
[Then(@"The (.*)nd category is selected")]
public void ThenTheNdCategoryIsSelected(int p0)
{
ScenarioContext.Current.Pending();
}
}
}
這是好的,我明白,這是在「步驟」將被調用的場景時,我的黃瓜文件寫在小黃瓜要求他們。
但是,因爲這是一個完全集成的UI測試,我需要能夠使用Xamarin.UITest.Android來點擊視圖等。
所以我需要以某種方式獲取代表被測試應用程序的對象,以便我可以對其執行UI操作。現在
,我可以看到,這個對象是在被稱爲「Tests.cs」另一個自動生成的測試夾具文件初始化:
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Android;
namespace UITest1
{
[TestFixture]
public class Tests
{
AndroidApp app;
[SetUp]
public void BeforeEachTest()
{
// TODO: If the Android app being tested is included in the solution then open
// the Unit Tests window, right click Test Apps, select Add App Project
// and select the app projects that should be tested.
app = ConfigureApp
.Android
// TODO: Update this path to point to your Android app and uncomment the
// code if the app is not included in the solution.
//.ApkFile ("../../../Android/bin/Debug/UITestsAndroid.apk")
.StartApp();
}
[Test]
public void AppLaunches()
{
app.Screenshot("First screen.");
}
}
}
我可以看到屬性AndroidApp app
是我所需要的對象訪問,但我如何從上面的CategoryPagerSteps
代碼訪問該屬性? Tests
不是靜態的,也不是任何方法或屬性。我很緊張,只是自己實例化它,因爲這應該可以由測試運行者完成,對吧?其他自動生成的文件之一包含一個testRunner屬性,但它被標記爲私有。
因此,我所下的每條大街都出現了堵塞,我覺得我錯過了一些明顯的東西。
看看:http://arteksoftware.com/bdd-tests-with-xamarin-uitest-and-specflow/本文深入介紹瞭如何開始使用SpecFlow + Xamarin.UITest – Cheesebaron