Esempio n. 1
0
        public void FindElementByName()
        {
            IOSElement element = session.FindElementByName("Alarm tab");

            Assert.IsNotNull(element);
            Assert.AreEqual(alarmTabElement, element);
        }
Esempio n. 2
0
        public void GetWindowHandlesClassicApp()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

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

            multiWindowsSession.FindElementByName("File").Click();
            multiWindowsSession.FindElementByName("Save As...").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();
        }
Esempio n. 3
0
        public void ErrorTouchStaleElement(string touchType)
        {
            Assert.IsNotNull(session.SessionId);
            var title = session.Title;

            GoToGitHub();

            // Make sure the page you went to is not the page you started on
            Assert.AreNotEqual(title, session.Title);

            // Create a request to touch Microsoft link
            JObject microsoftClickRequest = new JObject();

            microsoftClickRequest["element"] = session.FindElementByName("Microsoft").GetAttribute("elementId");

            // Navigate back to the original page
            JObject backRequestObject = new JObject();

            backRequestObject["element"] = session.FindElementByName("Back").GetAttribute("elementId");

            HttpWebResponse response2 = SendTouchPost("click", backRequestObject);

            Assert.IsNotNull(response2);

            System.Threading.Thread.Sleep(1000);

            // Make sure you are on the original page
            Assert.AreEqual(title, session.Title);

            // Try to touch the microsoft button
            HttpWebResponse staleResponse = SendTouchPost(touchType, microsoftClickRequest);
        }
Esempio n. 4
0
        public static void Setup(TestContext context)
        {
            // Launch Notepad Classic Windows Application
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", NotepadAppId);
            NotepadSession = new IOSDriver <IOSElement>(new Uri(AppDriverUrl), appCapabilities);
            Assert.IsNotNull(NotepadSession);
            // Verify that Notepad is started with untitled new file
            Assert.AreEqual("Untitled - Notepad", NotepadSession.Title);

            //Change the font to be more interesting
            NotepadSession.FindElementByName("Format").Click();
            NotepadSession.FindElementByName("Font...").Click();
            System.Threading.Thread.Sleep(1000);
            NotepadSession.FindElementByName("Cooper").Click();
            NotepadSession.FindElementByName("Black").Click();

            //Change the font size to be really big
            NotepadSession.FindElementByName("72").Click();

            //close the font dialog
            NotepadSession.FindElementByName("OK").Click();

            Thread.Sleep(1000);// Wait for 1 second until the main windows is displayed
            //Enable word wrap
            NotepadSession.FindElementByName("Format").Click();
            NotepadSession.FindElementByName("Word Wrap").Click();
        }
Esempio n. 5
0
        public void AddFilesByOne(string input1)
        {
            ApplicationSession.FindElementByName("Pick Files").Click();

            // Wait for 1 second until the dialog comes up
            System.Threading.Thread.Sleep(1000);
            // Open File Explorer
            var openFileDialog = ApplicationSession.FindElementByClassName("#32770");

            openFileDialog.FindElementByClassName("Edit").Click();
            openFileDialog.FindElementByClassName("Edit").SendKeys(input1 + OpenQA.Selenium.Keys.Enter);

            // Wait for 1 second until the dialog close
            System.Threading.Thread.Sleep(1000);
        }
Esempio n. 6
0
        public void BingLocalSearch()
        {
            var searchBox = CortanaSession.FindElementByAccessibilityId("SearchTextBox");

            Assert.IsNotNull(searchBox);
            searchBox.SendKeys("add");

            var bingPane = CortanaSession.FindElementByName("Bing");

            Assert.IsNotNull(bingPane);

            var bingResult = bingPane.FindElementByName("Add or remove devices, System settings");

            Assert.IsNotNull(bingResult);
        }
Esempio n. 7
0
        public void AddTwoNumbersTest()
        {
            IOSElement numberOne = _driver.FindElementById("IntegerA");
            var        numberTwo = _driver.FindElementById("IntegerB");
            var        compute   = _driver.FindElementByName("ComputeSumButton");
            var        answer    = _driver.FindElementByName("Answer");

            numberOne.Clear();
            numberOne.SetImmediateValue("5");
            numberTwo.Clear();
            numberTwo.SetImmediateValue("6");
            compute.Click();

            Assert.AreEqual("11", answer.GetAttribute("value"));
        }
