[英]BackDoor for Xamarin Forms(Android)
I created app with Xamarin Forms(Android). 我使用Xamarin Forms(Android)创建了应用程序。 I creaded xamarin ui test project( Xamarin.UiTest = 1.3.7).
我读取了xamarin ui测试项目(Xamarin.UiTest = 1.3.7)。 I need the use backdoor.
我需要使用后门。 It is my code:
这是我的代码:
public class MainActivity : FormsApplicationActivity
{
....
[Java.Interop.Export("Test")]
public void Test() { }
}
it is call method in unit test 它是单元测试中的调用方法
app.Invoke("Test");
I get this exception: 我得到这个例外:
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)
For Xamarin Android project it code is work. 对于Xamarin Android项目,它的代码有效。
How to use a backdoor method on xamarin ui test with xamarin form project? 如何在Xamarin表单项目的Xamarin UI测试中使用后门方法? It is my test project on git .
这是我在git上的测试项目 。
Works fine in our Xamarin.Forms
solutions, I would double check that you are exporting the method in the MainActivity
(which is the only one in a Xamarin.Forms
based Android project that you can add casbash backdoors to) and doing a casbah WaitForElement
to ensure that the main activity is running before the Backdoor
invoke takes place. 在我们的正常工作
Xamarin.Forms
的解决方案,我会仔细检查,你是在出口的方法MainActivity
(这在只有一个Xamarin.Forms
基于Android的项目,您可以添加casbash后门到),并做了卡斯巴WaitForElement
到确保在执行Backdoor
调用之前主活动正在运行。
Forms
solution/project. Forms
解决方案/项目的快速测试。 [[object CalabashRootView] > PhoneWindow$DecorView]
[ActionBarOverlayLayout] id: "decor_content_parent"
[FrameLayout > ... > LabelRenderer] id: "content"
[FormsTextView] text: "Welcome to Xamarin Forms!"
MainActivity
class: 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");
}
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 work
The Xamarin Test Cloud Agent will try to locate the method in the following order: Xamarin测试云代理将尝试按以下顺序查找方法:
Ref: https://developer.xamarin.com/guides/testcloud/uitest/working-with/backdoors/ 参考: https : //developer.xamarin.com/guides/testcloud/uitest/working-with/backdoors/
The Xamarin Test Cloud Agent will try to locate the method in the following order:
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) You are waiting for an element named "action_bar_overlay_layout", there is an Activity named "decor_content_parent" that you can wait for. 1)您正在等待一个名为“ action_bar_overlay_layout”的元素,您可以等待一个名为“ decor_content_parent”的活动。 I tend to use what is shown via the top level output of the Repl tree, it is easiest to match up and for others to follow along with.
我倾向于使用Repl树的顶级输出中显示的内容,这很容易匹配,其他人也可以跟随。
2) You were trying to invoke a method exported as Test
but in MainActivity.as
it is flagged as [Export("MyBackdoorMethod")]
. 2)您试图调用导出为
Test
的方法,但在MainActivity.as
中将其标记为[Export("MyBackdoorMethod")]
。
[Test]
public void AppLaunches()
{
app.Repl();
app.WaitForElement(c => c.Marked("decor_content_parent"));
app.Invoke("MyBackdoorMethod");
}
Ran test again and success, your debug output is written to logcat
. 再次运行测试并成功,您的调试输出将写入
logcat
。
I/mono-stdout( 8641): In through the backdoor - do some work
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.