Ejemplo n.º 1
0
        public void EditUserTest()
        {
            string username = "******"; string password = "******";
            WindowsDriver <WindowsElement> session = Initialize();

            session = WorkflowLogin(session, username, password);
            Assert.AreEqual(session.WindowHandles.Count, 1);

            // Main Page
            session.SwitchTo().Window(session.WindowHandles.Last());
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);

            WindowsElement eUser = session.FindElementByAccessibilityId("btnUser");

            eUser.Click();

            session.SwitchTo().Window(session.WindowHandles[0]);
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);

            WindowsElement   eRow      = session.FindElementsByClassName("DataGridRow").ElementAt(9);
            AppiumWebElement eCheckbox = eRow.FindElementByClassName("CheckBox");

            eCheckbox.Click();

            session.SwitchTo().Window(session.WindowHandles[0]);
            WindowsElement eYes = session.FindElementByName("Yes");

            eYes.Click();
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);
        }
Ejemplo n.º 2
0
        public void SearchAdvanceMovieTest()
        {
            string username = "******"; string password = "******";
            WindowsDriver <WindowsElement> session = Initialize();

            session = WorkflowLogin(session, username, password);
            Assert.AreEqual(session.WindowHandles.Count, 1);

            // Main Page
            session.SwitchTo().Window(session.WindowHandles.Last());
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);

            WindowsElement eSearch = session.FindElementByAccessibilityId("btnSearchAdvance");

            eSearch.Click();

            session.SwitchTo().Window(session.WindowHandles[0]);
            WindowsElement eYear = session.FindElementByAccessibilityId("txtYear");

            eYear.SendKeys("2021");

            WindowsElement eSearchSubmit = session.FindElementByAccessibilityId("btnSearch");

            eSearchSubmit.Click();
            session.SwitchTo().Window(session.WindowHandles[0]);

            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);
        }
Ejemplo n.º 3
0
        //截取一張相片
        public bool takeScreenShotOnce()
        {
            //("ScrollViewer")[1]代表Skype右邊的方框欄位;SaveAsFile將截圖放到某一個路徑
            session.FindElementsByClassName("ScrollViewer")[1].GetScreenshot().SaveAsFile("ScreenshotAlarmPivotItem.png", ScreenshotImageFormat.Png);

            return(true);
        }
Ejemplo n.º 4
0
        public void EditMovieTest()
        {
            string username = "******"; string password = "******";
            WindowsDriver <WindowsElement> session = Initialize();

            session = WorkflowLogin(session, username, password);
            Assert.AreEqual(session.WindowHandles.Count, 1);

            // Main Page
            session.SwitchTo().Window(session.WindowHandles.Last());
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);

            WindowsElement   eEditRow              = session.FindElementsByClassName("DataGridRow").ElementAt(0);
            AppiumWebElement eEditButton           = eEditRow.FindElementByName("Edit");

            eEditButton.Click();

            session.SwitchTo().Window(session.WindowHandles[0]);
            WindowsElement eEditSubmit = session.FindElementByAccessibilityId("btnSubmit");

            eEditSubmit.Click();

            WindowsElement eSubmitMessage = session.FindElementByName("Movie Submit Success!");

            Assert.AreEqual(eSubmitMessage.Text, "Movie Submit Success!");
        }
Ejemplo n.º 5
0
 public void ClickOnOptionMenu()
 {
     _driver.FindElementByName("ReSharper").Click();
     // Open ReSharper Option Dialog
     // for unknown reason FindElementByXPath($"//MenuItem[starts-with(@Text, \"Options…\")]") not able to find "Options…" menu item
     _driver.FindElementsByClassName("MenuItem").First(p => p.Text == "Options…").Click();
 }
Ejemplo n.º 6
0
        ReadOnlyCollection <WindowsElement> QueryWindows(WinQuery query, bool findFirst = false)
        {
            var resultByAccessibilityId = _session.FindElementsByAccessibilityId(query.Marked);
            ReadOnlyCollection <WindowsElement> resultByName = null;

            if (!findFirst || resultByAccessibilityId.Count == 0)
            {
                resultByName = _session.FindElementsByName(query.Marked);
            }

            IEnumerable <WindowsElement> result = resultByAccessibilityId;

            if (resultByName != null)
            {
                result = result.Concat(resultByName);
            }

            // TODO hartez 2017/10/30 09:47:44 Should this be == "*" || == "TextBox"?
            // what about other controls where we might be looking by content? TextBlock?
            if (query.ControlType == "*")
            {
                IEnumerable <WindowsElement> textBoxesByContent =
                    _session.FindElementsByClassName("TextBox").Where(e => e.Text == query.Marked);
                result = result.Concat(textBoxesByContent);
            }

            return(FilterControlType(result, query.ControlType));
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 8
0
        public static void Setup(TestContext context)
        {
            AppiumOptions opt = new AppiumOptions();

            opt.AddAdditionalCapability("platformName", "Windows");
            opt.AddAdditionalCapability("app", "Root");
            opt.AddAdditionalCapability("deviceName", "WindowsPC");
            session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), opt);

            WindowsElement applicationWindow = null;
            var            openWindows       = session.FindElementsByClassName("Window");

            foreach (var window in openWindows)
            {
                if (window.GetAttribute("Name").Equals("XRY"))
                {
                    applicationWindow = window;
                    break;
                }
            }

            // Attaching to existing Application Window
            var topLevelWindowHandle = applicationWindow.GetAttribute("NativeWindowHandle");

            topLevelWindowHandle = int.Parse(topLevelWindowHandle).ToString("X");

            AppiumOptions opts = new AppiumOptions();

            opts.AddAdditionalCapability("deviceName", "WindowsPC");
            opts.AddAdditionalCapability("appTopLevelWindow", topLevelWindowHandle);
            session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), opts);
            session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
        }
        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;
            }
        }
