如果登录时应用程序中显示弹出窗口 我想点击确定 如果它没有出现 我希望测试继续

if a pop up shows in the app on login I want to tap the ok if it does not appear I want the test to continue

它的 Xamarin 和使用 if else 导致 errors.I 在下面尝试过,但它给了我很多问题,否则无法开始一行和其他问题。可能有更好的方法可以做到这一点,但我尝试过的一切都是一个问题。这对 Android 和 IoS 都有效吗?我用谷歌搜索了这个,然后去了 xamarin 文档,但它的答案并不容易。

        if( app.Query(x => x.Id("button2").Invoke("exists","button2")));
        { app.Tap("button2");
        } {}
        else {
            app.WaitForElement(x => x.Id("contentPanel"), timeout: TimeSpan.FromSeconds(120));

您可以尝试将 Xamarin 查询分配给一个变量,而不是调用 'exisits' 方法。请尝试以下操作:

var okButton = app.Query(x => x.Id("button2")).SingleOrDefault();

if(okButton != null)
{
    app.Tap(x => x.Id("button2"))
}
else 
{
    app.WaitForElement(x => x.Id("contentPanel"), timeout: TimeSpan.FromSeconds(120));
}