我用Xamarin Forms(Android)创建了应用程序。我创建了xamarin测试项目( Xamarin.UiTest = 1.3.7)。我需要用后门。这是我的密码:
public class MainActivity : FormsApplicationActivity
{
....
[Java.Interop.Export("Test")]
public void Test() { }
}这是单元测试中的调用方法。
app.Invoke("Test");我明白这一例外:
20-04-2016 12:02:36.805 +03:00 - 72182 - Error while performing Invoke("Test", null)
Exception: System.Exception: Invoke for StartActivityTwo failed with outcome: ERROR
No such method found: Test()
in Xamarin.UITest.Android.AndroidGestures.Invoke(String methodName, Object[] arguments)
in Xamarin.UITest.Utils.ErrorReporting.With[T](Func`1 func, Object[] args, String memberName)对于Xamarin Android项目来说,它的代码是可行的。
如何使用后门方法在xamarin用户界面测试与xamarin表单项目?是我在git上的测试项目。
发布于 2016-04-20 11:03:28
在我们的Xamarin.Forms解决方案中工作得很好,我会再次检查您是否正在导出MainActivity中的方法(这是基于Xamarin.Forms的Android项目中唯一可以添加casbash后门的方法),并执行casbah WaitForElement以确保主活动在Backdoor调用发生之前运行。
使用基于默认/模板的Forms解决方案/项目进行快速测试。
在安卓(Xamarin.Forms` )项目中:
爬行树:
[[object CalabashRootView] > PhoneWindow$DecorView]
[ActionBarOverlayLayout] id: "decor_content_parent"
[FrameLayout > ... > LabelRenderer] id: "content"
[FormsTextView] text: "Welcome to Xamarin Forms!"在MainActivity类中:
[Activity (Label = "UITestBackDoorForms.Droid", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity后门出口方法:
[Export("MyBackdoorMethod")]
public void MyBackdoorMethod()
{
System.Diagnostics.Debug.WriteLine("In through the backdoor - do some work");
}在试验项目中:
[Test]
public void InvokeBackdoor()
{
// Wait for the Activity to load
app.WaitForElement(c => c.Marked("decor_content_parent"));
// Invoke the backdoor method MainActivity.MyBackDoorMethod
app.Invoke("MyBackdoorMethod");
}LogCat输出:
I/System.out( 5754): params: {json={"query":"* marked:'decor_content_parent'","operation":{"method_name":"query","arguments":[]}}
I/System.out( 5754): }
~~~
I/System.out( 5754): URI: /backdoor
I/System.out( 5754): params: {json={"method_name":"MyBackdoorMethod","arguments":[]}
I/System.out( 5754): }
~~~
I/mono-stdout( 5754): In through the backdoor - do some workXamarin测试云代理将按以下顺序尝试定位该方法:
后门
参考文献:https://developer.xamarin.com/guides/testcloud/uitest/working-with/backdoors/
Xamarin测试云代理将按以下顺序尝试定位该方法:
更新(用户提供的代码):
之前的测试代码:
[Test]
public void AppLaunches()
{
app.Repl();
//app.Screenshot("First screen.");
//Assert.IsTrue(true);
app.WaitForElement(c => c.Marked("action_bar_overlay_layout"));
app.Invoke("Test");
}回购产出:
>>> tree
[[object CalabashRootView] > PhoneWindow$DecorView]
[ActionBarOverlayLayout] id: "decor_content_parent"
[FrameLayout > ... > Platform_DefaultRenderer] id: "content"
[ButtonRenderer]
[Button] text: "Test1"
[ButtonRenderer]
[Button] text: "Test2"
[ButtonRenderer]
[Button] text: "Test3"问题:
1)您正在等待一个名为"action_bar_overlay_layout“的元素,有一个名为"decor_content_parent”的活动可以等待。我倾向于使用Repl树的顶级输出所显示的内容,这是最容易匹配和其他人跟随的。
2)您试图调用导出为Test的方法,但在MainActivity.as中它被标记为[Export("MyBackdoorMethod")]。
代码更改后:
[Test]
public void AppLaunches()
{
app.Repl();
app.WaitForElement(c => c.Marked("decor_content_parent"));
app.Invoke("MyBackdoorMethod");
}再次运行测试并成功,您的调试输出将写入logcat。
逻辑猫:
I/mono-stdout( 8641): In through the backdoor - do some workhttps://stackoverflow.com/questions/36739560
复制相似问题