Exemplo n.º 1
0
        public static void NavigateToIssue(Type type, IApp app)
        {
            var typeIssueAttribute = type.GetTypeInfo().GetCustomAttribute <IssueAttribute>();

            string cellName = "";

            if (typeIssueAttribute.IssueTracker.ToString() != "None" &&
                typeIssueAttribute.IssueNumber != 1461 &&
                typeIssueAttribute.IssueNumber != 342)
            {
                cellName = typeIssueAttribute.DisplayName;
            }
            else
            {
                cellName = typeIssueAttribute.Description;
            }

            int maxAttempts = 2;
            int attempts    = 0;

            while (attempts < maxAttempts)
            {
                attempts += 1;

                try
                {
                    // Attempt the direct way of navigating to the test page
#if __ANDROID__
                    if (bool.Parse((string)app.Invoke("NavigateToTest", cellName)))
                    {
                        return;
                    }
#endif
#if __IOS__
                    if (bool.Parse(app.Invoke("navigateToTest:", cellName).ToString()))
                    {
                        return;
                    }
#endif

#if __WINDOWS__
                    // Windows doens't have an 'invoke' option right now for us to do the more direct navigation
                    // we're using for Android/iOS
                    // So we're just going to use the 'Reset' method to bounce the app to the opening screen
                    // and then fall back to the old manual navigation
                    WindowsTestBase.Reset();
#endif
                }
                catch (Exception ex)
                {
                    var debugMessage = $"Could not directly invoke test; using UI navigation instead. {ex}";

                    System.Diagnostics.Debug.WriteLine(debugMessage);
                    Console.WriteLine(debugMessage);
                }

                try
                {
                    // Fall back to the "manual" navigation method
                    app.Tap(q => q.Button("Go to Test Cases"));
                    app.WaitForElement(q => q.Raw("* marked:'TestCasesIssueList'"));

                    app.EnterText(q => q.Raw("* marked:'SearchBarGo'"), cellName);

                    app.WaitForElement(q => q.Raw("* marked:'SearchButton'"));
                    app.Tap(q => q.Raw("* marked:'SearchButton'"));

                    return;
                }
                catch (Exception ex)
                {
                    var debugMessage = $"Both navigation methods failed. {ex}";

                    System.Diagnostics.Debug.WriteLine(debugMessage);
                    Console.WriteLine(debugMessage);

                    if (attempts < maxAttempts)
                    {
                        // Something has failed and we're stuck in a place where we can't navigate
                        // to the test. Usually this is because we're getting network/HTTP errors
                        // communicating with the server on the device. So we'll try restarting the app.
                        RunningApp = InitializeApp();
                    }
                    else
                    {
                        // But if it's still not working after [maxAttempts], we've got assume this is a legit
                        // problem that restarting won't fix
                        throw;
                    }
                }
            }
        }
Exemplo n.º 2
0
 static IApp InitializeUWPApp()
 {
     return(WindowsTestBase.ConfigureApp());
 }