我正在使用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