Xamarin自动登录凭据,适用于Google Play的发布前报告 [英] Xamarin automatic sign-in credentials for Google Play's pre-launch report
问题描述
我正在Visual Studio 2017中使用Xamarin Forms 3构建Android应用程序并将其发布到Google Play.Google Play提供了自动测试功能(发布前的报告),但是它无法通过我的登录屏幕.
I am building an Android application with Xamarin Forms 3 in Visual Studio 2017 and publishing to Google Play. Google Play offers automated testing (pre-launch report) but it cannot get past my sign-in screen.
Google Play可以输入用户名资源名称",密码资源名称"和登录按钮资源名称".我为每个控件( txtEmail
, txtPass
和 btnSignIn
)提供了Xamarin x:name,但是显然这是不正确的,因为自动测试人员仍然无法进入,甚至都没有尝试.
Google Play has a place to enter the "username resource name", "password resource name", and "sign-in button resource name". I provided the Xamarin x:name for each control (txtEmail
, txtPass
, and btnSignIn
), but apparently that is not correct, because the automated tester still can't get in and isn't even trying.
这是我的SignIn.xaml:
Here is my SignIn.xaml:
<Entry x:Name="txtEmail" Placeholder="email address" Keyboard="Email" />
<Entry x:Name="txtPass" IsPassword="True" />
<Button x:Name="btnSignIn" Text="Sign In" Clicked="OnSignInClicked" />
I've found these SO questions (here, here, and here) but they do not address my question from within a Xamarin Forms context. The first link seems particularly helpful but I do not know where to put that XML code.
在我看来Xamarin/C#被编译"为Android代码并生成这些XML文件.我该如何处理?
It seems to me that Xamarin/C# is "compiled" into Android code and generates these XML files. How can I work with this process?
我知道.APK文件只是一个ZIP文件.将发送给Google Play的APK文件重命名为.zip,我可以浏览内容,但是看不到任何有意义的XML代码.
I understand an .APK file is just a ZIP file. Renaming the APK file I send to Google Play to .zip I'm able to browse the contents, but I do not see any XML code that makes sense.
目前,我添加了一个额外的演示"按钮,单击该按钮后,会将用户名和密码放入字段中,然后单击登录"按钮.Google的自动化测试仪喜欢这种方法并且可以使用,但是对于人工测试来说这是一个糟糕的主意,我想删除这种解决方法.
For the moment, I added an extra "demo" button that, on click, puts a username and password into the fields and clicks the Sign In button. Google's automated tester likes this and can get in, but it's a terrible idea for human testing and I'd like to remove this workaround.
推荐答案
我最近也遇到了同样的问题.我提交了一个Alpha版本,启用了启动前报告,并收到一条违反政策的错误,说未提供登录凭据.正如问题中所述,我应该提供资源名称以及测试凭证,但是在Xamarin.Forms项目中如何实现却并不明显.不过,我能够使用渲染器解决该问题.我知道,创建一个单独的渲染器和一个仅用于设置id的控件有点极端,但是我真的不想大幅更改UI,因此,我创建了3个空控件:
I've faced the same issue recently. I submitted an alpha build, enabled pre-launch report and got a policy violation error saying, that sign-in credentials are not provided. As it's stated in the question, I should have provided resource names along with the test credentials, but it wasn't obvious how to do it in Xamarin.Forms project. Nevertheless, I was able to workaround it using renderers. I know, it's a bit extreme to create a separate renderer and a control just to set id, but I really didn't want to change UI significantly, so, I created 3 empty controls:
public class UsernameEntry : Entry { }
public class PasswordEntry : Entry { }
public class LoginButton : Button { }
并分别在登录屏幕上的相应位置使用了它们,而不是使用简单的条目和按钮.
And used each of them in corresponding places on the login screen, instead of plain entries and the button.
然后我将 ids.xml
文件添加到Android项目( Resource/values/ids.xml )中,并添加了3个ID,每个控件一个:
Then I added ids.xml
file into the Android project (Resource/values/ids.xml) and added 3 ids, one for every control:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="username_entry" type="id"/>
<item name="password_entry" type="id"/>
<item name="login_button" type="id"/>
</resources>
最后,我在本机Android项目中创建了3个渲染器,每个控件一个.例如,这是 UsernameEntryRenderer
的外观:
Finally, I created 3 renderers in the native Android project, one for each control. For example, this is how the UsernameEntryRenderer
looks:
[assembly: ExportRenderer(typeof(UsernameEntry), typeof(UsernameEntryRenderer))]
namespace Android.Renderers
{
public class UsernameEntryRenderer : EntryRenderer
{
public UsernameEntryRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
// here I can reference the id created previously in ids.xml file
// and set the native android id property
Control.Id = Resource.Id.username_entry;
}
}
}
}
这不是完美的方法,但就我而言,它效果很好.我不需要彻底更改UI或引入一些隐藏的UI元素.希望这会对遇到类似问题的人有所帮助.
This is not the perfect way, but it worked well in my case. I didn't need to change the UI drastically or to introduce some hidden UI elements. Hopefully, this will be helpful for anyone facing similar problem.
这篇关于Xamarin自动登录凭据,适用于Google Play的发布前报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!