Esempio n. 8
0
        public static void Setup(TestContext context)
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            // Id of application to test may finded through Inspect.exe
            appCapabilities.SetCapability("app", "51a830d1-e9e2-4a20-8a05-d547bfb2fc1c_z0qgta0qgdq0p!App");
            ApplicationSession = new IOSDriver <IOSElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(ApplicationSession);

            // Clear items from database before starting
            ApplicationSession.FindElementByName(" Settings").Click();
            ApplicationSession.FindElementByName("General").Click();
            System.Threading.Thread.Sleep(1000);
            ApplicationSession.FindElementByName("Delete").Click();
            // Back button
            ApplicationSession.FindElementByName("App Bar Item").Click();
            ApplicationSession.FindElementByName(" Settings").Click();
        }
Esempio n. 9
0
 public void DismissNotification()
 {
     try
     {
         AppiumWebElement newNotification = DesktopSession.FindElementByName("New notification");
         Assert.IsTrue(newNotification.FindElementByAccessibilityId("MessageText").Text.Contains(NewAlarmName));
         newNotification.FindElementByName("Dismiss").Click();
     }
     catch { }
 }
Esempio n. 10
0
        private void CreateProcess(string path, string shellToLaunch)
        {
            string WindowTitleToFind = "WindowsTerminal.UIA.Tests";

            job = WinBase.CreateJobObject(IntPtr.Zero, IntPtr.Zero);
            NativeMethods.Win32NullHelper(job, "Creating job object to hold binaries under test.");

            Log.Comment("Attempting to launch command-line application at '{0}'", path);

            string binaryToRunPath = path;
            string args            = $"new-tab --title \"{WindowTitleToFind}\" --suppressApplicationTitle \"{shellToLaunch}\"";

            string launchArgs = $"{binaryToRunPath} {args}";

            WinBase.STARTUPINFO si = new WinBase.STARTUPINFO();
            si.cb = Marshal.SizeOf(si);

            WinBase.PROCESS_INFORMATION pi = new WinBase.PROCESS_INFORMATION();

            NativeMethods.Win32BoolHelper(WinBase.CreateProcess(null,
                                                                launchArgs,
                                                                IntPtr.Zero,
                                                                IntPtr.Zero,
                                                                false,
                                                                WinBase.CP_CreationFlags.CREATE_SUSPENDED,
                                                                IntPtr.Zero,
                                                                null,
                                                                ref si,
                                                                out pi),
                                          "Attempting to create child host window process.");

            Log.Comment($"Host window PID: {pi.dwProcessId}");

            NativeMethods.Win32BoolHelper(WinBase.AssignProcessToJobObject(job, pi.hProcess), "Assigning new host window (suspended) to job object.");
            NativeMethods.Win32BoolHelper(-1 != WinBase.ResumeThread(pi.hThread), "Resume host window process now that it is attached and its launch of the child application will be caught in the job object.");

            Globals.WaitForTimeout();

            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", @"Root");
            Session = new IOSDriver <IOSElement>(new Uri(AppDriverUrl), appCapabilities);

            Verify.IsNotNull(Session);
            Actions = new Actions(Session);
            Verify.IsNotNull(Session);

            Globals.WaitForLongTimeout();

            UIRoot = Session.FindElementByName(WindowTitleToFind);

            // Set the timeout to 15 seconds after we found the initial window.
            Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
        }
Esempio n. 11
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;
        }
Esempio n. 12
0
        public void EnterText()
        {
            // Enter text into the edit field
            var editBox = NotepadSession.FindElementByClassName("Edit");

            editBox.SendKeys(TextValue);

            // Enter TimeStamp
            NotepadSession.FindElementByName("Edit").Click();
            NotepadSession.FindElementByName("Time/Date").Click();
        }
Esempio n. 13
0
        public static void TearDown()
        {
            ReturnToMainPage();
            SwitchToAlarmTab();

            // Delete all created alarms
            var alarmEntries = AlarmClockSession.FindElementsByName("Windows Application Driver Test Alarm");

            foreach (var alarmEntry in alarmEntries)
            {
                AlarmClockSession.Mouse.ContextClick(alarmEntry.Coordinates);
                AlarmClockSession.FindElementByName("Delete").Click();
            }

            AlarmClockSession.Dispose();
            AlarmClockSession = null;
        }