Ejemplo n.º 10
0
 private void FindContactControlId()
 {
     InputNumber(_options.TestPhoneNumber);
     Thread.Sleep(6000);
     _contactControlId = _session.FindElementsByClassName("TextBlock")
                         .FirstOrDefault(e => e.Text.Contains(_options.TestContactName)).Id;
     ClearNumber();
 }
Ejemplo n.º 11
0
        public void DeleteMovieTest()
        {
            string username = "******"; string password = "******";
            WindowsDriver <WindowsElement> session = Initialize();

            session = WorkflowLogin(session, username, password);
            Assert.AreEqual(session.WindowHandles.Count, 1);

            // Main Page
            session.SwitchTo().Window(session.WindowHandles.Last());
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);

            WindowsElement   eDeleteRow            = session.FindElementsByClassName("DataGridRow").ElementAt(0);
            AppiumWebElement eDeleteButton         = eDeleteRow.FindElementByName("Delete");

            eDeleteButton.Click();

            session.SwitchTo().Window(session.WindowHandles[0]);
            WindowsElement eYes = session.FindElementByName("Yes");

            eYes.Click();
        }
Ejemplo n.º 12
0
        public void AddMovieTest()
        {
            string username = "******"; string password = "******";
            WindowsDriver <WindowsElement> session = Initialize();

            session = WorkflowLogin(session, username, password);
            Assert.AreEqual(session.WindowHandles.Count, 1);

            // Main Page
            session.SwitchTo().Window(session.WindowHandles.Last());
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);

            WindowsElement eAddUser = session.FindElementByAccessibilityId("btnAddMovie");

            eAddUser.Click();
            session.SwitchTo().Window(session.WindowHandles[0]);

            WindowsElement eTitle = session.FindElementByAccessibilityId("txtTitle");

            eTitle.SendKeys($"title{DateTime.Now.ToString()}");

            WindowsElement eDirector = session.FindElementByAccessibilityId("txtDirector");

            eDirector.SendKeys("Director");

            WindowsElement eGenre = session.FindElementByAccessibilityId("txtGenre");

            eGenre.SendKeys("Genre");

            WindowsElement eCast = session.FindElementByAccessibilityId("txtCast");

            eCast.SendKeys("Cast");

            WindowsElement eYear = session.FindElementByAccessibilityId("txtYear");

            eYear.SendKeys("2021");

            WindowsElement eAward = session.FindElementByAccessibilityId("txtAwards");

            eAward.SendKeys("Award");

            WindowsElement ePlay = session.FindElementByAccessibilityId("rBtnNowPlaying");

            ePlay.Click();

            WindowsElement eSubmit = session.FindElementByAccessibilityId("btnSubmit");

            eSubmit.Click();
        }
Ejemplo n.º 13
0
        ReadOnlyCollection <WindowsElement> QueryWindows(WinQuery query)
        {
            var resultByName            = _session.FindElementsByName(query.Marked);
            var resultByAccessibilityId = _session.FindElementsByAccessibilityId(query.Marked);

            var result = resultByName
                         .Concat(resultByAccessibilityId);

            if (query.ControlType == "*")
            {
                var textBoxesByContent = _session.FindElementsByClassName("TextBox").Where(e => e.Text == query.Marked);
                result = result.Concat(textBoxesByContent);
            }

            return(FilterControlType(result, query.ControlType));
        }
Ejemplo n.º 14
0
        public void ViewMovieTest()
        {
            string username = "******"; string password = "******";
            WindowsDriver <WindowsElement> session = Initialize();

            session = WorkflowLogin(session, username, password);
            Assert.AreEqual(session.WindowHandles.Count, 1);

            // Main Page
            session.SwitchTo().Window(session.WindowHandles.Last());
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);

            WindowsElement eClose = session.FindElementByName("Close");

            eClose.Click();
        }
