Пример #1
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();
        }
Пример #2
0
        public void ErrorCloseWindowAlreadyClosedApplication()
        {
            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);

            // Attempt to close the previously closed application window
            try
            {
                singleWindowSession.Close();
                Assert.Fail("Exception should have been thrown");
            }
            catch (System.InvalidOperationException e)
            {
                Assert.AreEqual("Currently selected window has been closed", e.Message);
            }

            singleWindowSession.Quit();
        }
Пример #3
0
 public static void TearDown()
 {
     _camtasiaSession.Close();
     _mainWindowView.DismissSaveDialog();
     _desktopSession.Close();
     _winAppDriver.Kill();
 }
Пример #4
0
        private static void Main(string[] args)
        {
            //Before run: C:\Program Files (x86)\Windows Application Driver run WinAppDriver.exe
            WindowsDriver <WindowsElement> driver;

            AppiumOptions appOptions = new AppiumOptions();

            appOptions.AddAdditionalCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
            appOptions.AddAdditionalCapability("deviceName", "WindowsPC");
            driver = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appOptions);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

            var genView = new GeneralView(driver);

            genView.Number_1.Click();
            genView.PlusButton.Click();
            genView.Number_2.Click();
            genView.PlusButton.Click();
            genView.Number_3.Click();
            genView.EqualButton.Click();

            Assert.AreEqual("6", genView.ResultTextLabel.Text.Split(':').Last().Trim());

            driver.Close();
        }
Пример #5
0
        public void TestWaitForElementToAppear()
        {
            var cap = new AppiumOptions();

            cap.AddAdditionalCapability(MobileCapabilityType.App, "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
            cap.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Windows");
            cap.AddAdditionalCapability(MobileCapabilityType.DeviceName, "WindowsPC");
            var appiumLocalServer = new AppiumServiceBuilder().UsingAnyFreePort().Build();

            appiumLocalServer.Start();
            var driver = new WindowsDriver <WindowsElement>(appiumLocalServer, cap);

            // Wait until an element appears
            var wait = new DefaultWait <WindowsDriver <WindowsElement> >(driver)
            {
                Timeout         = TimeSpan.FromSeconds(60),
                PollingInterval = TimeSpan.FromMilliseconds(500)
            };

            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            wait.Until(x => x.FindElementByAccessibilityId("num7Button"));

            driver.Close();
            driver.Dispose();
        }
Пример #6
0
        public void TestFindElement()
        {
            var appId        = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App";
            var platformName = "Windows";
            var deviceName   = "WindowsPC";
            var cap          = new AppiumOptions();

            cap.AddAdditionalCapability(MobileCapabilityType.App, appId);
            cap.AddAdditionalCapability(MobileCapabilityType.PlatformName, platformName);
            cap.AddAdditionalCapability(MobileCapabilityType.DeviceName, deviceName);
            var appiumLocalServer = new AppiumServiceBuilder().UsingAnyFreePort().Build();

            appiumLocalServer.Start();
            var driver = new WindowsDriver <WindowsElement>(appiumLocalServer, cap);

            var btn7      = MobileBy.AccessibilityId("num7Button");
            var btn1      = MobileBy.AccessibilityId("num1Button");
            var btnEquals = MobileBy.AccessibilityId("equalButton");
            var btnPlus   = MobileBy.AccessibilityId("plusButton");

            driver.FindElement(btn7).Click();
            driver.FindElement(btn7).Click();
            driver.FindElement(btnPlus).Click();
            driver.FindElement(btn1).Click();
            driver.FindElement(btn1).Click();
            driver.FindElement(btnEquals).Click();

            driver.Close();
            driver.Dispose();
        }
        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;
            }
        }
Пример #8
0
 public void CleanUp()
 {
     if (_driver != null)
     {
         _driver.Close();
     }
 }
Пример #9
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;
        }
Пример #10
0
        public void TestMethod1()
        {
            // Launch the calculator app
            //DesiredCapabilities appCapabilities = new DesiredCapabilities();
            //appCapabilities.SetCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
            //var CalculatorSession = new RemoteWebDriver(new Uri(" http://127.0.0.1:4723/"), appCapabilities);

            var options = new AppiumOptions();

            options.AddAdditionalCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");

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

            Assert.IsNotNull(CalculatorSession);

            CalculatorSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);

            CalculatorSession.FindElementByName("One").Click();
            CalculatorSession.FindElementByName("Plus").Click();
            CalculatorSession.FindElementByName("Seven").Click();
            CalculatorSession.FindElementByName("Equals").Click();

            var CalculatorResults = CalculatorSession.FindElementByAccessibilityId("CalculatorResults");

            Assert.AreEqual("Display is 8", CalculatorResults.Text);

            CalculatorSession.Close();
        }
Пример #11
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;
            }
        }
Пример #12
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();
        }
