Example #1
0
        public void NavigateBackBrowser()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

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

            var originalTitle = session.Title;

            Assert.AreNotEqual(String.Empty, originalTitle);

            // Navigate to different URLs
            var addressEditBox = session.FindElementByAccessibilityId("addressEditBox");

            addressEditBox.SendKeys("https://github.com/Microsoft/WinAppDriver");
            session.FindElementByAccessibilityId("m_newTabPageGoButton").Click();

            System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
            Assert.AreNotEqual(originalTitle, session.Title);

            // Navigate back to original URL
            session.Navigate().Back();
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second
            Assert.AreEqual(originalTitle, session.Title);

            session.Quit();
            session = null;
        }
Example #2
0
        public void FindElementByAccessibilityId()
        {
            IOSElement element = session.FindElementByAccessibilityId("AlarmPivotItem");

            Assert.IsNotNull(element);
            Assert.AreEqual(alarmTabElement, element);
        }
Example #3
0
        public void NavigateForwardBrowser()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId);
            session = new IOSDriver <IOSElement>(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();
        }
Example #4
0
        public void SwitchWindows()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId);

            IOSDriver <IOSElement> multiWindowsSession = new IOSDriver <IOSElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

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

            multiWindowsSession.FindElementByAccessibilityId("m_actionsMenuButton").Click();
            multiWindowsSession.FindElementByAccessibilityId("m_newWindow").Click();

            System.Threading.Thread.Sleep(1000); // Sleep for 1 second
            var windowHandlesAfter = multiWindowsSession.WindowHandles;

            Assert.IsNotNull(windowHandlesAfter);

            foreach (var windowHandle in windowHandlesAfter)
            {
                multiWindowsSession.SwitchTo().Window(windowHandle);
                Assert.AreEqual(multiWindowsSession.CurrentWindowHandle, windowHandle);
                multiWindowsSession.Close();
            }

            multiWindowsSession.Quit();
        }
Example #5
0
        public void GetWindowHandlesModernApp()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId);
            IOSDriver <IOSElement> multiWindowsSession = new IOSDriver <IOSElement>(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();
        }
Example #6
0
        public void ErrorTouchClosedWindow(string touchType)
        {
            JObject enterRequestObject = new JObject();

            enterRequestObject["element"] = session.FindElementByAccessibilityId("m_newTabPageGoButton").GetAttribute("elementId");
            session.Close();
            HttpWebResponse response = SendTouchPost(touchType, enterRequestObject);

            Assert.Fail("Exception should have been thrown because there is no such window");
        }
Example #7
0
        public void SwitchWindows()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId);
            IOSDriver <IOSElement> multiWindowsSession = new IOSDriver <IOSElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

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

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

            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 (OpenQA.Selenium.NoSuchElementException)
            {
                multiWindowsSession.FindElementByAccessibilityId("ActionsMenuButton").Click();
                multiWindowsSession.FindElementByAccessibilityId("ActionsMenuNewWindow").Click();
            }

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

            Assert.IsTrue(multipleWindowHandles.Count > 1);

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

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

            string previousWindowHandle = String.Empty;

            foreach (var windowHandle in newlyOpenedEdgeWindows)
            {
                multiWindowsSession.SwitchTo().Window(windowHandle);
                Assert.AreEqual(multiWindowsSession.CurrentWindowHandle, windowHandle);
                Assert.AreNotEqual(windowHandle, previousWindowHandle);
                previousWindowHandle = windowHandle;
                multiWindowsSession.Close();
            }

            multiWindowsSession.Quit();
        }
        public void CheckMasterDetailAndBack()
        {
            driver.LaunchApp();
            // tap on second item
            var el1 = driver.FindElementByAccessibilityId("Second item");

            TouchAction a = new TouchAction(driver);

            a.Tap(el1);


            var el2 = driver.FindElementByAccessibilityId("ItemText");

            Assert.IsTrue(el2.Text == "Second item");

            var backButton = driver.FindElementByAccessibilityId("Back");

            backButton.Click();

            var el3 = driver.FindElementByAccessibilityId("Fourth item");

            Assert.IsTrue(el3 != null);

            driver.CloseApp();
        }