Esempio n. 14
0
        private int Populate()
        {
            IList <string> fields = new List <string> ();

            fields.Add("IntegerA");
            fields.Add("IntegerB");
            int sum = 0;

            for (int i = 0; i < fields.Count; i++)
            {
                IWebElement el = driver.FindElementByName(fields[i]);
                int         x  = rnd.Next(1, 10);
                el.SendKeys("" + x);
                sum += x;
            }
            return(sum);
        }
Esempio n. 15
0
        public void SendModifierWindowsKey()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

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

            Assert.IsNotNull(desktopSession);

            // Lauch action center using Window Keys + A
            session.Keyboard.PressKey(OpenQA.Selenium.Keys.Command + "a" + OpenQA.Selenium.Keys.Command);
            var actionCenterElement = desktopSession.FindElementByName("Action Center");

            Assert.IsNotNull(actionCenterElement);

            // Dismiss action center and cleanup the temporary session
            actionCenterElement.SendKeys(OpenQA.Selenium.Keys.Escape);
            editBox.SendKeys(OpenQA.Selenium.Keys.Escape);
            desktopSession.Quit();
        }
Esempio n. 16
0
        public static void TearDown()
        {
            ReturnToMainPage();
            SwitchToAlarmTab();

            // Delete all created alarms
            while (true)
            {
                try
                {
                    var alarmEntry = AlarmClockSession.FindElementByXPath(string.Format("//ListItem[starts-with(@Name, \"{0}\")]", NewAlarmName));
                    AlarmClockSession.Mouse.ContextClick(alarmEntry.Coordinates);
                    AlarmClockSession.FindElementByName("Delete").Click();
                }
                catch
                {
                    break;
                }
            }

            AlarmClockSession.Quit();
            AlarmClockSession = null;
        }
Esempio n. 17
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);

            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
            var newTitle = session.Title;

            Assert.AreNotEqual(originalTitle, newTitle);

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

            // Navigate forward to original URL
            session.FindElementByName("Microsoft Edge").Click(); // Set focus on the Microsoft Edge window
            session.Navigate().Forward();
            System.Threading.Thread.Sleep(3000);                 // Sleep for 3 seconds
            Assert.AreEqual(newTitle, session.Title);

            session.Quit();
        }
Esempio n. 18
0
        protected static RemoteWebElement GetStaleElement(IOSDriver <IOSElement> remoteSession)
        {
            RemoteWebElement staleElement = null;

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

            Assert.AreNotEqual(string.Empty, originalTitle);

            // Navigate to GitHub page
            remoteSession.FindElementByAccessibilityId("addressEditBox").SendKeys(CommonTestSettings.GitHubUrl + OpenQA.Selenium.Keys.Enter);
            System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
            Assert.AreNotEqual(originalTitle, remoteSession.Title);

            // Save a reference to Homepage web link on the GitHub page and navigate back to home
            staleElement = remoteSession.FindElementByName("Homepage");
            Assert.IsNotNull(staleElement);
            remoteSession.Navigate().Back();
            System.Threading.Thread.Sleep(2000);
            Assert.AreEqual(originalTitle, session.Title);

            return(staleElement);
        }
Esempio n. 19
0
 public void BasicScenario()
 {
     WordSession.FindElementByName("Blank document").Click();
 }
Esempio n. 20
0
        private void CreateCmdProcess(string path, string link = "")
        {
            //string AdminPrefix = "Administrator: ";
            string WindowTitleToFind = "Host.Tests.UIA window under test";

            job = WinBase.CreateJobObject(IntPtr.Zero, IntPtr.Zero);
            NativeMethods.Win32NullHelper(job, "Creating job object to hold binaries under test.");

            Log.Comment("Attempting to launch command-line application at '{0}'", path);

            string binaryToRunPath = path;

#if __INSIDE_WINDOWS
            string launchArgs = binaryToRunPath;
#else
            string openConsolePath = Path.Combine(this.context.TestDeploymentDir, "OpenConsole.exe");

            string launchArgs = $"{openConsolePath}  {binaryToRunPath}";
#endif

            WinBase.STARTUPINFO si = new WinBase.STARTUPINFO();
            si.cb = Marshal.SizeOf(si);

            // If we were given a LNK file to startup with, set the STARTUPINFO structure to pass that information in to the console host.
            if (!string.IsNullOrEmpty(link))
            {
                si.dwFlags |= WinBase.STARTF.STARTF_TITLEISLINKNAME;
                si.lpTitle  = link;
            }

            WinBase.PROCESS_INFORMATION pi = new WinBase.PROCESS_INFORMATION();

            NativeMethods.Win32BoolHelper(WinBase.CreateProcess(null,
                                                                launchArgs,
                                                                IntPtr.Zero,
                                                                IntPtr.Zero,
                                                                false,
                                                                WinBase.CP_CreationFlags.CREATE_NEW_CONSOLE | WinBase.CP_CreationFlags.CREATE_SUSPENDED,
                                                                IntPtr.Zero,
                                                                null,
                                                                ref si,
                                                                out pi),
                                          "Attempting to create child host window process.");

            Log.Comment($"Host window PID: {pi.dwProcessId}");

            NativeMethods.Win32BoolHelper(WinBase.AssignProcessToJobObject(job, pi.hProcess), "Assigning new host window (suspended) to job object.");
            NativeMethods.Win32BoolHelper(-1 != WinBase.ResumeThread(pi.hThread), "Resume host window process now that it is attached and its launch of the child application will be caught in the job object.");

            Globals.WaitForTimeout();

            WinBase.JOBOBJECT_BASIC_PROCESS_ID_LIST list = new WinBase.JOBOBJECT_BASIC_PROCESS_ID_LIST();
            list.NumberOfAssignedProcesses = 2;

            int    listptrsize = Marshal.SizeOf(list);
            IntPtr listptr     = Marshal.AllocHGlobal(listptrsize);
            Marshal.StructureToPtr(list, listptr, false);

            TimeSpan totalWait    = TimeSpan.Zero;
            TimeSpan waitLimit    = TimeSpan.FromSeconds(30);
            TimeSpan pollInterval = TimeSpan.FromMilliseconds(500);
            while (totalWait < waitLimit)
            {
                WinBase.QueryInformationJobObject(job, WinBase.JOBOBJECTINFOCLASS.JobObjectBasicProcessIdList, listptr, listptrsize, IntPtr.Zero);
                list = (WinBase.JOBOBJECT_BASIC_PROCESS_ID_LIST)Marshal.PtrToStructure(listptr, typeof(WinBase.JOBOBJECT_BASIC_PROCESS_ID_LIST));

                if (list.NumberOfAssignedProcesses > 1)
                {
                    break;
                }
                else if (list.NumberOfAssignedProcesses < 1)
                {
                    Verify.Fail("Somehow we lost the one console host process in the job already.");
                }

                Thread.Sleep(pollInterval);
                totalWait += pollInterval;
            }
            Verify.IsLessThan(totalWait, waitLimit);

            WinBase.QueryInformationJobObject(job, WinBase.JOBOBJECTINFOCLASS.JobObjectBasicProcessIdList, listptr, listptrsize, IntPtr.Zero);
            list = (WinBase.JOBOBJECT_BASIC_PROCESS_ID_LIST)Marshal.PtrToStructure(listptr, typeof(WinBase.JOBOBJECT_BASIC_PROCESS_ID_LIST));

            Verify.AreEqual(list.NumberOfAssignedProcesses, list.NumberOfProcessIdsInList);

#if __INSIDE_WINDOWS
            pid = pi.dwProcessId;
#else
            // Take whichever PID isn't the host window's PID as the child.
            pid = pi.dwProcessId == (int)list.ProcessId ? (int)list.ProcessId2 : (int)list.ProcessId;
            Log.Comment($"Child command app PID: {pid}");
#endif

            // Free any attached consoles and attach to the console we just created.
            // The driver will bind our calls to the Console APIs into the child process.
            // This will allow us to use the APIs to get/set the console state of the test window.
            NativeMethods.Win32BoolHelper(WinCon.FreeConsole(), "Free existing console bindings.");
            // need to wait a bit or we might not be able to reliably attach
            System.Threading.Thread.Sleep(Globals.Timeout);
            NativeMethods.Win32BoolHelper(WinCon.AttachConsole((uint)pid), "Bind to the new PID for console APIs.");

            // we need to wait here for a bit or else
            // setting the console window title will fail.
            System.Threading.Thread.Sleep(Globals.Timeout * 5);
            NativeMethods.Win32BoolHelper(WinCon.SetConsoleTitle(WindowTitleToFind), "Set the window title so AppDriver can find it.");

            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("app", @"Root");
            Session = new IOSDriver <IOSElement>(new Uri(AppDriverUrl), appCapabilities);

            Verify.IsNotNull(Session);
            Actions = new Actions(Session);
            Verify.IsNotNull(Session);

            Globals.WaitForTimeout();

            // If we are running as admin, the child window title will have a prefix appended as it will also run as admin.
            //if (IsRunningAsAdmin())
            //{
            //    WindowTitleToFind = $"{AdminPrefix}{WindowTitleToFind}";
            //}

            Log.Comment($"Searching for window title '{WindowTitleToFind}'");
            this.UIRoot  = Session.FindElementByName(WindowTitleToFind);
            this.hStdOut = WinCon.GetStdHandle(WinCon.CONSOLE_STD_HANDLE.STD_OUTPUT_HANDLE);
            Verify.IsNotNull(this.hStdOut, "Ensure output handle is valid.");
            this.hStdErr = WinCon.GetStdHandle(WinCon.CONSOLE_STD_HANDLE.STD_ERROR_HANDLE);
            Verify.IsNotNull(this.hStdErr, "Ensure error handle is valid.");

            // Set the timeout to 15 seconds after we found the initial window.
            Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
        }
