简体   繁体   English

Xamarin.UITest:如何验证占位符/提示文本

[英]Xamarin.UITest: How To Verify Placeholder/Hint Text

I am writing a Xamarin.UITest for a cross-platform Xamarin.iOS and Xamarin.Android app. 我正在为跨平台Xamarin.iOS和Xamarin.Android应用程序编写Xamarin.UITest。

In my Xamarin.UITest, how do I verify the following properties: 在我的Xamarin.UITest中,如何验证以下属性:

  • On Xamarin.Android, how can I verify the Hint property for an EditText ? 在Xamarin.Android上,如何验证EditTextHint属性?
  • On Xamarin.iOS, how can I verify the Placeholder property for a UITextField ? 在Xamarin.iOS上,如何验证UITextFieldPlaceholder属性?

Sample Code 样例代码

string GetPlaceholderText(string entryAutomationId)
{
    if (app is AndroidApp)
    {
        return app.Query(x => x.Marked(entryAutomationId)?.Invoke("getHint"))?.FirstOrDefault()?.ToString();
    }

    return app.Query(x => x.Marked(entryAutomationId)?.Invoke("placeholder"))?.FirstOrDefault()?.ToString();
}

Sample App 示例应用

Here is the same code-snippet in a sample app that demostrates how to accomplish this task in a cross-platform Xamarin.UITest: 这是示例应用程序中的相同代码段, 代码段演示了如何在跨平台Xamarin.UITest中完成此任务:

https://github.com/brminnick/FaceOff/blob/master/UITests/Pages/WelcomePage.cs#L73 https://github.com/brminnick/FaceOff/blob/master/UITests/Pages/WelcomePage.cs#L73

Explaination

In Xamarin.UITest, to retrieve text from an Android EditText or a iOS UITextField , you must use the Invoke method to access the native Java Android API and native ObjectiveC iOS API . 在Xamarin.UITest中,要从Android EditText或iOS UITextField检索文本,必须使用Invoke方法访问本机Java Android API和本机ObjectiveC iOS API In our Invoke statements, we can take advantage of the native methods ( getHint() on Android, and placeholder on iOS) to retrieve the string. 在我们的Invoke语句中,我们可以利用本机方法(Android上为getHint() ,iOS上为placeholder )来检索字符串。

All tests were validated via Xamarin Test Cloud . 所有测试均通过Xamarin测试云进行了验证。 The test report is viewable here . 这里可以查看测试报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM