Exemplo n.º 1
0
        public static void CreateSession(TestContext _)
        {
            if (_session == null)
            {
                int timeoutCount = 50;

                tryInitializeSession();
                if (_session == null)
                {
                    // WinAppDriver is probably not running, so lets start it!
                    if (File.Exists(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe"))
                    {
                        Process.Start(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe");
                    }
                    else if (File.Exists(@"C:\Program Files\Windows Application Driver\WinAppDriver.exe"))
                    {
                        Process.Start(@"C:\Program Files\Windows Application Driver\WinAppDriver.exe");
                    }
                    else
                    {
                        throw new Exception("Unable to start WinAppDriver since no suitable location was found.");
                    }

                    Thread.Sleep(10000);
                    tryInitializeSession();
                }

                while (_session == null && timeoutCount < 1000 * 4)
                {
                    tryInitializeSession();
                    Thread.Sleep(timeoutCount);
                    timeoutCount *= 2;
                }

                Thread.Sleep(3000);
                Assert.IsNotNull(_session);
                Assert.IsNotNull(_session.SessionId);

                // Dismiss the disclaimer window that may pop up on the very first application launch
                // If the disclaimer is not found, this throws an exception, so lets catch that
                try
                {
                    _session.FindElementByName("Disclaimer").FindElementByName("Accept").Click();
                }
                catch (OpenQA.Selenium.WebDriverException) { }

                // Wait if something is still animating in the visual tree
                _session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
                _session.Manage().Window.Maximize();

                AxeHelper.InitializeAxe();
            }
        }