public void SendKeysToElement_ModifierAlt() { alarmNameTextBox.SendKeys(Keys.Space); Assert.AreEqual("True", alarmNameTextBox.GetAttribute("HasKeyboardFocus")); alarmNameTextBox.SendKeys(Keys.Alt + Keys.Enter + Keys.Alt); // Alt + Enter moves the focus to the next element Assert.AreEqual("False", alarmNameTextBox.GetAttribute("HasKeyboardFocus")); }
public void Test_Main_Can_Minimize() { var controlBar = header.FindElementByAccessibilityId("uc"); controlBar.FindElementByName("_").Click(); Assert.AreEqual("Minimized", header.GetAttribute("Window.WindowVisualState")); }
/// <summary> /// Verifies the elements name or AutomationId based on the given compare. /// </summary> /// <param name="element"> /// The element to verify. /// </param> /// <param name="compare"> /// The value to verify is the name or AutomationId. /// </param> /// <returns> /// True if the element's name or AutomationId matches; otherwise, false. /// </returns> public static bool VerifyNameOrAutomationIdEquals(this WindowsElement element, string compare) { string name = element.GetAttribute("Name"); string automationId = element.GetAttribute("AutomationId"); return(string.Equals(compare, name, StringComparison.CurrentCultureIgnoreCase) || string.Equals( compare, automationId, StringComparison.CurrentCultureIgnoreCase)); }
private void SaveChanges() { string isEnabled = _saveButton.GetAttribute("IsEnabled"); Assert.AreEqual("True", isEnabled); _saveButton.Click(); isEnabled = _saveButton.GetAttribute("IsEnabled"); Assert.AreEqual("False", isEnabled); }
public void TestInitialize() { isWinKeyPressed = false; // If the start menu is open, close it. WindowsElement startMenuWindow = null; try { startMenuWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Window[@Name=\"Start\"]"); } catch (Exception) { //Start menu not found, as expected. } if (startMenuWindow != null) { string startMenuWindowHandle = (int.Parse(startMenuWindow.GetAttribute("NativeWindowHandle"))).ToString("x"); // Create session for controlling the Start Menu. AppiumOptions appiumOptions = new AppiumOptions(); appiumOptions.PlatformName = "Windows"; appiumOptions.AddAdditionalCapability("appTopLevelWindow", startMenuWindowHandle); WindowsDriver <WindowsElement> startMenuSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions); if (startMenuSession != null) { new Actions(session).SendKeys(OpenQA.Selenium.Keys.Escape + OpenQA.Selenium.Keys.Escape).Perform(); startMenuSession.Quit(); } } }
public static void AttachToApplication() { CloseApplication(); // Get the root desktop DesiredCapabilities rootCapabilities = new DesiredCapabilities(); rootCapabilities.SetCapability("app", "Root"); // Create a session for the desktop WindowsDriver <WindowsElement> desktopSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), rootCapabilities); // Set up a loop so it doesn't fail if it tries to find the window too soon. Note: if you have multiple cases where you need to wait for a window to be present, it's best to abstract this logic out to a helper function. WebDriverWait wait = new WebDriverWait(desktopSession, TimeSpan.FromSeconds(10)); wait.IgnoreExceptionTypes(typeof(InvalidOperationException)); WindowsElement appWindow = null; appWindow = wait.Until(w => { return((WindowsElement)w.FindElement(By.Name("MainWindow"))); }); // After getting the window, get it's handle string appHandle = appWindow.GetAttribute("NativeWindowHandle"); // Convert to Hex appHandle = (int.Parse(appHandle)).ToString("x"); // Create session by attaching to the top level window DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability("appTopLevelWindow", appHandle); Session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), capabilities); }
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); }
private void InitializeTestSession() { StartWinAppDriver(); Thread.Sleep(3000); // speeds up appium by not 'missing' the first attempt to find the window and then going through the timeouts. // Create a session for Desktop AppiumOptions desktopOptions = new AppiumOptions(); desktopOptions.AddAdditionalCapability("app", "Root"); desktopSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopOptions); Assert.IsNotNull(desktopSession); //desktopSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3)); mainWindow = desktopSession.FindElementByAccessibilityId(SQLiteArrayStore.Resources.AutomationIds.SimpleMessageBoxWindowID); string mainWindowTopLevelWindowHandle = (int.Parse(mainWindow.GetAttribute("NativeWindowHandle"))).ToString("x"); // Create session for messageBox window AppiumOptions messageboxOptions = new AppiumOptions(); messageboxOptions.AddAdditionalCapability("appTopLevelWindow", mainWindowTopLevelWindowHandle); messageBoxSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), messageboxOptions); Assert.IsNotNull(messageBoxSession); //messageBoxSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0.5)); }
public static WindowsDriver <WindowsElement> GetSession(String appid, String name) { WindowsDriver <WindowsElement> session; DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", appid); appCapabilities.SetCapability("deviceName", "WindowsPC"); try { session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); } catch (System.InvalidOperationException) { // get desktop session DesiredCapabilities desktopAppCapabilities = new DesiredCapabilities(); desktopAppCapabilities.SetCapability("app", "Root"); WindowsDriver <WindowsElement> desktopSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopAppCapabilities); // use desktop session to locate existing app session WindowsElement appWindow = desktopSession.FindElementByName(name); String topLevelWindowHandle = appWindow.GetAttribute("NativeWindowHandle"); topLevelWindowHandle = (int.Parse(topLevelWindowHandle)).ToString("x"); appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("appTopLevelWindow", topLevelWindowHandle); session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); } Assert.IsNotNull(session); return(session); }
public void ExitDialogSave() { WindowsElement toggle = session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]"); Assert.IsNotNull(toggle); bool initialToggleValue = toggle.GetAttribute("Toggle.ToggleState") == "1"; toggle.Click(); CloseSettings(); WindowsElement exitDialog = session.FindElementByName("Changes not saved"); Assert.IsNotNull(exitDialog); exitDialog.FindElementByName("Save").Click(); //check if window still opened WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); Assert.IsNotNull(powerToysWindow); //check settings change JObject savedProps = GetProperties(); Assert.AreNotEqual(initialToggleValue, GetPropertyValue <bool>(savedProps, "fancyzones_shiftDrag")); //return initial app state toggle.Click(); }
private void OpenTemplates() { WindowsElement templatesTab = session.FindElementByName("Templates"); templatesTab.Click(); string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected"); Assert.AreEqual("True", isSelected, "Templates tab cannot be opened"); }
protected static void OpenCustomLayouts() { WindowsElement customsTab = session.FindElementByName("Custom"); customsTab.Click(); string isSelected = customsTab.GetAttribute("SelectionItem.IsSelected"); Assert.AreEqual("True", isSelected, "Custom tab cannot be opened"); }
static PointF GetClickablePoint(WindowsElement element) { string cpString = element.GetAttribute("ClickablePoint"); string[] parts = cpString.Split(','); float x = float.Parse(parts[0]); float y = float.Parse(parts[1]); return(new PointF(x, y)); }
public bool CzyMaFocus(WindowsElement element) { if (element.GetAttribute("HasKeyboardFocus").ToString() == "True") { return(true); } else { return(false); } }
protected static DesiredCapabilities MakeCapabilities(WindowsElement appElement) { var handle = appElement.GetAttribute("NativeWindowHandle"); handle = (int.Parse(handle)).ToString("x"); // Convert to Hex var capabilities = new DesiredCapabilities(); capabilities.SetCapability("appTopLevelWindow", handle); return(capabilities); }
public void Test_08_ElementInfo() { WindowsElement element = session.FindElementByAccessibilityId("mainframe.ChildFrame00.form.TextArea00"); Assert.IsNotNull(element); Debug.WriteLine("element.GetAttribute:" + element.GetAttribute("AutomationId")); Debug.WriteLine("element.Text:" + element.Text); Debug.WriteLine("element.Name:" + element.Id); Debug.WriteLine("element.TagName:" + element.TagName); }
public void Test_14_CompStatus() { WindowsElement nexaButton00 = session.FindElementByAccessibilityId("mainframe.ChildFrame00.form.Button00"); Debug.WriteLine("nexaButton00.Displayed:" + nexaButton00.Displayed); Debug.WriteLine("nexaButton00.Enabled:" + nexaButton00.Enabled); Debug.WriteLine("nexaButton00.Selected:" + nexaButton00.Selected); Debug.WriteLine("nexaButton00.Location:" + nexaButton00.Location); Debug.WriteLine("nexaButton00.LocationOnScreenOnceScrolledIntoView:" + nexaButton00.LocationOnScreenOnceScrolledIntoView); Debug.WriteLine("nexaButton00.Size:" + nexaButton00.Size); Debug.WriteLine("nexaButton00.GetAttribute:" + nexaButton00.GetAttribute("AutomationId")); }
static PointF GetOriginOfBoundingRectangle(WindowsElement element) { string vpcpString = element.GetAttribute("BoundingRectangle"); // returned string format looks like: // Left:-1868 Top:382 Width:1013 Height:680 string[] vpparts = vpcpString.Split(new[] { ':', ' ' }, StringSplitOptions.RemoveEmptyEntries); float vpx = float.Parse(vpparts[1]); float vpy = float.Parse(vpparts[3]); return(new PointF(vpx, vpy)); }
protected static void OpenCustomLayouts() { try { WindowsElement customsTab = session.FindElementByName("Custom"); customsTab.Click(); string isSelected = customsTab.GetAttribute("SelectionItem.IsSelected"); Assert.AreEqual("True", isSelected, "Custom tab cannot be opened"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public WindowsDriver <WindowsElement> CreateDriver(WindowsElement app) { var handle = app.GetAttribute("NativeWindowHandle"); handle = (int.Parse(handle)).ToString("x"); var capabilities = new DesiredCapabilities(); capabilities.SetCapability("appTopLevelWindow", handle); var uri = new Uri(_windowsApplicationDriverUrl); return(new WindowsDriver <WindowsElement>(uri, capabilities)); }
protected static void OpenTemplates() { try { WindowsElement templatesTab = session.FindElementByName("Templates"); templatesTab.Click(); string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected"); Assert.AreEqual("True", isSelected, "Templates tab cannot be opened"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
// find a existing/running app on desktop public static WindowsDriver <WindowsElement> AttachExistingSession(string appName) { WindowsDriver <WindowsElement> desktopSession = CreateDesktopSession(); WindowsElement appWindow = desktopSession.FindElementByName(appName); string appWindowHandle = appWindow.GetAttribute("NativeWindowHandle"); // to hex string hexWindowHandle = (int.Parse(appWindowHandle)).ToString("x"); // create session by attaching to app top level window DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("appTopLevelWindow", hexWindowHandle); return(new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities)); }
protected static void Init(string url, string id, TestContext context) { if (Session == null) { //close app Close(); //check condition PreInit(ref url); try { AppiumOptions appCapabilities = new AppiumOptions(); appCapabilities.AddAdditionalCapability("app", id); appCapabilities.AddAdditionalCapability("ms:experimental-webdriver", true); Session = new WindowsDriver <WindowsElement>(new Uri(url), appCapabilities); } catch (Exception) { AppiumOptions desktopCapabilities = new AppiumOptions(); desktopCapabilities.AddAdditionalCapability("app", "Root"); var desktop = new WindowsDriver <WindowsElement>(new Uri(url), desktopCapabilities); WindowsElement recovery = desktop.FindElementByName(NameApp); var hwid = (Int32.Parse(recovery.GetAttribute("NativeWindowHandle"))).ToString("x"); AppiumOptions app = new AppiumOptions(); app.AddAdditionalCapability("appTopLevelWindow", hwid); app.AddAdditionalCapability("ms:experimental-webdriver", true); Session = new WindowsDriver <WindowsElement>(new Uri(url), app); } //wait load TimeWait(); //create actions if (Actions == null) { Actions = new Actions(Session); } } }
public virtual void TestInit() { // Attempt to go back to the main page in case Alarms & Clock app is started in EditAlarm view try { alarmTabElement = FindAlarmTabElement(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); DismissAddAlarmPage(); alarmTabElement = FindAlarmTabElement(); } Assert.IsNotNull(alarmTabElement); if (!alarmTabElement.Selected) { alarmTabElement.Click(); } // Different Alarm & Clock application version uses different UI elements if (alarmTabElement.GetAttribute("AutomationId") == "AlarmButton") { // Latest version of Alarms & Clock application AlarmTabClassName = "ListViewItem"; AlarmTabAutomationId = "AlarmButton"; StopwatchTabAutomationId = "StopwatchButton"; WorldClockTabAutomationId = "ClockButton"; } else { // Earlier version of Alarms & Clock application AlarmTabClassName = "PivotItem"; AlarmTabAutomationId = "AlarmPivotItem"; StopwatchTabAutomationId = "StopwatchPivotItem"; WorldClockTabAutomationId = "WorldClockPivotItem"; } }
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(); }
public void ExitDialogExit() { WindowsElement toggle = session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]"); Assert.IsNotNull(toggle); bool initialToggleValue = toggle.GetAttribute("Toggle.ToggleState") == "1"; toggle.Click(); CloseSettings(); WindowsElement exitDialog = session.FindElementByName("Changes not saved"); Assert.IsNotNull(exitDialog); exitDialog.FindElementByName("Exit").Click(); //check if window still opened try { WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); Assert.IsNull(powerToysWindow); } catch (OpenQA.Selenium.WebDriverException) { //window is no longer available, which is expected } //return initial app state Init(); //check settings change JObject savedProps = GetProperties(); Assert.AreEqual(initialToggleValue, GetPropertyValue <bool>(savedProps, "fancyzones_shiftDrag")); }
static void Main(string[] args) { // start winappdriver myProcess = Process.Start(WinAppDriver); // launch the browser via WebDriver CreateDriver(_browser); _driver.Navigate().GoToUrl("https://www.bing.com"); //var wh1 = _driver.WindowHandles.Count; //Console.WriteLine(wh1); //_driver.Navigate().GoToUrl("http://ie-snap/scratchtests/nisunny/drt/bugs/validity/popup.html"); //Thread.Sleep(2000); //_driver.FindElementByTagName("Button").Click(); //Thread.Sleep(2000); //var wh2 = _driver.WindowHandles.Count; //Console.WriteLine(wh2); //Console.ReadLine(); // Create a session for Desktop DesiredCapabilities desktopCapabilities = new DesiredCapabilities(); desktopCapabilities.SetCapability("app", "Root"); desktopSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopCapabilities); if (desktopSession == null) { Console.WriteLine("deskTopSession is null!"); Console.ReadLine(); } else { Console.WriteLine("Pass! deskTopSession is not null."); } // Find the browser window from the Desktop Session var browser = new BrowserInformation(_browser); WindowsElement browserWindow = desktopSession.FindElementByName(browser.applicationIdentifier); string browserTopLevelWindowHandle = browserTopLevelWindowHandle = (int.Parse(browserWindow.GetAttribute("NativeWindowHandle"))).ToString("x"); // Create session for already running browser DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("appTopLevelWindow", browserTopLevelWindowHandle); browserSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); if (browserSession == null) { Console.WriteLine("browserSession is null!"); Console.ReadLine(); } else { Console.WriteLine("Pass! browserSession is not null."); } // get the addressbar via WinAppDriver var addressBar = browserSession.FindElementByXPath("//Edit[@Name=\"" + browser.searchElementIdenifier + "\"]"); addressBar.Clear(); addressBar.SendKeys("http://www.google.com"); addressBar.SendKeys(OpenQA.Selenium.Keys.Enter); Thread.Sleep(3000); // enter the username and password into the dialog //var userFields = browserSession.FindElementsByXPath(browser.basicAuthDialogEditFields); //userFields[0].Clear(); //userFields[0].SendKeys("userName"); //Thread.Sleep(500); //userFields[1].Clear(); //userFields[1].SendKeys("passWord"); //Thread.Sleep(500); //userFields[2].Clear(); //userFields[2].SendKeys("passWord"); // hit enter //var okButton = browserSession.FindElementByXPath("//Window[@Name=\"Windows Security\"]/*[3]"); //okButton.SendKeys(OpenQA.Selenium.Keys.Enter); Thread.Sleep(3000); Console.WriteLine("clicking to close the browser"); browserSession.FindElementByName("Close Google - Microsoft Edge").Click(); TearDown(); }
public static string GetElementName(this WindowsElement element) { return(element.GetAttribute("Name")); }
public void ShouldFindBtnBlueViewByUsageNameInViewMenu() { WindowsElement match = sut.FindElementByUsageNameInLastINavigable("button to open the blue view"); Assert.Equal("BtnOpenBlueView", match.GetAttribute("AutomationId")); }
public static void Setup(TestContext context) { // Create a session for Desktop DesiredCapabilities desktopCapabilities = new DesiredCapabilities(); desktopCapabilities.SetCapability("app", "Root"); desktopSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopCapabilities); Assert.IsNotNull(desktopSession); // Launch Cortana Window using Windows Key + S keyboard shortcut to allow session creation to find it desktopSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Meta + "s" + OpenQA.Selenium.Keys.Meta); Thread.Sleep(TimeSpan.FromSeconds(1)); WindowsElement CortanaWindow = desktopSession.FindElementByName("Cortana"); string CortanaTopLevelWindowHandle = CortanaTopLevelWindowHandle = (int.Parse(CortanaWindow.GetAttribute("NativeWindowHandle"))).ToString("x"); // Create session for already running Cortana DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("appTopLevelWindow", CortanaTopLevelWindowHandle); cortanaSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(cortanaSession); // Set implicit timeout to 5 seconds to make element search to retry every 500 ms for at most ten times cortanaSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)); }