public void TestMethod1() { if (calSession == null) { //DriverOptions driverOptions = new DriverOptions(); DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", calApp); appCapabilities.SetCapability("deviceName", "WindowsPC"); //Create a session to intract with Calculator windows application //calSession = new WindowsDriver<WindowsElement>(new Uri(appiumDriverURI), appCapabilities); calSession = new WindowsDriver <WindowsElement>(new Uri(appiumDriverURI), appCapabilities); //Automate Button and Get answer from Calculator //find by Name calSession.FindElement(By.Name("Nine")).Click(); calSession.FindElement(By.Name("One")).Click(); calSession.FindElement(By.Name("Two")).Click(); calSession.FindElement(By.Name("Three")).Click(); calSession.FindElement(By.Name("Multiply by")).Click(); //find by automation id calSession.FindElementByAccessibilityId("num9Button").Click(); calSession.FindElementByAccessibilityId("equalButton").Click(); //getting value from textbox string ExpectedValue = calSession.FindElementByAccessibilityId("CalculatorResults").Text; string ExpectedValue1 = ExpectedValue.Replace("Display is ", "").Replace(",", ""); //Testcases Assert.AreEqual(82107, Convert.ToInt64(ExpectedValue1)); } }
// Help method to handle unique automationId locator public WindowsElement GetIdentifier() { if (GetByType().Equals("Id")) { return(WindowsDriver.FindElementByAccessibilityId(GetByLocator())); } return(WindowsDriver.FindElement(Identifier)); }
private void OpenFile(string filePath) { WindowsElement mediaMenuItem = _driver.FindElement(By.Name("Media Alt+M")); mediaMenuItem.Click(); // we are going to click on the Open File button by moving the mouse relative to the Media menu item new Actions(_driver).MoveToElement(mediaMenuItem, 20, 30).Click().Perform(); // at this point a popup window will open so we set focus to that _driver.SwitchTo().Window(_driver.CurrentWindowHandle); // enter file name in the file name field _driver.FindElementByAccessibilityId("1148").SendKeys(filePath); // click Open button _driver.FindElementByAccessibilityId("1").Click(); }
public Boolean isElementExists(WindowsDriver <WindowsElement> driver, By by) { try { WindowsElement elem = driver.FindElement(by); return(true); } catch { return(false); } }
public void TestFindElement() { var appId = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"; var platformName = "Windows"; var deviceName = "WindowsPC"; var cap = new AppiumOptions(); cap.AddAdditionalCapability(MobileCapabilityType.App, appId); cap.AddAdditionalCapability(MobileCapabilityType.PlatformName, platformName); cap.AddAdditionalCapability(MobileCapabilityType.DeviceName, deviceName); var appiumLocalServer = new AppiumServiceBuilder().UsingAnyFreePort().Build(); appiumLocalServer.Start(); var driver = new WindowsDriver <WindowsElement>(appiumLocalServer, cap); var btn7 = MobileBy.AccessibilityId("num7Button"); var btn1 = MobileBy.AccessibilityId("num1Button"); var btnEquals = MobileBy.AccessibilityId("equalButton"); var btnPlus = MobileBy.AccessibilityId("plusButton"); driver.FindElement(btn7).Click(); driver.FindElement(btn7).Click(); driver.FindElement(btnPlus).Click(); driver.FindElement(btn1).Click(); driver.FindElement(btn1).Click(); driver.FindElement(btnEquals).Click(); driver.Close(); driver.Dispose(); }
public void TestCustomFindElementExtension() { var cap = new AppiumOptions(); cap.AddAdditionalCapability(MobileCapabilityType.App, "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"); cap.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Windows"); cap.AddAdditionalCapability(MobileCapabilityType.DeviceName, "WindowsPC"); var appiumLocalServer = new AppiumServiceBuilder().UsingAnyFreePort().Build(); appiumLocalServer.Start(); var driver = new WindowsDriver <WindowsElement>(appiumLocalServer, cap); // This should fail! "abcxyz" does not exist. driver.FindElement(MobileBy.AccessibilityId("abcxyz"), TimeSpan.FromSeconds(3), TimeSpan.FromMilliseconds(500)); driver.Close(); driver.Dispose(); }
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 AddNewItemWithNewCategory() { var capabilities = new AppiumOptions(); capabilities.AddAdditionalCapability(MobileCapabilityType.App, "8b831c56-bc54-4a8b-af94-a448f80118e7_sezxftbtgh66j!App"); capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Windows"); capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "WindowsPC"); var _appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort().Build(); _appiumLocalService.Start(); var driver = new WindowsDriver <WindowsElement>(_appiumLocalService, capabilities); // Create new Category item first var categoryButton = driver.FindElement(MobileBy.AccessibilityId("AddCategory")); categoryButton.Click(); // fill out the form for a new category var categoryName = driver.FindElement(MobileBy.AccessibilityId("categoryName")); categoryName.Clear(); categoryName.SendKeys("New category from automation"); //save category var saveCategory = driver.FindElement(MobileBy.AccessibilityId("Save")); saveCategory.Click(); var el1 = driver.FindElementByAccessibilityId("Add"); el1.Click(); var elItemText = driver.FindElementByAccessibilityId("ItemText"); elItemText.Clear(); elItemText.SendKeys("This is a new Item"); var elItemDetail = driver.FindElementByAccessibilityId("ItemDescription"); elItemDetail.Clear(); elItemDetail.SendKeys("These are the details"); var elItemCategory = driver.FindElement(MobileBy.AccessibilityId("ItemCategory")); elItemCategory.Click(); var categoryListItem = elItemCategory.FindElement(By.Name("New category from automation")); categoryListItem.Click(); var elSave = driver.FindElementByAccessibilityId("Save"); elSave.Click(); elSave.ClearCache(); //wait for progress bar to disapear var wait = new DefaultWait <WindowsDriver <WindowsElement> >(driver) { Timeout = TimeSpan.FromSeconds(60), PollingInterval = TimeSpan.FromMilliseconds(500) }; wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); wait.Until(d => d.FindElementByName("Second item")); var listview = driver.FindElementByAccessibilityId("ItemsListView"); //now use wait to scroll untill we find item wait = new DefaultWait <WindowsDriver <WindowsElement> >(driver) { Timeout = TimeSpan.FromSeconds(60), PollingInterval = TimeSpan.FromMilliseconds(500) }; wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); var elementfound = wait.Until(d => { var input = new PointerInputDevice(PointerKind.Touch); ActionSequence FlickUp = new ActionSequence(input); FlickUp.AddAction(input.CreatePointerMove(listview, 0, 0, TimeSpan.Zero)); FlickUp.AddAction(input.CreatePointerDown(MouseButton.Left)); FlickUp.AddAction(input.CreatePointerMove(listview, 0, -300, TimeSpan.FromMilliseconds(200))); FlickUp.AddAction(input.CreatePointerUp(MouseButton.Left)); driver.PerformActions(new List <ActionSequence>() { FlickUp }); return(d.FindElementByName("This is a new Item")); }); Assert.IsTrue(elementfound != null); driver.CloseApp(); }
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(); }
public void TestMethod1() { if (session == null) { DateTime date = DateTime.Now; string startDate = string.Format("{0:D}", date); string endDate = string.Format("{0:D}", date.AddDays(1)); AppiumOptions opt = new AppiumOptions(); opt.AddAdditionalCapability("app", Lodge); opt.AddAdditionalCapability("deviceName", "WindowsPC"); session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), opt); Assert.IsNotNull(session); Assert.IsNotNull(session.SessionId); session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60); session.FindElementByAccessibilityId("userIDTb").SendKeys("ashish"); session.FindElementByAccessibilityId("passwordTb").SendKeys("password"); session.FindElement(By.XPath("//Window/Custom[1]/Button[3]")).Click(); session.FindElement(By.XPath("//Window/Custom[1]/Button[3]/ComboBox[1]")).Clear(); session.FindElement(By.XPath("//Window/Custom[1]/Button[3]/ComboBox[1]")).SendKeys("holms-qa.centricconsulting.com:8080"); session.FindElementByAccessibilityId("loginBtn").Click(); //Verify that after login PMC QA Tenancy Text is visible string ExpectedValue = session.FindElementByAccessibilityId("tenancyName").Text.ToString(); Assert.AreEqual("PMC QA Tenancy", ExpectedValue); //New Reservation session.FindElementByAccessibilityId("TabReservations").Click(); //TabReservations//NewReservationButtom session.FindElementByAccessibilityId("NewReservationButtom").Click(); //Input Dates session.FindElementByAccessibilityId("PART_TextBoxEntryPort").Clear(); session.FindElementByAccessibilityId("PART_TextBoxEntryPort").SendKeys(startDate); session.FindElementByAccessibilityId("roomTypeCb").Click(); session.FindElement(By.Name("DBL DBL Deluxe")).Click(); System.Threading.Thread.Sleep(3); //Lodging total text assertion string lodgeTextAssertion = session.FindElement(By.Name("LODGING SUBTOTAL")).Text.ToString(); Assert.AreEqual("LODGING SUBTOTAL", lodgeTextAssertion); System.Threading.Thread.Sleep(3); session.FindElement(By.XPath("//Window/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Edit[5]/Text[1]")).Click(); session.FindElement(By.XPath("//Window/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Edit[5]")).SendKeys("seh"); session.FindElement(By.XPath("//Window/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Pane[1]/Button[3]")).Click(); session.FindElement(By.XPath("//Window/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Button[12]")).Click(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); //Assign Room session.FindElementByAccessibilityId("Button_ShowAssignableRooms").Click(); //Room Assigned System.Threading.Thread.Sleep(3); session.FindElement(By.XPath("//Window/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Pane[1]/Pane[3]")).Click(); //verify that room assigned string assignedRoom = session.FindElement(By.XPath("Window/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Pane[1]/Pane[2]/Button[1]/Text[4]")).Text.ToString(); Assert.AreNotEqual("Unassigned", assignedRoom); //click to checkin session.FindElement(By.XPath("//Window/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Button[2]")).Click(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2)); //input govt ID session.FindElement(By.XPath("//Window/Window[1]/Edit[1]")).SendKeys("1234"); //input vehicle plate session.FindElement(By.XPath("//Window/Window[1]/Edit[2]")).SendKeys("1323"); //click on allow checkin without authorization session.FindElement(By.XPath("//Window/Window[1]/CheckBox[1]")).Click(); //click checkin session.FindElement(By.XPath("//Window/Window[1]/Button[6]")).Click(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); string checkedIn = session.FindElement(By.XPath("Window/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Tab[1]/TabItem[2]/Custom[1]/Text[2]")).Text.ToString(); Assert.AreEqual("CHECKED IN", checkedIn); } }
private WindowsElement FindElement(By selectorType) { // WaitForElementOnPage(selectorType); return(AppDriver.FindElement(selectorType)); }
public void ZapiszIZamknij() { driver.FindElement(By.Name("Zapisz i zamknij")).Click(); }
/// <summary> /// Finds an element within the <paramref name="driver"/> with the given <paramref name="automationId"/>. /// </summary> /// <param name="driver">The <see cref="WindowsDriver{TElement}"/> to search.</param> /// <param name="automationId">The automation ID associated with the element to locate.</param> /// <returns>The located <typeparamref name="TElement"/>.</returns> public static TElement FindElementByAutomationId <TElement>(this WindowsDriver <TElement> driver, string automationId) where TElement : IWebElement { return(driver.FindElement(ByExtensions.AutomationId(automationId))); }
public void ClickRefreshButton() { winAppDriver.FindElement(refreshButton).Click(); customWait.Until(ExpectedConditions.ElementIsVisible(refreshStatus)); }