Пример #1
0
 public void Test1()
 {
     if (_driver != null)
     {
         _driver.Quit();
         _driver = null;
     }
 }
Пример #2
0
        public void GetSessionsSingleEntry()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.AlarmClockAppId);
            WindowsDriver <WindowsElement> session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

            Assert.IsNotNull(session);

            using (HttpWebResponse response = WebRequest.Create(CommonTestSettings.WindowsApplicationDriverUrl + "/sessions").GetResponse() as HttpWebResponse)
            {
                var     responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                JObject responseObject = JObject.Parse(responseString);
                Assert.AreEqual(0, (int)responseObject["status"]);

                JArray capabilitiesArray = (JArray)responseObject["value"];
                Assert.AreEqual(1, capabilitiesArray.Count);

                JToken firstEntry = capabilitiesArray[0];
                Assert.AreEqual(session.SessionId.ToString(), firstEntry["id"].ToString());
                Assert.AreEqual(CommonTestSettings.AlarmClockAppId, firstEntry["capabilities"]["app"].ToString());
            }

            session.Quit();
        }
Пример #3
0
 public static void WinAppDriverQuit()
 {
     if (winAppDriverInstance != null)
     {
         winAppDriverInstance.Quit();
     }
 }
Пример #4
0
        public static void TearDown()
        {
            if (browserSession != null)
            {
                browserSession.Quit();
                browserSession = null;
            }

            if (desktopSession != null)
            {
                desktopSession.Quit();
                desktopSession = null;
            }

            // stop winappdriver
            if (myProcess != null)
            {
                myProcess.CloseMainWindow();
            }

            // stop webdriver
            if (_driver != null)
            {
                _driver.Quit();
            }
        }
Пример #5
0
        public void SendKeys_ModifierWindowsKey()
        {
            WindowsDriver <WindowsElement> desktopSession = Utility.CreateNewSession(CommonTestSettings.DesktopAppId);

            Assert.IsNotNull(desktopSession);

            // Launch action center using Window Keys + A
            session.Keyboard.PressKey(Keys.Command + "a" + Keys.Command);
            WindowsElement actionCenterElement = null;

            // Before Windows 10 Anniversary and Creators Update Action Center name had lower case c for "center"
            try
            {
                actionCenterElement = desktopSession.FindElementByName("Action Center");
            }
            catch
            {
                actionCenterElement = desktopSession.FindElementByName("Action center");
            }

            Assert.IsNotNull(actionCenterElement);

            // Dismiss action center and cleanup the temporary session
            actionCenterElement.SendKeys(Keys.Escape);
            editBox.Click();
            desktopSession.Quit();
        }
Пример #6
0
        public void SoapUITest()
        {
            AppiumOptions appOptions = new AppiumOptions();

            appOptions.AddAdditionalCapability("app", @"C:\Program Files (x86)\SmartBear\SoapUI-5.5.0\bin\SoapUI-5.5.0.exe");
            appOptions.AddAdditionalCapability("ms:waitForAppLaunch", "15");
            WindowsDriver <WindowsElement> SOAPUISession = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appOptions);

            Console.WriteLine("WindowsDriver is initialized");
            Console.WriteLine("Application Title:" + SOAPUISession.Title);
            AppiumWebElement EndPointExpClose = SOAPUISession.FindElementByName("Endpoint Explorer").FindElementByName("Close");

            EndPointExpClose.Click();
            Console.WriteLine("Endpoint explorer window is closed");

            SOAPUISession.Manage().Window.Maximize();
            Console.WriteLine("SOAPUI tool window is maximized");

            SOAPUISession.FindElementByName("Close").Click();
            Console.WriteLine("Close button is clicked");

            SOAPUISession.FindElementByName("Question").SendKeys(Keys.Enter);

            Console.WriteLine("SOAPUI application is closed");

            SOAPUISession.Quit();
        }
        public void TestInitialize()
        {
            isWinKeyPressed = false;

            // If the start menu is open, close it.
            WindowsElement startMenuWindow = null;

            try
            {
                startMenuWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Window[@Name=\"Start\"]");
            }
            catch (Exception)
            {
                //Start menu not found, as expected.
            }
            if (startMenuWindow != null)
            {
                string startMenuWindowHandle = (int.Parse(startMenuWindow.GetAttribute("NativeWindowHandle"))).ToString("x");
                // Create session for controlling the Start Menu.
                AppiumOptions appiumOptions = new AppiumOptions();
                appiumOptions.PlatformName = "Windows";
                appiumOptions.AddAdditionalCapability("appTopLevelWindow", startMenuWindowHandle);
                WindowsDriver <WindowsElement> startMenuSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions);
                if (startMenuSession != null)
                {
                    new Actions(session).SendKeys(OpenQA.Selenium.Keys.Escape + OpenQA.Selenium.Keys.Escape).Perform();
                    startMenuSession.Quit();
                }
            }
        }