Example #9
0
        public void TestShouldClickAButtonThatOpensAnAlert()
        {
            IOSElement buttonElement = driver.FindElementByAccessibilityId("show alert");

            buttonElement.Click();

            String     alertTitle        = "Cool title";
            IOSElement alertTitleElement = driver.FindElementByAccessibilityId(alertTitle);

            Assert.AreEqual(alertTitle, alertTitleElement.GetAttribute("name"));
        }
Example #10
0
        protected RemoteWebElement GetOrphanedElement(IOSDriver <IOSElement> 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 (OpenQA.Selenium.NoSuchElementException)
            {
                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);
        }
Example #11
0
        public static void ClassInitialize(TestContext context)
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.AlarmClockAppId);
            session = new IOSDriver <IOSElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(session);
            Assert.IsNotNull(session.SessionId);

            alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
            Assert.IsNotNull(alarmTabElement);

            alarmListViewElement = session.FindElementByAccessibilityId("AlarmListView");
            Assert.IsNotNull(alarmListViewElement);
        }
Example #12
0
        public void TestMethod1()
        {
            var appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", "93011e2b-f3e0-4b2c-9307-fe76414c4d3e_e4thgbjj8qbka!App");
            //using (var appSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities))
            using (var appSession = new IOSDriver <IOSElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities))
            {
                var button1Elem = appSession.FindElementByAccessibilityId("Button1") as IOSElement;
                Assert.IsNotNull(button1Elem);
                button1Elem.Click();
                var textBox1Elem = appSession.FindElementByAccessibilityId("TextBox1") as IOSElement;
                Assert.IsNotNull(textBox1Elem);
                Assert.AreEqual("Hello World!", textBox1Elem.Text);
            }
        }
Example #13
0
        protected void FillInField(string fieldName, string data, string focusField)
        {
            if (data == null)
            {
                return;
            }

            var field = AppSession.FindElementByAccessibilityId(fieldName);

            field.Clear();
            if (data.Length > 0)
            {
                field.SendKeys(data);
            }
            AppSession.FindElementByAccessibilityId(focusField).Click();
        }
Example #14
0
        public void ErrorGetClosedSessionElementScreenshot()
        {
            // Launch calculator for this specific test case
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

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

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

            try
            {
                calculatorSession.Close();
                IOSElement 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;
        }
Example #15
0
        public void TestInit()
        {
            // Attempt to go back to the main page in case Alarm & Clock app is started in EditAlarm view
            try
            {
                alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
            }
            catch
            {
                session.Navigate().Back();
                alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
            }

            Assert.IsNotNull(alarmTabElement);
            alarmTabElement.Click();
        }
Example #16
0
        public void FromElementTestCase()
        {
            IOSDriver <IWebElement> driver = new IOSDriver <IWebElement>(defaultUri, capabilities);

            server.respondTo("POST", "/element", new Dictionary <string, object>  {
                
                             {
                    "ELEMENT", '5'
                } 

            });
            AppiumWebElement element = (AppiumWebElement)driver.FindElementByAccessibilityId(".elements()");

            server.clear();
            server.respondTo("POST", "/element/5/element", new Dictionary <string, object>  {
                
                           {
                    "ELEMENT", '6'
                } 

            });
            element.FindElementByAccessibilityId(".elements()");
            server.clear();
            List <object> results = new List <object>();

            results.Add(new Dictionary <string, object> {
                { "ELEMENT", "4" }
            });
            server.respondTo("POST", "/element/5/elements", results);
            element.FindElementsByAccessibilityId(".elements()");
        }
Example #17
0
        protected static IOSDriver <IOSElement> AppSession; // Temporary placeholder until Windows namespace exists

        public BaseUITest()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", "cf59c34d-6a44-4b82-9029-ad2fc3cc2611_xnnwpqakf2yqj!App");
            AppSession = new IOSDriver <IOSElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
            Assert.NotNull(AppSession);
            AppSession.FindElementByAccessibilityId("deleteAllContactsBtn").Click();
        }
        public static void Setup(TestContext context)
        {
            //Launch the app
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", "57b3a460-8843-4d84-822a-9f316274c2bf_tz6ph9wdjhqw8!App");
            AppSession = new IOSDriver <IOSElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(AppSession);
            AppSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));

            //locate elements
            ButtonPlusElement = AppSession.FindElementByAccessibilityId("btn_plus") as IOSElement;
            Assert.IsNotNull(ButtonPlusElement);
            ButtonPlusElement.Click();
            ButtonPlusElement.Click();
            RestultTextElement = AppSession.FindElementByAccessibilityId("result") as IOSElement;
            Assert.IsNotNull(RestultTextElement);
        }
