public static bool TryFindElementsByClassName(this WindowsDriver <WindowsElement> session, string className, out ReadOnlyCollection <WindowsElement> elements)
 {
     try
     {
         elements = session.FindElements(By.ClassName(className));
         return(true);
     }
     catch
     {
         elements = null;
         return(false);
     }
 }
Пример #2
0
        public void ClickMailItemContainerFromList(string emailNameContent1, string emailNameContent2)
        {
            IReadOnlyCollection <WindowsElement> list = winAppDriver.FindElements(mailItemContainer);
            int listItemsCounter = 1;

            foreach (WindowsElement element in list)
            {
                if (element.GetElementName().Contains(emailNameContent1) &&
                    element.GetElementName().Contains(emailNameContent2))
                {
                    element.Click();
                    break;
                }
                listItemsCounter++;
                if (list.Count() == listItemsCounter)
                {
                    throw new NoSuchElementException("Target email was not found in Inbox folder");
                }
            }
        }
        public static bool TryFindElementByClassNameAndText(this WindowsDriver <WindowsElement> session, string className, string text, out WindowsElement element)
        {
            try
            {
                // Can't get FindElementByWindowsUIAutomation to work with WPF app so this is a workaround
                foreach (var windowsElement in session.FindElements(By.ClassName(className)))
                {
                    var possibleElement = session.FindElement(By.Id(windowsElement.Id));

                    if (possibleElement.Text == text)
                    {
                        element = possibleElement;
                        return(true);
                    }
                    else
                    {
                        foreach (var textblock in possibleElement.FindElements(By.ClassName("TextBlock")))
                        {
                            if (textblock.GetAttribute("Name") == text)
                            {
                                element = possibleElement;
                                return(true);
                            }
                        }
                    }
                }

                element = null;
                return(false);
            }
            catch
            {
                element = null;
                return(false);
            }
        }
        public static bool TryFindElementByAutomationId(this WindowsDriver <WindowsElement> session, string className, string automationId, out WindowsElement element)
        {
            try
            {
                // Can't get FindElementByWindowsUIAutomation to work with WPF app so this is a workaround
                foreach (var windowsElement in session.FindElements(By.ClassName(className)))
                {
                    var possibleElement = session.FindElement(By.Id(windowsElement.Id));
                    if (possibleElement.GetAttribute("AutomationId") == automationId)
                    {
                        element = possibleElement;
                        return(true);
                    }
                }

                element = null;
                return(false);
            }
            catch
            {
                element = null;
                return(false);
            }
        }
        public void Test1()
        {
            //var header = _driver.FindElementByAccessibilityId(("ButtonAddNewSapSystem"));
            //var name = header.GetAttribute("Name");
            //TestContext.Out.WriteLine($"Profile: {name}");
            //Assert.AreEqual(name, "SAP-System erstellen", "Wrong profile name");

            //var sysButton = _driver.FindElement(By.XPath("//Text[@AutomationId='SID' and @Name='MT7']/.."));
            var sysButton = _driver.FindElement(By.XPath("//Text[@AutomationId='SID' and @Name='MT7']/parent::*"));
            //sysButton.Click();
            var description = sysButton.FindElement(By.XPath("//Text[@AutomationId='SystemDescription']"))
                              .GetAttribute("Name");

            var helpButton            = sysButton.FindElement(By.XPath("//Button[@AutomationId='EditSapSystemButton']"));
            var removeSapSystemButton =
                sysButton.FindElement(By.XPath("//Button[@AutomationId='RemoveSapSystemButton']"));

            //var t1 = _driver
            //    .FindElementsByAccessibilityId("SID");

            //var t2 = t1.Single(e => e.GetAttribute("Name") == "MT7");

            var text = _driver.FindElement(By.XPath("//Text[@AutomationId='SID' and @Name='MT7']"));

            //var t3 = text.FindElement(By.XPath("./.."));

            //var sysButton = _driver
            //    .FindElementsByAccessibilityId("SID")
            //    .Single(e => e.GetAttribute("Name") == "MT7")
            //    .FindElement(By.XPath("./.."));

            var systems = _driver.FindElements(By.XPath("//Text[@AutomationId='SID']"));
            var sids    = systems.Select(e => e.GetAttribute("Name")).ToList();

            var systemButtons = _driver.FindElementsByAccessibilityId(("SapSystemButton"));

            foreach (var system in systemButtons)
            {
                //var button = system.FindElement(By.XPath("//Text[@AutomationId='SID']/.."));

                //    var test = system.FindElement(By.XPath("//Text[@AutomationId='SID']")).GetAttribute("Name");
                //    TestContext.Out.WriteLine($"System: {test}");
            }


            //var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
            //wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(ElementNotVisibleException));

            //var visible = wait.Until(driver => driver.FindElement(By.Id("header")).Displayed);
            //Assert.IsTrue(visible, "Header not visible");

            //var exist = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.Id("header")));
            ////new WebDriverWait(_driver, TimeSpan.FromSeconds(5)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.Id("header")));

            //var header1 = wait.Until(c => c.FindElement(By.Id("header")));
            //Assert.AreEqual(header1.Text, "Default", "Wrong profile name");

            //var header2 = _driver.Wait().ForElement(By.Id("header")).ToExist();
            //Assert.AreEqual(header2.Text, "Default", "Wrong profile name");


            //var userInput = _driver.FindElement(By.Id("userInput"));
            //userInput.SendKeys("mobentw");
            //var user = userInput.GetAttribute("value");
            //Assert.AreEqual(user, "mobentw", "Wrong user");
            //TestContext.Out.WriteLine($"User: {user}");

            //var passwordInput = _driver.FindElement(By.Id("passwordInput"));
            //passwordInput.SendKeys("sapmobis");
            //var password = passwordInput.GetAttribute("value");
            //Assert.AreEqual(password, "sapmobis", "Wrong password");
            //TestContext.Out.WriteLine($"Password: {password}");

            //var loginApplicationInput = _driver.FindElement(By.Id("loginApplicationInput"));
            //loginApplicationInput.SendKeys("QS1");
            //var application = loginApplicationInput.GetAttribute("value");
            //Assert.AreEqual(application, "QS1", "Wrong application");
            //TestContext.Out.WriteLine($"Application: {application}");


            //var profileButton = _driver.FindElement(By.Id("header"));
            ////profileButton.Click();

            //var settingsButton = _driver.FindElement(By.Id("settingsButton"));
            //settingsButton.Click();


            //var cancelButton = _driver.FindElement(By.Id("cancelButton"));
            //_driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", cancelButton);
            //Thread.Sleep(1000);
            //cancelButton.Click();

            //Assert.Pass();
        }