Пример #8
0
        public void ErrorGetClosedSessionElementScreenshot()
        {
            // Launch calculator for this specific test case
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.CalculatorAppId);
            WindowsDriver <WindowsElement> calculatorSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

            Assert.IsNotNull(calculatorSession);
            Assert.IsNotNull(calculatorSession.SessionId);

            try
            {
                calculatorSession.Close();
                WindowsElement element = calculatorSession.FindElementByAccessibilityId("AppNameTitle");
                element.GetScreenshot();
                Assert.Fail("Exception should have been thrown because there is no such window");
            }
            catch (System.InvalidOperationException exception)
            {
                Assert.AreEqual("Currently selected window has been closed", exception.Message);
            }

            calculatorSession.Quit();
            calculatorSession = null;
        }
Пример #9
0
        public void NavigateForwardSystemApp()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.ExplorerAppId);
            session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(session);

            var originalTitle = session.Title;
            //Assert.AreNotEqual(String.Empty, originalTitle);

            // Navigate Windows Explorer to change folder
            var targetLocation  = @"%TEMP%\";
            var addressBandRoot = session.FindElementByClassName("Address Band Root");
            var addressToolbar  = addressBandRoot.FindElementByAccessibilityId("1001"); // Address Band Toolbar

            session.Mouse.Click(addressToolbar.Coordinates);
            addressBandRoot.FindElementByAccessibilityId("41477").SendKeys(targetLocation + OpenQA.Selenium.Keys.Enter);
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second
            var newTitle = session.Title;

            Assert.AreNotEqual(originalTitle, newTitle);

            // Navigate back to the original folder
            session.Navigate().Back();
            Assert.AreEqual(originalTitle, session.Title);

            // Navigate forward to the target folder
            session.Navigate().Forward();
            Assert.AreEqual(newTitle, session.Title);

            session.Quit();
        }
Пример #10
0
        public void NavigateForwardBrowser()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId);
            session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(session);

            session.FindElementByAccessibilityId("addressEditBox").SendKeys(CommonTestSettings.MicrosoftUrl + OpenQA.Selenium.Keys.Enter);
            System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
            var originalTitle = session.Title;

            Assert.AreNotEqual(String.Empty, originalTitle);

            // Navigate to different URLs
            session.FindElementByAccessibilityId("addressEditBox").SendKeys(CommonTestSettings.GitHubUrl + OpenQA.Selenium.Keys.Enter);
            System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
            var newTitle = session.Title;

            Assert.AreNotEqual(originalTitle, newTitle);

            // Navigate back to original URL
            session.Navigate().Back();
            System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
            Assert.AreEqual(originalTitle, session.Title);

            // Navigate forward to original URL
            session.Navigate().Forward();
            System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
            Assert.AreEqual(newTitle, session.Title);

            session.Quit();
        }
Пример #11
0
        public static void TearDown()
        {
            //restore initial settings files
            if (_initialSettings.Length > 0)
            {
                File.WriteAllText(_settingsPath, _initialSettings);
            }
            else
            {
                File.Delete(_settingsPath);
            }

            if (_initialZoneSettings.Length > 0)
            {
                File.WriteAllText(_zoneSettingsPath, _initialZoneSettings);
            }
            else
            {
                File.Delete(_zoneSettingsPath);
            }

            if (session != null)
            {
                session.Quit();
                session = null;
            }
        }
Пример #12
0
        public void ErrorGetWindowHandleAlreadyClosedApplication()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.AlarmClockAppId);
            WindowsDriver <WindowsElement> singleWindowSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

            Assert.IsNotNull(singleWindowSession);
            Assert.IsNotNull(singleWindowSession.SessionId);

            // Close the application window without deleting the session
            singleWindowSession.Close();
            Assert.IsNotNull(singleWindowSession);
            Assert.IsNotNull(singleWindowSession.SessionId);

            try
            {
                string windowHandle = singleWindowSession.CurrentWindowHandle;
                Assert.Fail("Exception should have been thrown");
            }
            catch (System.InvalidOperationException e)
            {
                Assert.AreEqual("Currently selected window has been closed", e.Message);
            }

            singleWindowSession.Quit();
        }
Пример #13
0
 public void Teardown()
 {
     if (calcSession != null)
     {
         calcSession.Quit();
     }
 }