Example #19
0
        public void GetWindowHandlesModernApp()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId);

            IOSDriver <IOSElement> multiWindowsSession = new IOSDriver <IOSElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

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

            var windowHandlesBefore = multiWindowsSession.WindowHandles;

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

            // 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 (OpenQA.Selenium.NoSuchElementException)
            {
                multiWindowsSession.FindElementByAccessibilityId("ActionsMenuButton").Click();
                multiWindowsSession.FindElementByAccessibilityId("ActionsMenuNewWindow").Click();
            }

            System.Threading.Thread.Sleep(1000); // Sleep for 1 second
            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();
        }
Example #20
0
        public void ConnectionTest()
        {
            driver.FindElementByAccessibilityId("Photos").Click();

            //TouchAction action = new TouchAction(driver);
            //action.Tap(140, 457);
            //action.Perform();

            driver.Quit();
        }
Example #21
0
        public static async Task WaitForNoElementByAccessibilityId(this IOSDriver <IOSElement> driver, String selector, TimeSpan?timeout = null)
        {
            timeout ??= TimeSpan.FromSeconds(60);

            await Retry.For(async() =>
            {
                var element = driver.FindElementByAccessibilityId(selector);
                element.ShouldNotBeNull($"Element {selector} is not null but should be");
            });
        }
Example #22
0
        public static void TearDown()
        {
            // Close Notepad
            NotepadSession.Quit();
            NotepadSession = null;

            // Launch Windows Explorer to delete the saved text file above
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", ExplorerAppId);
            IOSDriver <IOSElement> WindowsExplorerSession = new IOSDriver <IOSElement>(new Uri(AppDriverUrl), appCapabilities);

            Assert.IsNotNull(WindowsExplorerSession);

            // Create Desktop session to control context menu and access dialogs
            DesiredCapabilities desktopCapabilities = new DesiredCapabilities();

            desktopCapabilities.SetCapability("app", "Root");
            IOSDriver <IOSElement> DesktopSession = new IOSDriver <IOSElement>(new Uri(AppDriverUrl), desktopCapabilities);

            Assert.IsNotNull(DesktopSession);

            // Navigate Windows Explorer to the target save location folder
            var addressBandRoot = WindowsExplorerSession.FindElementByClassName("Address Band Root");
            var addressToolbar  = addressBandRoot.FindElementByAccessibilityId("1001"); // Address Band Toolbar

            WindowsExplorerSession.Mouse.Click(addressToolbar.Coordinates);
            addressBandRoot.FindElementByAccessibilityId("41477").SendKeys(TargetSaveLocation);
            var gotoButton = addressBandRoot.FindElementByName("Go to \"" + TargetSaveLocation + "\"");

            WindowsExplorerSession.Mouse.Click(gotoButton.Coordinates);

            // Locate the saved test file
            WindowsExplorerSession.FindElementByAccessibilityId("SearchEditBox").SendKeys(TestFileName);

            // Delete the located saved test file
            Thread.Sleep(1000); // Wait for 1 second
            var shellFolderView = WindowsExplorerSession.FindElementByName("Shell Folder View");
            var targetFileItem  = shellFolderView.FindElementByName("NotepadTestOutputFile.txt");

            Assert.IsNotNull(targetFileItem);
            WindowsExplorerSession.Mouse.Click(targetFileItem.Coordinates);
            WindowsExplorerSession.Mouse.ContextClick(targetFileItem.Coordinates);
            Thread.Sleep(1000); // Wait for 1 second for the context menu to appear
            var contextMenu = DesktopSession.FindElementByName("Context");

            Assert.IsNotNull(contextMenu);
            contextMenu.FindElementByAccessibilityId("30994").Click(); // Select Delete from the context menu item

            WindowsExplorerSession.Quit();
            WindowsExplorerSession = null;
            DesktopSession.Quit();
            DesktopSession = null;
        }
