【问题标题】:Xamarin.Forms UI Automation Testing WaitForElement WebView always times outXamarin.Forms UI 自动化测试 WaitForElement WebView 总是超时
【发布时间】:2020-01-01 03:45:09
【问题描述】:

我的 Xamarin.Forms 应用使用 Azure AD B2C 进行身份验证。它工作得很好。我现在正在尝试构建 UI 自动化测试,但遇到了我的第一个阻止程序。我一直在尝试等待 WebView 出现在屏幕上,以便将测试用户的电子邮件和密码输入到我的 ui 测试自动化脚本中,但是 WaitForElement 方法总是超时!

[Test]
public void RegistrationStarts()
{
    app.Screenshot("Welcome screen.");

    app.WaitForElement(c => c.WebView());
    app.Tap(c => c.WebView().Css("input#logonIdentifier"));
    app.EnterText("sample@example.com");

}

我不知道为什么。我只在Android中进行测试。我注意到 Azure AD B2C 登录 Web 视图似乎在我的应用程序中。我可以这么说,因为当我打开 Android 任务切换器时,我可以看到 Chrome 和我的应用程序。

【问题讨论】:

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


    【解决方案1】:

    您在 id 之前使用 input 有什么原因吗?如果 logonIdentifier 是您想要输入的任何内容的 ID,它应该只是

    app.Tap(c => c.WebView().Css("#logonIdentifier"));
    

    另外,如果 logonIdentifier 是您要在其中键入的 TextBox,则输入文本应该是

    _app.EnterText(c => c.WebView().Css("#logonIdentifier"), "sample@example.com");
    

    【讨论】:

      【解决方案2】:

      您可以尝试等待具有超时的元素 - 以毫秒、秒和分钟为单位的时间。

      app.WaitForElement(x => x.Marked("AutomationID"), timeout:TimeSpan.FromSeconds(90));

      https://docs.microsoft.com/en-us/dotnet/api/xamarin.uitest.iapp.waitforelement?view=xamarin-uitest-sdk

      【讨论】:

        【解决方案3】:

        您似乎使用的是systembrowser 而不是WebView

        使用 WebView 更改获取令牌的方法。

        AuthenticationResult authResult = await _pca.AcquireTokenInteractive(B2CConstants.Scopes)
                        .WithUseEmbeddedWebView(true)
                        .ExecuteAsync();
        

        https://github.com/microsoft/appcenter/issues/287#issuecomment-484151924

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-10-13
          • 1970-01-01
          • 2010-11-24
          • 1970-01-01
          相关资源
          最近更新 更多