Пример #13
0
        public void TestMethod2()
        {
            // lets do it with M4
            var options = new AppiumOptions();

            options.AddAdditionalCapability("app", @"C:\Program Files (x86)\M4Solutions\M4Solutions.exe");

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

            Assert.IsNotNull(driver);

            var appWindow           = driver.FindElementByAccessibilityId("MDIForm1");
            var projectCenterWindow = appWindow.FindElementByAccessibilityId("ProjectCenter");

            // lets open a project (a bit!)
            var pickProjectButton = projectCenterWindow.FindElementByAccessibilityId("btnPickProject");

            pickProjectButton.Click();

            var openDialog      = appWindow.FindElementByName("Open");
            var fileNameTextBox = openDialog.FindElementByAccessibilityId("1148");

            fileNameTextBox.SendKeys(@"E:\clients\mapcom\M4 Regression Test Automation\Test Project\Diversicom\ARVIG.prj");

            var openButton = openDialog.FindElementByAccessibilityId("1");

            openButton.Click();

            driver.Close();
        }
Пример #14
0
 public static void Cleanup()
 {
     if (session != null)
     {
         session.Close();
         session.Quit();
     }
 }
Пример #15
0
 private static void InitializeOrphanedSession()
 {
     // Create new calculator session and close the window to get an orphaned element
     CleanupOrphanedSession();
     orphanedSession      = CreateNewSession(CommonTestSettings.CalculatorAppId);
     orphanedElement      = orphanedSession.FindCalculatorTitleByAccessibilityId();
     orphanedWindowHandle = orphanedSession.CurrentWindowHandle;
     orphanedSession.Close();
 }
Пример #16
0
        public void GetWindowHandlesModernApp()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId);
            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);

            // Preserve previously opened Edge window(s) and only manipulate newly opened windows
            List <String> previouslyOpenedEdgeWindows = new List <String>(windowHandlesBefore);

            previouslyOpenedEdgeWindows.Remove(multiWindowsSession.CurrentWindowHandle);

            // Open a new window
            // The menu item names have changed between Windows 10 and the anniversary update
            // account for both combinations.
            try
            {
                multiWindowsSession.FindElementByAccessibilityId("m_actionsMenuButton").Click();
                multiWindowsSession.FindElementByAccessibilityId("m_newWindow").Click();
            }
            catch (System.InvalidOperationException)
            {
                multiWindowsSession.FindElementByAccessibilityId("ActionsMenuButton").Click();
                multiWindowsSession.FindElementByAccessibilityId("ActionsMenuNewWindow").Click();
            }

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

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

            // Preserve previously opened Edge Windows by only closing newly opened windows
            List <String> newlyOpenedEdgeWindows = new List <String>(windowHandlesAfter);

            foreach (var previouslyOpenedEdgeWindow in previouslyOpenedEdgeWindows)
            {
                newlyOpenedEdgeWindows.Remove(previouslyOpenedEdgeWindow);
            }

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

            multiWindowsSession.Quit();
        }
Пример #17
0
 public static void ClassCleanupTwo()
 {
     // Close the application and delete the session
     if (session != null)
     {
         session.Close();
         session.Quit();
         session = null;
     }
 }
Пример #18
0
 public static void TearDown()
 {
     // Close the application and delete the session
     if (desktopSession != null)
     {
         desktopSession.Close();
         desktopSession.Quit();
         desktopSession = null;
     }
 }
Пример #19
0
        public void Launch_SystemApp()
        {
            session = Utility.CreateNewSession(CommonTestSettings.ExplorerAppId);
            var originalSessionId            = session.SessionId;
            var originalTitle                = session.Title;
            var originalWindowHandlesCount   = session.WindowHandles.Count;
            var originalLaunchedWindowHandle = session.CurrentWindowHandle;

            // Re-launch Windows Explorer in the same session using the same capabilities configuration
            // This will create a new explorer window and point the current active session to it
            session.LaunchApp();
            Assert.AreEqual(originalSessionId, session.SessionId);
            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();
        }
Пример #20
0
        private static void ClosePaint()
        {
            try
            {
                ourSession.Close();
                string currentHandle = ourSession.CurrentWindowHandle;

                DismissSaveConfirmDialog();
            }
            catch { }
        }
Пример #21
0
        public void Launch_ModernApp()
        {
            session = Utility.CreateNewSession(CommonTestSettings.CalculatorAppId);
            var originalSessionId            = session.SessionId;
            var originalTitle                = session.Title;
            var originalWindowHandlesCount   = session.WindowHandles.Count;
            var originalLaunchedWindowHandle = session.CurrentWindowHandle;

            // Re-launch calculator application in the same session using the same capabilities configuration
            // This will create a new calculator window and point the current active session to it
            session.LaunchApp();
            Assert.AreEqual(originalSessionId, session.SessionId);
            Assert.IsTrue(originalTitle.Contains(session.Title));
            Assert.AreEqual(originalWindowHandlesCount + 1, session.WindowHandles.Count);
            Assert.AreNotEqual(originalLaunchedWindowHandle, session.CurrentWindowHandle);

            session.Close();
            session.SwitchTo().Window(originalLaunchedWindowHandle);
            session.Close();
        }