Example #23
0
        public void NavigateBackModernApp()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.AlarmClockAppId);
            session = new IOSDriver <IOSElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(session);

            // Navigate to New Alarm view
            session.FindElementByAccessibilityId("AlarmPivotItem").Click();
            session.FindElementByAccessibilityId("AddAlarmButton").Click();
            Assert.IsNotNull(session.FindElementByAccessibilityId("EditAlarmHeader"));

            // Navigate back to the original view
            session.Navigate().Back();
            Assert.IsNotNull(session.FindElementByAccessibilityId("AlarmPivotItem"));

            session.Quit();
            session = null;
        }
Example #24
0
        public static async Task <IWebElement> WaitForElementByAccessibilityId(this IOSDriver <IOSElement> driver, String selector, TimeSpan?timeout = null)
        {
            timeout ??= TimeSpan.FromSeconds(60);
            IWebElement element = null;
            await Retry.For(async() =>
            {
                element = driver.FindElementByAccessibilityId(selector);
                element.ShouldNotBeNull($"Element {selector} is null but should not be");
            });

            return(element);
        }
Example #25
0
        public void DoubleTap()
        {
            // Launch calculator for this specific test case
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.CalculatorAppId);
            calculatorSession = new IOSDriver <IOSElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(calculatorSession);
            Assert.IsNotNull(calculatorSession.SessionId);

            // Save application window original size and position
            var originalSize     = calculatorSession.Manage().Window.Size;
            var originalPosition = calculatorSession.Manage().Window.Position;

            // Get maximized window size
            calculatorSession.Manage().Window.Maximize();
            var maximizedSize = calculatorSession.Manage().Window.Size;

            Assert.IsNotNull(maximizedSize);

            // Shrink the window size by 100 pixels each side from maximized size to ensure size changes when maximized
            int offset = 100;

            calculatorSession.Manage().Window.Size = new System.Drawing.Size(maximizedSize.Width - offset, maximizedSize.Height - offset);
            calculatorSession.Manage().Window.Position = new System.Drawing.Point(offset, offset);
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second
            var currentWindowSize = calculatorSession.Manage().Window.Size;

            Assert.IsNotNull(currentWindowSize);
            Assert.AreNotEqual(maximizedSize.Width, currentWindowSize.Width);
            Assert.AreNotEqual(maximizedSize.Height, currentWindowSize.Height);

            // Perform double tap touch on the title bar to maximize calculator window
            calculatorTouchScreen = new RemoteTouchScreen(calculatorSession);
            Assert.IsNotNull(calculatorTouchScreen);
            calculatorTouchScreen.DoubleTap(calculatorSession.FindElementByAccessibilityId("AppNameTitle").Coordinates);
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second
            currentWindowSize = calculatorSession.Manage().Window.Size;
            Assert.IsNotNull(currentWindowSize);
            Assert.AreEqual(maximizedSize.Width, currentWindowSize.Width);
            Assert.AreEqual(maximizedSize.Height, currentWindowSize.Height);

            // Restore application window original size and position
            calculatorSession.Manage().Window.Size = originalSize;
            calculatorSession.Manage().Window.Position = originalPosition;
            System.Threading.Thread.Sleep(1000); // Sleep for 1 second

            // Close the calculator application and delete the session after cleaning up
            calculatorTouchScreen = null;
            calculatorSession.Quit();
            calculatorSession = null;
        }
        public void FindElementByAccessibilityIdTestCase()
        {
            IOSDriver driver = new IOSDriver(defaultUri, capabilities);

            server.respondTo("POST", "/element", new Dictionary <string, object>  {
                { "ELEMENT", '5' }
            });
            IWebElement element = driver.FindElementByAccessibilityId(".elements()");

            server.clear();
            server.respondTo("GET", "/element/5/attribute/id", "1234");
            element.GetAttribute("id");
        }
