Xamarin.UITest: How To Verify Placeholder/Hint Text

北战南征 提交于 2019-12-12 18:28:06

问题


I am writing a Xamarin.UITest for a cross-platform Xamarin.iOS and Xamarin.Android app.

In my Xamarin.UITest, how do I verify the following properties:

  • On Xamarin.Android, how can I verify the Hint property for an EditText?
  • On Xamarin.iOS, how can I verify the Placeholder property for a UITextField?

回答1:


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:

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. In our Invoke statements, we can take advantage of the native methods (getHint() on Android, and placeholder on iOS) to retrieve the string.

All tests were validated via Xamarin Test Cloud. The test report is viewable here.



来源:https://stackoverflow.com/questions/41354663/xamarin-uitest-how-to-verify-placeholder-hint-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!