Пример #14
0
        public void LaunchSystemApp()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.ExplorerAppId);
            WindowsDriver <WindowsElement> session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

            Assert.IsNotNull(session);
            Assert.IsNotNull(session.SessionId);

            var originalTitle = session.Title;
            var originalWindowHandlesCount   = session.WindowHandles.Count;
            var originalLaunchedWindowHandle = session.CurrentWindowHandle;

            session.LaunchApp();

            Assert.AreEqual(originalTitle, session.Title);
            Assert.AreEqual(originalWindowHandlesCount + 1, session.WindowHandles.Count);
            Assert.AreNotEqual(originalLaunchedWindowHandle, session.CurrentWindowHandle);

            session.Close();
            session.SwitchTo().Window(originalLaunchedWindowHandle);
            session.Close();
            session.Quit();
        }
Пример #15
0
        public static void TearDown()
        {
            // Close the application and delete the session
            if (session != null)
            {
                try
                {
                    // Sticky Notes applciation can be closed by explicitly closing any of the opened Sticky Notes window.
                    // Create a new session based on any of opened Sticky Notes window and close it to close the application.
                    var openedStickyNotes = session.FindElementsByClassName("ApplicationFrameWindow");
                    if (openedStickyNotes.Count > 0)
                    {
                        var newStickyNoteWindowHandle = openedStickyNotes[0].GetAttribute("NativeWindowHandle");
                        newStickyNoteWindowHandle = (int.Parse(newStickyNoteWindowHandle)).ToString("x"); // Convert to Hex

                        DesiredCapabilities appCapabilities = new DesiredCapabilities();
                        appCapabilities.SetCapability("appTopLevelWindow", newStickyNoteWindowHandle);
                        appCapabilities.SetCapability("deviceName", "WindowsPC");
                        var stickyNoteSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
                        stickyNoteSession.Close();
                    }
                }
                catch { }

                session.Quit();
                session = null;
            }
        }
Пример #16
0
        public void SendModifierWindowsKey()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", "Root");
            WindowsDriver <WindowsElement> desktopSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

            Assert.IsNotNull(desktopSession);

            // Launch action center using Window Keys + A
            editBox.SendKeys(OpenQA.Selenium.Keys.Command + "a" + OpenQA.Selenium.Keys.Command);
            WindowsElement actionCenterElement = null;

            // Before Windows 10 Anniversary and Creators Update Action Center name had lower case c for "center"
            try
            {
                actionCenterElement = desktopSession.FindElementByName("Action Center");
            }
            catch
            {
                actionCenterElement = desktopSession.FindElementByName("Action center");
            }

            Assert.IsNotNull(actionCenterElement);

            // Dismiss action center and cleanup the temporary session
            actionCenterElement.SendKeys(OpenQA.Selenium.Keys.Escape);
            editBox.Click();
            desktopSession.Quit();
        }
Пример #17
0
        public void GetWindowHandlesClassicApp()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.NotepadAppId);
            WindowsDriver <WindowsElement> multiWindowsSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

            Assert.IsNotNull(multiWindowsSession);
            Assert.IsNotNull(multiWindowsSession.SessionId);

            var windowHandlesBefore = multiWindowsSession.WindowHandles;

            Assert.IsNotNull(windowHandlesBefore);
            Assert.IsTrue(windowHandlesBefore.Count > 0);

            multiWindowsSession.FindElementByName("File").Click();
            multiWindowsSession.FindElementByName("Save As...").Click();

            System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
            var windowHandlesAfter = multiWindowsSession.WindowHandles;

            Assert.IsNotNull(windowHandlesAfter);
            Assert.AreEqual(windowHandlesBefore.Count + 1, windowHandlesAfter.Count);

            foreach (var windowHandle in windowHandlesAfter)
            {
                multiWindowsSession.SwitchTo().Window(windowHandle);
                multiWindowsSession.Close();
            }

            multiWindowsSession.Quit();
        }
