Android Resource Name From Xamarin Forms Button

2020-03-24 05:22发布

问题:

The Play Store now allows you to specify credentials for the Pre-launch Report emulator to use. In order for the emulators to know which text field to add the credentials to and which button to click to login, it asks for the text field and button's Resource Name.

Do any of the Xamarin Form's properties translate into a Resource name? I tried looking in the /obj/ and /bin/ folders after building my app to see if one of the files had anything like this but I did not find anything.

Possible properties that I can think of that might map to a Resource Name:

StyleId
AutomationId
ClassId
AutomationProperties.Name (in XF 2.3.5)

If nothing maps over, would you know of a way to use a custom renderer to make this work?

回答1:

You have two options to use the Pre-launch reports with Xamarin.Forms:

1) Define a Login Activity via a Layout XML resource that includes a username & password Entry fields, a login button is optional and if not supplied, the robots will tap every available button on the screen.

You can either define this Activity as your main launcher (or the activity that gets launched after "splash screen" activity) and perform the login authentication independently of Xamarin.Forms code, of course you can access PCL/NStd library code. After authentication success, proceed to the "MainActivity" which does the normal Xamarin.Forms initiation or present this Login Activity (or ViewGroup, Fragment, ...) via a custom renderer (or a dependency service which is the easiest for a complete Activity....)

Now you know the resource ids that Google needs as they are hardcoded in the Login layout XML...

2) Publish your app as an Alpha/Beta and either have it auto-login to a test account or just present a login screen that have a pre-supplied test account user and pwd filled in and have those entries set to read-only. The robot will tap the login button.

Option 2 is the quickest and easiest to setup as you would already have a login Page and just need to define a test account id/pwd to those two fields as defaults and then set those fields to read-only....