Ejemplo n.º 15
0
        protected AppiumWebElement SearchWindowsElement(WindowsDriver <AppiumWindowsElement> desktopSession, AppiumWebElement parentElement, WindowsElementSearchSpec windowsElementSearchSpec, IList <string> log)
        {
            log.Clear();
            var elements = new List <AppiumWebElement>();

            if (desktopSession != null && !string.IsNullOrWhiteSpace(windowsElementSearchSpec.Name))
            {
                elements = desktopSession.FindElementsByName(windowsElementSearchSpec.Name).Cast <AppiumWebElement>().ToList();
            }
            else if (desktopSession != null && windowsElementSearchSpec.ClassNames.Any())
            {
                windowsElementSearchSpec.ClassNames.ForEach(n => elements.AddRange(desktopSession.FindElementsByClassName(n)));
            }
            else if (!string.IsNullOrWhiteSpace(windowsElementSearchSpec.Name))
            {
                elements = parentElement.FindElementsByName(windowsElementSearchSpec.Name).ToList();
            }
            else if (windowsElementSearchSpec.ClassNames.Any())
            {
                windowsElementSearchSpec.ClassNames.ForEach(n => elements.AddRange(parentElement.FindElementsByClassName(n)));
            }
            else
            {
                throw new ArgumentException($"Invalid {nameof(WindowsElementSearchSpec)}, name or class name is required");
            }
            var reverseSearchSpecs = elements.Select(e => new WindowsElementSearchSpec(e));

            log.Add(elements.Any()
                ? $"[{windowsElementSearchSpec}] applied to root element resulted in {elements.Count} elements: {string.Join(", ", reverseSearchSpecs)}"
                : $"[{windowsElementSearchSpec}] applied to root element did not yield any results");

            foreach (var element in elements)
            {
                if (!DoesElementMatchSearchSpec(element, windowsElementSearchSpec, 0, log, "", out var elementOrMatchingChildElement))
                {
                    continue;
                }

                if (elementOrMatchingChildElement == null)
                {
                    throw new Exception("Element matches search specification, but no element is returned");
                }
                return(elementOrMatchingChildElement);
            }
            return(null);
        }
Ejemplo n.º 16
0
        public void AddUserTest()
        {
            string username = "******"; string password = "******";
            WindowsDriver <WindowsElement> session = Initialize();

            session = WorkflowLogin(session, username, password);
            Assert.AreEqual(session.WindowHandles.Count, 1);

            // Main Page
            session.SwitchTo().Window(session.WindowHandles.Last());
            Assert.IsTrue(session.FindElementsByClassName("DataGridRow").Count > 0);

            WindowsElement eUser = session.FindElementByAccessibilityId("btnUser");

            eUser.Click();

            session.SwitchTo().Window(session.WindowHandles[0]);
            WindowsElement eAddUser = session.FindElementByAccessibilityId("colAddUser");

            eAddUser.Click();

            WindowsElement eNewUser = session.FindElementByAccessibilityId("txtUsername");

            eNewUser.SendKeys($"newUser{DateTime.Now.ToString()}");

            WindowsElement eEmail = session.FindElementByAccessibilityId("txtEmail");

            eEmail.SendKeys("*****@*****.**");

            WindowsElement ePassword = session.FindElementByAccessibilityId("txtPassword");

            ePassword.SendKeys("P@ssw0rd");

            WindowsElement ePassword2 = session.FindElementByAccessibilityId("txtPasswordConfirm");

            ePassword2.SendKeys("P@ssw0rd");

            WindowsElement eRole = session.FindElementByAccessibilityId("rBtnAdmin");

            eRole.Click();

            WindowsElement eAddSubmit = session.FindElementByAccessibilityId("btnAddUser");

            eAddSubmit.Click();
        }
Ejemplo n.º 17
0
        public void AlreadyRunningApp()
        {
            AppiumOptions appOptions = new AppiumOptions();

            appOptions.AddAdditionalCapability("platformName", "Windows");
            appOptions.AddAdditionalCapability("app", "Root");
            appOptions.AddAdditionalCapability("deviceName", "WindowsPC");
            WindowsDriver <WindowsElement> Session = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appOptions);

            WindowsElement applicationWindow = null;
            var            openWindows       = Session.FindElementsByClassName("Window");

            foreach (var window in openWindows)
            {
                Console.WriteLine(window.GetAttribute("Name"));
                if (window.GetAttribute("Name").StartsWith("SoapUI 5.5.0"))
                {
                    applicationWindow = window;
                    break;
                }
            }

            // Attaching to existing Application Window
            var topLevelWindowHandle = applicationWindow.GetAttribute("NativeWindowHandle");

            Console.WriteLine("Top level window handle " + topLevelWindowHandle);
            topLevelWindowHandle = int.Parse(topLevelWindowHandle).ToString("X");
            Console.WriteLine("Top level window handle after parse" + topLevelWindowHandle);

            AppiumOptions appOptions1 = new AppiumOptions();

            appOptions1.AddAdditionalCapability("deviceName", "WindowsPC");
            appOptions1.AddAdditionalCapability("appTopLevelWindow", topLevelWindowHandle);
            Session = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appOptions1);
            Console.WriteLine(Session.Title);
            Session.Close();
        }
Ejemplo n.º 18
0
 public override IEnumerable <WindowsElement> FindAllElements(WindowsDriver <WindowsElement> searchContext)
 {
     return(searchContext.FindElementsByClassName(Value));
 }