Пример #18
0
        public void GetSessions_SingleEntry()
        {
            WindowsDriver <WindowsElement> session = Utility.CreateNewSession(CommonTestSettings.AlarmClockAppId);

            Assert.IsNotNull(session);

            using (HttpWebResponse response = WebRequest.Create(CommonTestSettings.WindowsApplicationDriverUrl + "/sessions").GetResponse() as HttpWebResponse)
            {
                var     responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                JObject responseObject = JObject.Parse(responseString);
                Assert.AreEqual(0, (int)responseObject["status"]);

                JArray capabilitiesArray = (JArray)responseObject["value"];
                Assert.IsTrue(capabilitiesArray.Count >= 1);

                // Verify that the newly created session is on the list
                JToken newSessionEntry = null;
                foreach (var entry in capabilitiesArray.Children())
                {
                    if (entry["id"].ToString() == session.SessionId.ToString())
                    {
                        newSessionEntry = entry;
                        break;
                    }
                }

                Assert.IsNotNull(newSessionEntry);
                Assert.AreEqual(CommonTestSettings.AlarmClockAppId, newSessionEntry["capabilities"]["app"].ToString());
            }

            session.Quit();
        }
        public void AfterAll()
        {
            // Close the application and delete the session
            if (session != null)
            {
                var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri;

                try
                {
                    // Sticky Notes applciation can be closed by explicitly closing any of the opened Sticky Notes window.
                    // Create a new session based on any of opened Sticky Notes window and close it to close the application.
                    var openedStickyNotes = session.FindElementsByClassName("ApplicationFrameWindow");
                    if (openedStickyNotes.Count > 0)
                    {
                        var newStickyNoteWindowHandle = openedStickyNotes[0].GetAttribute("NativeWindowHandle");
                        newStickyNoteWindowHandle = (int.Parse(newStickyNoteWindowHandle)).ToString("x"); // Convert to Hex

                        AppiumOptions appCapabilities = new AppiumOptions();
                        appCapabilities.AddAdditionalCapability("appTopLevelWindow", newStickyNoteWindowHandle);
                        appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC");
                        var stickyNoteSession = new WindowsDriver <WindowsElement>(serverUri, appCapabilities);
                        stickyNoteSession.Close();
                    }
                }
                catch { }

                session.Quit();
                session = null;
            }
        }
Пример #20
0
        private void CloseApplication(string applicationId)
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", applicationId);
            WindowsDriver <WindowsElement> session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

            Assert.IsNotNull(session);
            Assert.IsNotNull(session.SessionId);
            Assert.AreNotEqual(String.Empty, session.Title);
            Assert.AreNotEqual(String.Empty, session.CurrentWindowHandle);
            var originalWindowHandlesCount = session.WindowHandles.Count;

            session.CloseApp();

            System.Threading.Thread.Sleep(3000); // Sleep for 3 second
            Assert.IsNotNull(session);
            Assert.IsNotNull(session.SessionId);
            Assert.AreEqual(originalWindowHandlesCount - 1, session.WindowHandles.Count);

            try
            {
                session.CloseApp(); // Attempt to close already closed app
                Assert.Fail("Exception should have been thrown");
            }
            catch (System.InvalidOperationException exception)
            {
                Assert.AreEqual("Currently selected window has been closed", exception.Message);
            }

            session.Quit();
        }
Пример #21
0
        public void TestMethod8()
        {
            var notepad = @"C:\Windows\System32\notepad.exe";

            var options = new AppiumOptions();

            options.AddAdditionalCapability("app", notepad);

            var driver = new WindowsDriver <WindowsElement>(new Uri(" http://127.0.0.1:4723/"), options);

            var eyes = new Eyes();

            eyes.ApiKey = "lFMnO9e1nbFQEdhebrDmhEBOqB7jXUXJGogj103lRWAzM110";
            eyes.SetAppEnvironment("Windows 10", null);

            try
            {
                eyes.Open("AppiumPractice", "TestMethod8");
                Thread.Sleep(3000);
                var currentAppScreenshot = driver.GetScreenshot();
                var croppedScreenshot    = CropScreenshot(currentAppScreenshot);

                eyes.CheckImage(croppedScreenshot, "Notepad Just Opened");

                eyes.Close();
            }
            finally
            {
                eyes?.AbortIfNotClosed();
                driver.Quit();
            }
        }
 public static void ClassCleanup()
 {
     if (_driver != null)
     {
         _driver.Quit();
         _driver = null;
     }
 }
Пример #23
0
 public void TestCleanup()
 {
     if (session != null)
     {
         session.Quit();
         session = null;
     }
 }
Пример #24
0
 public void TestCleanup()
 {
     if (driver != null)
     {
         driver.Quit();
         driver = null;
     }
 }
Пример #25
0
 public static void Cleanup()
 {
     if (session != null)
     {
         session.Close();
         session.Quit();
     }
 }
Пример #26
0
 public static void EndSession()
 {
     if (_session != null)
     {
         _session.Quit();
         _session = null;
     }
 }
Пример #27
0
 public static void TearDown()
 {
     if (session != null)
     {
         session.Quit();
         session = null;
     }
 }
Пример #28
0
 public void SessionTearDown()
 {
     if (driver != null)
     {
         driver.Quit();
         driver = null;
     }
 }
Пример #29
0
 public void Dispose()
 {
     if (_driver != null)
     {
         _driver.Quit();
         _driver = null;
     }
 }
Пример #30
0
 public static void TearDown()
 {
     if (DesktopSession != null)
     {
         DesktopSession.Quit();
         DesktopSession = null;
     }
 }