Esempio n. 21
0
        public void AppiumTestMethod()
        {
            //Write your test here
            try
            {
                // write your code here
                // press Don't Allow button on Notifications screen if it appears
                try
                {
                    //IWebElement alert = driver.FindElementByXPath("//UIAAlert[contains(@name, \"Send You Notifications\")]");
                    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
                    driver.FindElementByName("Don't Allow").Click();
                }
                catch (NoSuchElementException n1)
                {
                    Trace.WriteLine("No notifications popup, just plow ahead!");
                }

                // press OK button on Welcome popup if it appears
                try
                {
                    IWebElement header = driver.FindElementByName("Welcome");
                    IWebElement okBtn  = driver.FindElementByName("OK");
                    okBtn.Click();
                }
                catch (NoSuchElementException n1)
                {
                    Trace.WriteLine("No welcome popup, just plow ahead!");
                }

                // Press "New Note" button (on right end of header)
                driver.FindElementByName("add os7").Click();

                // Verify that arrive at the New Task screen
                try
                {
                    IWebElement nTask = driver.FindElementByName("New Task");
                }
                catch (NoSuchElementException n)
                {
                    Trace.WriteLine("Did not reach New Task window!");
                    throw n;
                }

                // Enter a title for the new task
                IWebElement title = driver.FindElementByIosUIAutomation("UIATarget.localTarget().frontMostApp().mainWindow().textFields()[0]");
                title.SendKeys("Prepare the script for Native Application");

                // Enter text into the Details field
                IWebElement detail = driver.FindElementByIosUIAutomation(".textFields()[1]");
                detail.SendKeys("Select an application, upload, and use Object Spy");

                // Click "Done" to go to next stage
                driver.FindElementByName("Done").Click();

                // Click on the Due Date field to select the due date
                try
                {
                    driver.FindElementByXPath("//UIAStaticText[@name='Due Date']").Click();
                }
                catch (NoSuchElementException n)
                {
                    Trace.WriteLine("Not showing second stage display!");
                    throw n;
                }
                // select that task is due next week
                driver.FindElementByName("+1 Week").Click();

                // Click "Done" to complete the task definition
                driver.FindElementByName("Done").Click();

                // Verify that task is listed
                try
                {
                    IWebElement nTask = driver.FindElementByName("Prepare the script for Native Application");
                }
                catch (NoSuchElementException n)
                {
                    Trace.WriteLine("The task is not listed!");
                    throw n;
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("Failed due to an exception:" + e.Message);
            }
        }
Esempio n. 22
0
        public void EnterText(string inputtext)
        {
            // Enter text into the edit field
            var editBox = NotepadSession.FindElementByClassName("Edit");

            // Clear the edit field of any values
            editBox.SendKeys(inputtext);
            Assert.AreEqual(inputtext, editBox.Text);

            // Enter TimeStamp
            NotepadSession.FindElementByName("Edit").Click();
            NotepadSession.FindElementByName("Time/Date").Click();
            Assert.AreNotEqual(inputtext, editBox.Text);
        }
        public void AppiumTestMethod()
        {
            try
            {
                reportiumClient.testStart("Calendar assignment", new TestContextTags("assignment3", "calendarApp"));

                // write your code here

                reportiumClient.stepStart("Open the Calendar app");
                Dictionary <String, Object> pars = new Dictionary <String, Object>();
                try
                {
                    // close the calendar if open to verify that starting from fresh app
                    pars.Add("name", "Calendar");
                    driver.ExecuteScript("mobile:application:close", pars);
                }
                catch (Exception e)
                {
                    Trace.Write(e.StackTrace);
                    Trace.WriteLine(" ");
                }
                pars.Clear();
                pars.Add("name", "Calendar");
                driver.ExecuteScript("mobile:application:open", pars);
                reportiumClient.stepEnd();

                // Check for What's New Screen and dismiss
                reportiumClient.stepStart("Dismiss popup");
                pars.Clear();
                pars.Add("content", "What's New");
                pars.Add("timeout", 10);
                String result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);
                if (result.ToLower().Equals("true"))
                {
                    pars.Clear();
                    pars.Add("label", "Continue");
                    pars.Add("threshold", 80);
                    pars.Add("ignorecase", "nocase");
                    driver.ExecuteScript("mobile:button-text:click", pars);
                }
                pars.Clear();
                pars.Add("content", "Access");
                pars.Add("timeout", 10);
                result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);
                if (result.ToLower().Equals("true"))
                {
                    pars.Clear();
                    pars.Add("label", "Don't Allow");
                    pars.Add("threshold", 80);
                    pars.Add("ignorecase", "nocase");
                    driver.ExecuteScript("mobile:button-text:click", pars);
                }
                reportiumClient.stepEnd();

                // Go to add the event screen
                reportiumClient.stepStart("Open the event add screen");
                driver.Context = "NATIVE_APP";
                driver.FindElementByName("Add").Click();

                // use a checkpoint to visually check that we are on the correct screen
                pars.Clear();
                pars.Add("content", "new event");
                pars.Add("timeout", 20);
                result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);

                reportiumClient.stepEnd();

                reportiumClient.stepStart("Add location & title");
                IWebElement inField = driver.FindElementsByClassName("XCUIElementTypeTextField").ElementAt(1);
                inField.SendKeys("fun day");
                System.Threading.Thread.Sleep(2000);
                inField = driver.FindElementByName("Location");
                inField.SendKeys("London");
                driver.FindElementByName("Done").Click();

                reportiumClient.stepEnd();

                reportiumClient.stepStart("Set start time");
                driver.FindElementByName("Starts").Click();
                System.Threading.Thread.Sleep(1000);
                IWebElement hour = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1);
                String      hr   = hour.GetAttribute("value");
                hour.SendKeys("9");
                IWebElement mins = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2);
                String      min  = mins.GetAttribute("value");
                mins.SendKeys("45");
                Trace.WriteLine("old time: " + hr + ':' + min);
                hr  = hour.GetAttribute("value");
                min = mins.GetAttribute("value");
                Trace.WriteLine("new time: " + hr + ':' + min);
                reportiumClient.stepEnd();

                reportiumClient.stepStart("Set End Time");
                driver.FindElementByName("Ends").Click();
                System.Threading.Thread.Sleep(2000);
                hour = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1);
                hr   = hour.GetAttribute("value");
                hour.SendKeys("11");
                mins = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2);
                min  = mins.GetAttribute("value");
                mins.SendKeys("15");
                Trace.WriteLine("old end time: " + hr + ':' + min);
                hr  = hour.GetAttribute("value");
                min = mins.GetAttribute("value");
                Trace.WriteLine("new end time: " + hr + ':' + min);
                driver.FindElementByName("Ends").Click();
                reportiumClient.stepEnd();

                reportiumClient.stepStart("Recurring Event");
                driver.FindElementByName("Repeat").Click();
                driver.FindElementByName("Every Month").Click();
                driver.FindElementByName("End Repeat").Click();
                driver.FindElementByName("On Date").Click();
                System.Threading.Thread.Sleep(3000);
                IWebElement month    = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(0);
                String      endMonth = month.GetAttribute("value");
                month.SendKeys("December");
                IWebElement day     = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1);
                String      endDate = day.GetAttribute("value");
                day.SendKeys("5");
                IWebElement year    = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2);
                String      endYear = year.GetAttribute("value");
                year.SendKeys("2020");
                Trace.WriteLine("old end date: " + endMonth + ' ' + endDate + ", " + endYear);
                endMonth = month.GetAttribute("value");
                endDate  = day.GetAttribute("value");
                endYear  = year.GetAttribute("value");
                Trace.WriteLine("new end date: " + endMonth + ' ' + endDate + ", " + endYear);

                // go back to Event definition screen
                driver.FindElementByName("New Event").Click();
                reportiumClient.stepEnd();

                reportiumClient.stepStart("Add Travel time");
                driver.FindElementByName("Travel Time").Click();
                IWebElement travelToggle = driver.FindElementsByClassName("XCUIElementTypeSwitch").ElementAt(0);
                travelToggle.Click();
                driver.FindElementByName("2 hours").Click();
                // go back to Event definition screen
                driver.FindElementByName("New Event").Click();

                reportiumClient.stepEnd();

                reportiumClient.stepStart("Close application");
                pars.Clear();
                pars.Add("name", "Calendar");
                driver.ExecuteScript("mobile:application:close", pars);

                reportiumClient.stepEnd();
                reportiumClient.testStop(TestResultFactory.createSuccess());
            }
            catch (Exception e)
            {
                reportiumClient.testStop(TestResultFactory.createFailure(e.Message, e));
                Trace.Write(e.StackTrace);
                Trace.WriteLine(" ");
            }
        }