Пример #6
0
        public void TestMLL()
        {
            // You can find the Application Id of your application in the generated AppX\vs.appxrecipe file under RegisteredUserModeAppID node. E.g. c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", "1c0748ac-ce4c-4925-a3d3-e8cbd8d20db6_j0c0e5hxdtz1g!App");
            appCapabilities.SetCapability("deviceName", "Windows"); // Notwendig bei Start über Appium, nicht notwendig bei WinAppDriver.exe

            // Appium: http://127.0.0.1:4723/wd/hub
            // WinAppDriver.exe: http://127.0.0.1:4723
            using (var app = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities))
            {
                app.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0.0);

                Assert.IsNotNull(app);
                Assert.IsNotNull(app.SessionId);

                var text1 = "Dies ist eine Aufgabe";
                var text2 = "Dies ist noch eine Aufgabe";
                // Use the session to control the app
                app.FindElementByName("Remove all").Click();

                var sc = app.GetScreenshot();
                sc.SaveAsFile("Screen1.png");

                app.FindElementByAccessibilityId("C_Task").Click();

                app.FindElementByAccessibilityId("C_Datum").Click();

                var Feb = app.FindElementByAccessibilityId("HeaderButton");
                Feb.Click();
                var Maerz = app.FindElementByName("März");
                Maerz.Click();
                var eins = app.FindElementByName("1");
                eins.Click();
                //app.FindElementByAccessibilityId("C_Datum").Click();

                app.FindElementByAccessibilityId("C_Task").SendKeys(text1);

                // https://github.com/Microsoft/WinAppDriver/blob/master/Tests/UWPControls/DatePicker.cs


                app.FindElementByName("Add").Click();

                app.FindElementByAccessibilityId("C_Task").SendKeys(text2);
                app.FindElementByName("Add").Click();

                var listenelemente = app.FindElements(By.XPath($"//ListItem"));
                Assert.AreEqual(2, listenelemente.Count);
                var e = listenelemente[0];
                Assert.AreEqual(e.Text, "EFC_UWP.DAL.Task");
                // app.FindElements(By.XPath($"//Button"))

                string b = app.FindElementByAccessibilityId("C_Details").Text;
                //Assert.AreEqual(System.DateTime.Now.ToShortDateString() + ": " + text1, b);
                Assert.AreEqual("01.03." + System.DateTime.Now.Year + ": " + text1, b);
                var alleAufgaben = app.FindElements(By.XPath($"//*[contains(@Name, \"Aufgabe\")]"));
                Assert.IsTrue(alleAufgaben[0].Text.Contains(text1));
                Assert.IsTrue(alleAufgaben[1].Text.Contains(text2));

                // geht so nicht, weil die Liste sich durch "Done" verändert
                //var alleAufgabenDoneButtons = app.FindElements(By.XPath($"//*[contains(@Name, \"Done\")]"));
                //foreach (var done in alleAufgabenDoneButtons.Reverse().ToList())
                //{
                // done.Click();
                //}

                ReadOnlyCollection <WindowsElement> alleAufgabenDoneButtons;
                do
                {
                    alleAufgabenDoneButtons = app.FindElements(By.XPath($"//*[contains(@Name, \"Done\")]"));
                    alleAufgabenDoneButtons[0].Click();
                } while (alleAufgabenDoneButtons.Count > 1);


                var listenelemente2 = app.FindElements(By.XPath($"//ListItem"));
                Assert.AreEqual(0, listenelemente2.Count);

                app.CloseApp();
            }
        }
Пример #7
0
        public IWebElement getElementById(WindowsDriver <WindowsElement> driver, string Xpath, int id)
        {
            var elements = driver.FindElements(By.XPath(Xpath + "/*"));

            return(elements[id]);
        }
Пример #8
0
        /// <summary>
        /// Checks if the item with the specified name is present in the Playlist
        /// </summary>
        /// <param name="itemName"></param>
        /// <returns></returns>
        private bool CheckItemExistsInPlaylist(string itemName)
        {
            var items = _driver.FindElements(By.Name(itemName));

            return(items.Count > 0);
        }