Example #27
0
        public void CanActivateAppTest()
        {
            //Activate an app to foreground
            Assert.DoesNotThrow(() => _driver.ActivateApp(IosTestAppBundleId));

            //Verify the expected app was activated
            Assert.DoesNotThrow(() => _driver.FindElementByAccessibilityId(IosTestAppElement));
        }
        public static void Main(string[] args)
        {
            DesiredCapabilities caps = new DesiredCapabilities();

            caps.SetCapability("browserstack.user", userName);
            caps.SetCapability("browserstack.key", accessKey);

            caps.SetCapability("realMobile", true);
            caps.SetCapability("device", "iPhone 7");
            caps.SetCapability("app", "bs://<hashed app-id>");
            IOSDriver <IOSElement> driver = new IOSDriver <IOSElement> (new Uri("http://hub.browserstack.com/wd/hub"), caps);

            IOSElement loginButton = (IOSElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(
                ExpectedConditions.ElementToBeClickable(MobileBy.AccessibilityId("Log In"))
                );

            loginButton.Click();
            IOSElement emailTextField = (IOSElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(
                ExpectedConditions.ElementToBeClickable(MobileBy.AccessibilityId("Email address"))
                );

            // element.SendKeys() method is not supported in Appium 1.6.3
            // Workaround for SendKeys() method:
            emailTextField.Click();
            String email = "*****@*****.**";

            for (int i = 0; i < email.Length; i++)
            {
                driver.FindElementByXPath("//XCUIElementTypeKey[@name='" + email[i] + "']").Click();
            }

            driver.FindElementByAccessibilityId("Next").Click();
            System.Threading.Thread.Sleep(5000);


            IReadOnlyList <IOSElement> textElements = driver.FindElementsByXPath("//XCUIElementTypeStaticText");

            String matchedString = "";

            foreach (IOSElement textElement in textElements)
            {
                String textContent = textElement.Text;
                if (textContent.Contains("not registered"))
                {
                    matchedString = textContent;
                }
            }

            Console.WriteLine(matchedString);
            driver.Quit();
        }
Example #29
0
        public void ComputeSumTestCase()
        {
            // fill form with random data
            int sumIn = Populate();

            // compute and check the sum
            driver.FindElementByAccessibilityId("ComputeSumButton").Click();
            Thread.Sleep(1000);

            IWebElement sumEl  = driver.FindElementByIosUIAutomation(".elements().withName(\"Answer\")");
            int         sumOut = Convert.ToInt32(sumEl.Text);

            Assert.AreEqual(sumIn, sumOut);
        }
Example #30
0
 static public void ReturnToMainPage()
 {
     // Try to return to main page in case application is started in nested view
     try
     {
         AppiumWebElement backButton = null;
         do
         {
             backButton = XAMLCatalogSession.FindElementByAccessibilityId("Back");
             backButton.Click();
         }while (backButton != null);
     }
     catch {}
 }