Пример #22
0
        public static void Teardown()
        {
            if (session != null)
            {
                session.Close();

                session.Quit();

                session = null;
            }
        }
Пример #23
0
        public static void TearDown()
        {
            // Close the application and delete the session
            if (session != null)
            {
                session.Close();
                session.Quit();
                session = null;
            }

            StopWinAppDriver();
        }
Пример #24
0
        public static void TearDown()
        {
            if (session == null)
            {
                return;
            }
            session.Close();
            session.Quit();
            session = null;

            StopCommand.Execute();
        }
Пример #25
0
 public static void CloseRadar(WindowsDriver <WindowsElement> radarSession)
 {
     try
     {
         //close
         radarSession.Close();
         //verify
     }
     catch
     {
     }
 }
        private static void ClosePaint3D()
        {
            try
            {
                session.Close();
                string currentHandle = session.CurrentWindowHandle; // This should throw if the window is closed successfully

                // When the Paint 3D window remains open because of save confirmation dialog, attempt to close modal dialog
                DismissSaveConfirmDialog();
            }
            catch { }
        }
Пример #27
0
        public void CloseWindow()
        {
            session = Utility.CreateNewSession(CommonTestSettings.AlarmClockAppId);
            Assert.IsNotNull(session.SessionId);

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

            // Delete the session
            session.Quit();
        }
Пример #28
0
        public static void CloseEdge(WindowsDriver <WindowsElement> edgeSession)
        {
            try
            {
                edgeSession.Close();
                var currentHandle = edgeSession.CurrentWindowHandle; // This should throw if the window is closed successfully

                // When the Edge window remains open because of multiple tabs are open, attempt to close modal dialog
                var closeAllButton = edgeSession.FindElementByXPath("//Button[@Name='Close all']");
                closeAllButton.Click();
            }
            catch { }
        }
Пример #29
0
        protected RemoteWebElement GetOrphanedElement(WindowsDriver <WindowsElement> remoteSession)
        {
            RemoteWebElement orphanedElement = null;

            // Track existing opened Edge window(s) and only manipulate newly opened windows
            var previouslyOpenedEdgeWindows = remoteSession.WindowHandles;
            var originalActiveWindowHandle  = remoteSession.CurrentWindowHandle;

            // Open a new window
            // The menu item names have changed between Windows 10 and the anniversary update
            // account for both combinations.
            try
            {
                remoteSession.FindElementByAccessibilityId("m_actionsMenuButton").Click();
                remoteSession.FindElementByAccessibilityId("m_newWindow").Click();
            }
            catch (System.InvalidOperationException)
            {
                remoteSession.FindElementByAccessibilityId("ActionsMenuButton").Click();
                remoteSession.FindElementByAccessibilityId("ActionsMenuNewWindow").Click();
            }

            System.Threading.Thread.Sleep(3000); // Sleep for 3 second
            var multipleWindowHandles = remoteSession.WindowHandles;

            Assert.IsTrue(multipleWindowHandles.Count == previouslyOpenedEdgeWindows.Count + 1);

            // Ensure we get the newly opened window by removing other previously known windows from the list
            List <String> newlyOpenedEdgeWindows = new List <String>(multipleWindowHandles);

            foreach (var previouslyOpenedEdgeWindow in previouslyOpenedEdgeWindows)
            {
                newlyOpenedEdgeWindows.Remove(previouslyOpenedEdgeWindow);
            }
            Assert.IsTrue(newlyOpenedEdgeWindows.Count == 1);

            // Switch to new window and use the address edit box as orphaned element
            remoteSession.SwitchTo().Window(newlyOpenedEdgeWindows[0]);
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second
            Assert.AreEqual(newlyOpenedEdgeWindows[0], remoteSession.CurrentWindowHandle);
            orphanedElement = remoteSession.FindElementByAccessibilityId("addressEditBox");
            Assert.IsNotNull(orphanedElement);

            // Close the newly opened window and return to previously active window
            remoteSession.Close();
            remoteSession.SwitchTo().Window(originalActiveWindowHandle);
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second

            return(orphanedElement);
        }
Пример #30
0
        public static void TearDown()
        {
            // Cleanup RemoteTouchScreen object if initialized
            touchScreen = null;

            // Close the application and delete the session
            if (session != null)
            {
                try
                {
                    session.Close();
                    var currentHandle = session.CurrentWindowHandle; // This should throw if the window is closed successfully

                    // When the Edge window remains open because of multiple tabs are open, attempt to close modal dialog
                    var closeAllButton = session.FindElementByXPath("//Button[@Name='Close all']");
                    closeAllButton.Click();
                }
                catch { }

                session.Quit();
                session = null;
            }
        }