Esempio n. 24
0
 public override IOSElement FindElement(IOSDriver <IOSElement> searchContext)
 {
     return(searchContext.FindElementByName(Value));
 }
Esempio n. 25
0
        public static void TearDown()
        {
            List <string> filelist = new List <string>();

            filelist.Add("NotepadAdvancedTestOutputFile1.txt");
            filelist.Add("NotepadAdvancedTestOutputFile2.txt");
            filelist.Add("NotepadAdvancedTestOutputFile3.txt");
            filelist.Add("NotepadAdvancedTestOutputFile4.txt");
            filelist.Add("NotepadAdvancedTestOutputFile5.txt");


            //Change the font back to the default
            NotepadSession.FindElementByName("Format").Click();

            System.Threading.Thread.Sleep(1000);// Wait for 1 second until the dialog comes up
            NotepadSession.FindElementByName("Font...").Click();

            //Change the font size back to the default Lucida Console
            NotepadSession.FindElementByName("Lucida Console").Click();

            //Change the font format back to the default regular
            NotepadSession.FindElementByName("Regular").Click();

            //Change the font size back to the default size
            NotepadSession.FindElementByName("10").Click();

            //close the font dialog
            NotepadSession.FindElementByName("OK").Click();

            //Disable word wrap
            NotepadSession.FindElementByName("Format").Click();
            NotepadSession.FindElementByName("Word Wrap").Click();

            // Close Notepad
            NotepadSession.FindElementByName("File").Click();
            NotepadSession.FindElementByName("Exit").Click();
            System.Threading.Thread.Sleep(1000);// Wait for 1 second until the dialog comes up
            NotepadSession.FindElementByName("Don't Save").Click();

            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
            Thread.Sleep(1000);                                                         // Wait for 1 second
            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 + OpenQA.Selenium.Keys.Enter);

            // Locate the saved test files

            foreach (string file in filelist)
            {
                WindowsExplorerSession.FindElementByAccessibilityId("SearchEditBox").SendKeys(file);

                // Delete the located saved test file
                Thread.Sleep(1000); // Wait for 1 second
                var shellFolderView = WindowsExplorerSession.FindElementByName("Shell Folder View");
                var targetFileItem  = shellFolderView.FindElementByName(file);
                Assert.IsNotNull(targetFileItem);
                WindowsExplorerSession.Mouse.Click(targetFileItem.Coordinates);
                WindowsExplorerSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Delete);
                WindowsExplorerSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Escape);
            }

            WindowsExplorerSession.Quit();
            WindowsExplorerSession = null;
            DesktopSession.Quit();
            DesktopSession = null;
        }
Esempio n. 26
0
 public void BasicScenario()
 {
     WpfnotepadSession.FindElementByName("File").Click();
     WpfnotepadSession.Quit();
 }