public static void LaunchPowerToys() { try { AppiumOptions opts = new AppiumOptions(); opts.PlatformName = "Windows"; opts.AddAdditionalCapability("app", "Microsoft.PowerToys_8wekyb3d8bbwe!PowerToys"); WindowsDriver <WindowsElement> driver = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), opts); Assert.IsNotNull(driver); driver.LaunchApp(); } catch (OpenQA.Selenium.WebDriverException) { //exception could be thrown even if app launched successfully } }
private bool ElementExists <TBy>(WindowsDriver <WindowsElement> searchContext, TBy by) where TBy : FindStrategy { try { var element = by.FindElement(searchContext); return(element != null); } catch (NoSuchElementException) { return(false); } catch (WebDriverException) { return(false); } }
public static void Setup(TestContext context) { // Cleanup leftover objects from previous test if exists TearDown(); // Launch Alarm Clock DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", CommonTestSettings.AlarmClockAppId); session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(session); Assert.IsNotNull(session.SessionId); // Initialize touch screen object touchScreen = new RemoteTouchScreen(session); Assert.IsNotNull(touchScreen); }
// 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)); }
public static void TestBug10763() // Preference: "Use wheel for zoom" is not kept { Driver.FindElementByName("Preferences").Click(); var preferences = jupiter.FindElementByName("Preferences"); preferences.FindElementByName("Mouse").Click(); preferences.FindElementByName("MyPreset1").Click(); var useWheel = preferences.FindElementByAccessibilityId("2037"); if (!useWheel.Selected) { useWheel.Click(); preferences.FindElementByName("OK").Click(); Driver.Close(); Thread.Sleep(4000); AppiumOptions appOptions = new AppiumOptions(); Assert.IsNotNull(appOptions); appOptions.AddAdditionalCapability("app", @"C:\Program Files\TechnoStar\Jupiter-Post_4.1.2\PCAD_main.exe"); Driver = new WindowsDriver <WindowsElement>( new Uri("http://127.0.0.1:4723"), appOptions, TimeSpan.FromMinutes(5) ); Assert.IsNotNull(Driver); Assert.IsNotNull(Driver.SessionId); wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(50)); Assert.IsNotNull(wait); Driver.Manage().Window.Maximize(); jupiter = Driver.FindElementByXPath("//Window[starts-with(@Name,'Jupiter-Post 4.1.2')]"); toolBar = Driver.FindElementByName("Ribbon Tabs"); } Driver.FindElementByName("Preferences").Click(); preferences = jupiter.FindElementByName("Preferences"); preferences.FindElementByName("Mouse").Click(); preferences.FindElementByName("MyPreset1").Click(); useWheel = preferences.FindElementByAccessibilityId("2037"); Assert.IsTrue(useWheel.Selected); Thread.Sleep(2000); }
public bool StartSession() { var url = this.settings.MachineUrl; var deviceName = this.settings.DeviceName; var platformName = this.settings.PlatformName; var desktopLaunched = true; if (this.CurrentSession == null || !this.IsSessionAlive()) { WindowsDriver <WindowsElement> desktop = this.StartAppSession(url, deviceName, platformName, "Root"); desktopLaunched = desktop != null; this.CurrentSession = desktop; } return(desktopLaunched); }
public static void setup() { try { dynamic CalculatorSession; DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability("app", "C:\\Windows\\System32\\calc.exe"); CalculatorSession = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), capabilities); //CalculatorSession.Manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); } catch (Exception e) { } finally { } }
public static void fecharAplicacao() { // Close the application and delete the session if (session != null) { try { session.FindElementByXPath(WindowsObjects.JanelaPrincipal.ICONE_FECHAR_APLICACAO).Click(); session.FindElementByXPath("//Button[@Name='OK']").Click(); session = null; } catch (Exception e) { string message = e.Message; } } }
/// <summary> /// Wraps the WindowsDriver.FindElementByClassName and adds retry logic for when the element cannot be found due to WinAppDriver losing the window. /// If FindElementByAccessibilityId fails for a different reason rethrow the error. /// </summary> public static WindowsElement TryFindElementByClassName(this WindowsDriver <WindowsElement> driver, string name) { try { return(driver.FindElementByClassName(name)); } catch (WebDriverException ex) { if (ex.Message.Contains("Currently selected window has been closed")) { driver.SwitchToCurrentWindowHandle(); return(driver.FindElementByClassName(name)); } throw; } }
internal AppiumElementContext( string windowName, WindowsDriver <WindowsElement> driver, ILogger logger, ISettings settings, AppiumUiItemWrapperFactory wrapperFactory, IAwaitingService awaitingService, Action <string> appRootFunction) { this.WindowName = windowName; this.Settings = settings; this.Driver = driver; this.WrapperFactory = wrapperFactory; this.Logger = logger; this.AwaitingService = awaitingService; this.BringIntoViewFunc = appRootFunction; }
public void LaunchApp() { if (AppSession == null) { var appiumOptions = new AppiumOptions(); appiumOptions.AddAdditionalCapability("app", AppToLaunch); appiumOptions.AddAdditionalCapability("deviceName", "WindowsPC"); AppSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions); Assert.IsNotNull(AppSession, "Unable to launch app."); AppSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(4); // Maximize the window to have a consistent size and position. AppSession.Manage().Window.Maximize(); } }
private async Task <bool> ClickNoOnPopUpAsync(WindowsDriver <WindowsElement> session) { await Task.Delay(TimeSpan.FromSeconds(1)); // Allow extra time for popup to be displayed var popups = session.FindElementsByAccessibilityId("Popup Window"); if (popups.Count == 1) { var no = popups[0].FindElementsByName("No"); if (no.Count == 1) { no[0].Click(); return(true); } } return(false); }
public void TestFixtureTearDown() { 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; }
public void LaunchApp() { if (AppSession == null) { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", AppToLaunch); appCapabilities.SetCapability("deviceName", "WindowsPC"); AppSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(AppSession, "Unable to launch app."); AppSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(4)); // Maximize the window to have a consistent size and position AppSession.Manage().Window.Maximize(); } }
private bool ElementHasContent <TBy>(WindowsDriver <WindowsElement> searchContext, TBy by) where TBy : Locators.FindStrategy { try { var element = by.FindElement(searchContext); return(!string.IsNullOrEmpty(element.Text)); } catch (NoSuchElementException) { return(false); } catch (InvalidOperationException) { return(false); } }
public void GetWindowHandles() { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", CommonTestSettings.NotepadAppId); WindowsDriver <WindowsElement> multiWindowsSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(multiWindowsSession); Assert.IsNotNull(multiWindowsSession.SessionId); var handles = multiWindowsSession.WindowHandles; Assert.IsNotNull(handles); Assert.IsTrue(handles.Count > 0); multiWindowsSession.Quit(); }
public static void Setup(TestContext context) { // Launch a new instance of Notepad application if (session == null) { // Create a new session to launch Notepad application var appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", AppId); appCapabilities.SetCapability("appWorkingDir", AppWorkingDir); session = new WindowsDriver <WindowsElement>(new Uri(DriverUrl), appCapabilities); Assert.IsNotNull(session); Assert.IsNotNull(session.SessionId); // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times session.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1.5)); } }
public static void Setup(TestContext context) { // Launch Calculator application if it is not yet launched if (session == null) { // Create a new session to bring up an instance of the Calculator application // Note: Multiple calculator windows (instances) share the same process Id DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", AppPath); appCapabilities.SetCapability("deviceName", "WindowsPC"); session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(session); // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5); } }
public void NavigateBack_SystemApp() { session = Utility.CreateNewSession(CommonTestSettings.ExplorerAppId); Thread.Sleep(TimeSpan.FromSeconds(1)); var originalTitle = session.Title; Assert.AreNotEqual(string.Empty, originalTitle); // Navigate Windows Explorer to change folder session.Keyboard.SendKeys(Keys.Alt + "d" + Keys.Alt + CommonTestSettings.TestFolderLocation + Keys.Enter); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.AreNotEqual(originalTitle, session.Title); // Navigate back to the original folder session.Navigate().Back(); Assert.AreEqual(originalTitle, session.Title); }
public void Initialize() { var appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); appCapabilities = new DesiredCapabilities(); var path = Path.GetFullPath(appPath + "\\RM.exe"); Assert.IsTrue(File.Exists(path), "Expected to find OemUiTool executable at location " + path + " but didn't. Make sure to run the debug build of the UI application first."); appCapabilities.SetCapability("app", path); appCapabilities.SetCapability("appWorkingDir", Path.GetFullPath(appPath)); app = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); windows = new Dictionary <string, string> { [app.Title] = app.CurrentWindowHandle }; }
public void ErrorStaleSessionId() { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", CommonTestSettings.AlarmClockAppId); session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(session); Assert.IsNotNull(session.SessionId); string applicationTitle = session.Title; Assert.IsNotNull(applicationTitle); session.Quit(); applicationTitle = session.Title; Assert.Fail("Exception should have been thrown"); }
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(); }
public static void ClassCleanup() { // Create a Windows Explorer session to delete the saved text file above DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", ExplorerAppId); appCapabilities.SetCapability("deviceName", "WindowsPC"); WindowsDriver <WindowsElement> windowsExplorerSession = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(windowsExplorerSession); // Navigate Windows Explorer to the target save location folder windowsExplorerSession.Keyboard.SendKeys(Keys.Alt + "d" + Keys.Alt + TargetSaveLocation + Keys.Enter); // Verify that the file is indeed saved in the working directory and delete it windowsExplorerSession.FindElementByAccessibilityId("SearchEditBox").SendKeys(TestFileName + Keys.Enter); Thread.Sleep(TimeSpan.FromSeconds(2)); WindowsElement testFileEntry = null; try { testFileEntry = windowsExplorerSession.FindElementByName("Items View").FindElementByName(TestFileName + ".txt") as WindowsElement; // In case extension is added automatically } catch { try { testFileEntry = windowsExplorerSession.FindElementByName("Items View").FindElementByName(TestFileName) as WindowsElement; } catch { } } // Delete the test file when it exists if (testFileEntry != null) { testFileEntry.Click(); testFileEntry.SendKeys(Keys.Delete); Thread.Sleep(TimeSpan.FromSeconds(1)); } windowsExplorerSession.Quit(); windowsExplorerSession = null; TearDown(); }
public void GetSessionsMultipleEntry() { DesiredCapabilities alarmAppCapabilities = new DesiredCapabilities(); alarmAppCapabilities.SetCapability("app", CommonTestSettings.AlarmClockAppId); WindowsDriver <WindowsElement> alarmSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), alarmAppCapabilities); Assert.IsNotNull(alarmSession); DesiredCapabilities notepadAppCapabilities = new DesiredCapabilities(); notepadAppCapabilities.SetCapability("app", CommonTestSettings.NotepadAppId); WindowsDriver <WindowsElement> notepadSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), notepadAppCapabilities); Assert.IsNotNull(notepadSession); using (HttpWebResponse response = WebRequest.Create(CommonTestSettings.WindowsApplicationDriverUrl + "/sessions").GetResponse() as HttpWebResponse) { var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); JObject responseObject = JObject.Parse(responseString); Assert.AreEqual(0, (int)responseObject["status"]); JArray capabilitiesArray = (JArray)responseObject["value"]; Assert.AreEqual(2, capabilitiesArray.Count); foreach (var entry in capabilitiesArray.Children()) { if (entry["id"].ToString() == alarmSession.SessionId.ToString()) { Assert.AreEqual(CommonTestSettings.AlarmClockAppId, entry["capabilities"]["app"].ToString()); } else if (entry["id"].ToString() == notepadSession.SessionId.ToString()) { Assert.AreEqual(CommonTestSettings.NotepadAppId, entry["capabilities"]["app"].ToString()); } else { Assert.Fail("This session entry is unexpected"); } } } alarmSession.Quit(); notepadSession.Quit(); }
public void GetWindowHandlesModernApp() { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId); WindowsDriver <WindowsElement> multiWindowsSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(multiWindowsSession); Assert.IsNotNull(multiWindowsSession.SessionId); var windowHandlesBefore = multiWindowsSession.WindowHandles; Assert.IsNotNull(windowHandlesBefore); Assert.IsTrue(windowHandlesBefore.Count > 0); // Preserve previously opened Edge window(s) and only manipulate newly opened windows List <String> previouslyOpenedEdgeWindows = new List <String>(windowHandlesBefore); previouslyOpenedEdgeWindows.Remove(multiWindowsSession.CurrentWindowHandle); // Open a new window multiWindowsSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Control + "n" + OpenQA.Selenium.Keys.Control); System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds var windowHandlesAfter = multiWindowsSession.WindowHandles; Assert.IsNotNull(windowHandlesAfter); Assert.AreEqual(windowHandlesBefore.Count + 1, windowHandlesAfter.Count); // Preserve previously opened Edge Windows by only closing newly opened windows List <String> newlyOpenedEdgeWindows = new List <String>(windowHandlesAfter); foreach (var previouslyOpenedEdgeWindow in previouslyOpenedEdgeWindows) { newlyOpenedEdgeWindows.Remove(previouslyOpenedEdgeWindow); } foreach (var windowHandle in newlyOpenedEdgeWindows) { multiWindowsSession.SwitchTo().Window(windowHandle); multiWindowsSession.Close(); } multiWindowsSession.Quit(); }
public static void Setup(TestContext context) { // Launch Calculator if it is not yet launched if (session == null || touchScreen == null) { session = Utility.CreateNewSession(CommonTestSettings.CalculatorAppId); Assert.IsNotNull(session); Assert.IsNotNull(session.SessionId); try { header = session.FindElementByAccessibilityId("Header"); } catch { header = session.FindElementByAccessibilityId("ContentPresenter"); } Assert.IsNotNull(header); // Initialize touch screen object touchScreen = new RemoteTouchScreen(session); Assert.IsNotNull(touchScreen); } // Ensure that calculator is in standard mode if (!header.Text.Equals("Standard", StringComparison.OrdinalIgnoreCase)) { try { // Current version of Calculator application session.FindElementByAccessibilityId("TogglePaneButton").Click(); } catch { // Previous version of Calculator application session.FindElementByAccessibilityId("NavButton").Click(); } Thread.Sleep(TimeSpan.FromSeconds(1)); var splitViewPane = session.FindElementByClassName("SplitViewPane"); splitViewPane.FindElementByName("Standard Calculator").Click(); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.IsTrue(header.Text.Equals("Standard", StringComparison.OrdinalIgnoreCase)); } }
public void CreateSessionWithArguments_ClassicApp() { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", CommonTestSettings.NotepadAppId); appCapabilities.SetCapability("appArguments", "NonExistentTextFile.txt"); session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(session); Assert.IsNotNull(session.SessionId); // Verify that Notepad file not found dialog is displayed and dismiss it var notFoundDialog = session.FindElementByName("Notepad"); Assert.AreEqual("ControlType.Window", notFoundDialog.TagName); notFoundDialog.FindElementByName("No").Click(); Assert.IsTrue(session.Title.Contains("Notepad")); }
public void CreateSessionFromExistingWindowHandle_ModernApp() { // Get the top level window handle of a running application secondarySession = Utility.CreateNewSession(CommonTestSettings.CalculatorAppId); var existingApplicationTopLevelWindow = secondarySession.CurrentWindowHandle; // Create a new session by attaching to an existing application top level window DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("appTopLevelWindow", existingApplicationTopLevelWindow); session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(session); Assert.IsNotNull(session.SessionId); // Verify that newly created session is indeed attached to the correct application top level window Assert.AreEqual(secondarySession.CurrentWindowHandle, session.CurrentWindowHandle); Assert.AreEqual(secondarySession.FindElementByAccessibilityId("AppNameTitle"), session.FindElementByAccessibilityId("AppNameTitle")); }
public void CreateSessionFromExistingWindowHandleError_NonTopLevelWindowHandle() { // Get a non top level window element secondarySession = Utility.CreateNewSession(CommonTestSettings.CalculatorAppId); var nonTopLevelWindowHandle = secondarySession.FindElementByClassName("Windows.UI.Core.CoreWindow").GetAttribute("NativeWindowHandle"); try { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("appTopLevelWindow", nonTopLevelWindowHandle); session = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities); Assert.Fail("Exception should have been thrown"); } catch (InvalidOperationException exception) { Assert.AreEqual("Cannot find active window specified by capabilities: appTopLevelWindow", exception.Message); } }
public static void Main(string[] args) { var options = new AppiumOptions(); options.AddAdditionalCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"); options.AddAdditionalCapability("deviceName", "WindowsPC"); Session = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), options); Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); Session.Manage().Window.Maximize(); Session.FindElementByName("Two").Click(); Session.FindElementByName("Plus").Click(); Session.FindElementByName("Two").Click(); Session.FindElementByName("Equals").Click(); var results = Session.FindElementByAccessibilityId("CalculatorResults"); Console.WriteLine(results.Text); Session.Quit(); }