【问题标题】:Q: AutomationId not getting set on Android with Forms问:AutomationId 没有在 Android 上通过 Forms 设置
【发布时间】:2018-11-13 13:26:01
【问题描述】:

我有一套用于 Xamarin Forms 项目的 UITest。所有的 AutomationId 都存在于 XAML 文件中,并且在 iOS 项目上工作正常。但是,在 Android 上运行测试时,AutomationId 不存在,这导致我的测试失败。

我已经使用 REPL 和树进行了双重检查,以检查每个视图的 ID

【问题讨论】:

  • 你能把有问题的代码贴出来吗?
  • 你的问题解决了吗?

标签: xamarin xamarin.forms xamarin-test-cloud


【解决方案1】:

你是在初始化Android原生项目中MainActivityOnCreate中的AutomationId吗?

Xamarin.Forms.Forms.Init (this, bundle); 之后:

Xamarin.Forms.Forms.ViewInitialized += (object sender, Xamarin.Forms.ViewInitializedEventArgs e) => {
   if (!string.IsNullOrWhiteSpace (e.View.AutomationId)) {
      e.NativeView.ContentDescription = e.View.AutomationId;
   }
};

【讨论】:

  • 是的,我仔细检查了。也做了一个干净的构建。
  • @Mike 那个代表有没有被叫过?
  • 是的,它正在被调用。我走过,AutomationId 正在设置,但是在运行实际测试或查看REPL 中的tree 时,AutomationId 不存在。
【解决方案2】:

在使用 Xamarin Forms 构建的 android 应用程序中,自动化 ID 被转换为 cont-desc。您可以使用 cont-desc 进行测试。

【讨论】:

    【解决方案3】:

    在 REPL 中没有可见的automationId 本身,只有标签或id 的值等于automationId 上设置的值,所以你应该只使用Marked 传入值。

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 2019-06-21
      • 1970-01-01
      • 1970-01-01
      • 2016-03-09
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      相关资源
      最近更新 更多