private static bool CheckPowerToysLaunched() { trayButton.Click(); bool isLaunched = false; try { WindowsElement pt = session.FindElementByName("PowerToys"); isLaunched = (pt != null); } catch (OpenQA.Selenium.WebDriverException) { //PowerToys not found } trayButton.Click(); //close return(isLaunched); }
void ClickOrTapElement(WindowsElement element) { try { // For most stuff, a simple click will work element.Click(); } catch (InvalidOperationException) { // Some elements aren't "clickable" from an automation perspective (e.g., Frame renders as a Border // with content in it; if the content is just a TextBlock, we'll end up here) // All is not lost; we can figure out the location of the element in in the application window // and Tap in that spot PointF p = ElementToClickablePoint(element); TapCoordinates(p.X, p.Y); } }
public static WindowsDriver <WindowsElement> abrirFenix() { if (session == null) { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", EXECUTAVEL_FENIX); try { session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); } catch (Exception e) { string message = e.Message; } Assert.IsNotNull(session); Assert.IsNotNull(session.SessionId); var currentWindowHandle = session.CurrentWindowHandle; Thread.Sleep(TimeSpan.FromSeconds(3)); var allWindowHandles = session.WindowHandles; session.SwitchTo().Window(allWindowHandles[0]); try { WindowsElement element = session.FindElementByName("Novidades das versões"); //element.FindElementByXPath(WindowsObjects.JanelaPrincipal.ICONE_FECHAR_APLICACAO).Click(); session.FindElementByXPath(WindowsObjects.JanelaPrincipal.ICONE_FECHAR_APLICACAO).Click(); } catch (Exception e) { string message = e.Message; } } return(session); }
public void HighlightHexInputTest() { ScrollDown(2); WindowsElement hexInput = session.FindElementByXPath("//Edit[@Name=\"Hex\"]"); Assert.IsNotNull(hexInput); hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); string invalidSymbols = "qwrtyuiopsghjklzxvnm,./';][{}:`~!#@$%^&*()_-+=\"\'\\"; foreach (char symbol in invalidSymbols) { hexInput.SendKeys(symbol.ToString()); Assert.AreEqual("", hexInput.Text.Trim()); } string validSymbols = "0123456789abcdef"; foreach (char symbol in validSymbols) { hexInput.SendKeys(symbol.ToString()); Assert.AreEqual(symbol.ToString(), hexInput.Text.Trim()); hexInput.SendKeys(OpenQA.Selenium.Keys.Backspace); } //too many symbols hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); hexInput.SendKeys("000000"); hexInput.SendKeys("1"); Assert.AreEqual("000000\r\n", hexInput.Text); //short string hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); hexInput.SendKeys("000"); new Actions(session).MoveToElement(hexInput).MoveByOffset(0, hexInput.Rect.Height).Click().Perform(); Assert.AreEqual("000000\r\n", hexInput.Text); hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); hexInput.SendKeys("1234"); new Actions(session).MoveToElement(hexInput).MoveByOffset(0, hexInput.Rect.Height).Click().Perform(); Assert.AreEqual("112233\r\n", hexInput.Text); }
public void Touch_Click_OriginPointer() { WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem"); WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem"); int relativeX = 0; // Initial x coordinate int relativeY = 0; // Initial y coordinate Assert.IsNotNull(alarmPivotItem); Assert.IsNotNull(worldClockPivotItem); Assert.IsTrue(alarmPivotItem.Selected); Assert.IsFalse(worldClockPivotItem.Selected); // Perform touch click action using pointer coordinate origin to switch from Alarm to WorldClock tab PointerInputDevice touchDevice = new PointerInputDevice(PointerKind.Touch); ActionSequence sequence = new ActionSequence(touchDevice, 0); relativeX = worldClockPivotItem.Location.X - relativeX; relativeY = worldClockPivotItem.Location.Y - relativeY; sequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Pointer, relativeX, relativeY, TimeSpan.Zero)); sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact)); sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact)); session.PerformActions(new List <ActionSequence> { sequence }); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.IsFalse(alarmPivotItem.Selected); Assert.IsTrue(worldClockPivotItem.Selected); // Perform touch click action using pointer coordinate origin to switch from WorldClock to Alarm tab sequence = new ActionSequence(touchDevice, 0); relativeX = alarmPivotItem.Location.X - relativeX; relativeY = alarmPivotItem.Location.Y - relativeY; sequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Pointer, relativeX, relativeY, TimeSpan.Zero)); sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact)); sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact)); session.PerformActions(new List <ActionSequence> { sequence }); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.IsTrue(alarmPivotItem.Selected); Assert.IsFalse(worldClockPivotItem.Selected); }
public void DoesNotSpawnStartMenuOnLongPress() { PressWinKey(); Thread.Sleep(TimeSpan.FromSeconds(2)); try { // FindElementByClassName will be faster than using with XPath. WindowsElement shortcutHelperWindow = session.FindElementByClassName("PToyD2DPopup"); Assert.IsNotNull(shortcutHelperWindow); } catch (InvalidOperationException) { // Not the exception we wanted to catch here. Assert.Fail("Shortcut Guide not found"); } ReleaseWinKey(); Thread.Sleep(TimeSpan.FromSeconds(0.5)); WindowsElement startMenuWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Window[@Name=\"Start\"]"); }
public void SetImplicitTimeout_FindElementNotFound() { session.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(Convert.ToDouble(implicitTimeoutMs))); try { stopWatch.Restart(); WindowsElement element = session.FindElementByAccessibilityId("InvalidAccessibiliyId"); Assert.Fail("Exception should have been thrown"); } catch (InvalidOperationException exception) { stopWatch.Stop(); // The search should fail after the timeout period lapsed Assert.IsTrue(stopWatch.ElapsedMilliseconds >= implicitTimeoutMs); Assert.AreEqual("An element could not be located on the page using the given search parameters.", exception.Message); } }
public void ClearSearchBox() { try { // Locate Cortana search box to ensure it is still displayed on the screen searchBox = cortanaSession.FindElementByAccessibilityId("SearchTextBox"); searchBox.Clear(); } catch { // Use Windows Key + S to relaunch Cortana window if it is not displayed desktopSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Meta + "s" + OpenQA.Selenium.Keys.Meta); Thread.Sleep(TimeSpan.FromSeconds(1)); searchBox = cortanaSession.FindElementByAccessibilityId("SearchTextBox"); } Assert.IsNotNull(searchBox); Thread.Sleep(TimeSpan.FromSeconds(0.5)); }
public void PlayMedia() { Thread.Sleep(1000); WindowsElement play = session.FindElementByAccessibilityId("PlayPauseButton"); Assert.IsNotNull(play); Assert.IsNotNull(session.FindElementByAccessibilityId("svPanel")); Thread.Sleep(1000); try { play.Click(); } catch { } Thread.Sleep(1000); play.Click(); }
/// <summary> /// Dispose the VPN session and close the app. /// </summary> public void Dispose() { // Close the application and delete the session if (this.Session != null) { this.Session.SwitchTo(); try { WindowsElement landingView = this.Session.FindElementByClassName("LandingView"); } catch (InvalidOperationException) { UserCommonOperation.UserSignOut(this); } this.Session.Quit(); this.Session = null; } }
public void KH035_NhapThieuDuLieu() { button_Them.Click(); SwitchToPopupWindow(); window_Them = session.FindElementByClassName("Popup"); Thread.Sleep(100); SwitchToPopupWindow(); window_Them.FindElementByName("Thêm").Click(); bool isNewKhachHangExists = table_KhachHang.FindElementsByTagName("DataItem").Any(row => { var cell_Ten = row.FindElementsByClassName("DataGridCell")[1]; return(cell_Ten.Text.Equals("")); }); Assert.IsTrue(isNewKhachHangExists); }
public void HighlightOpacityClearValueButton() { ScrollDown(3); WindowsElement editor = session.FindElementByName("Zone opacity (%)"); Assert.IsNotNull(editor); editor.Click(); //activate AppiumWebElement clearButton = editor.FindElementByName("Clear value"); Assert.IsNotNull(clearButton); /*element is not pointer- or keyboard interactable.*/ Actions action = new Actions(session); action.MoveToElement(clearButton).Click().Perform(); Assert.AreEqual("\r\n", editor.Text); }
public void AlarmDelete() { WindowsElement alarmEntry = null; // Sprawdzenie, czy wcześniej utworzono wpis alarmu. W przeciwnym razie tworzony jest poprzez wywołanie AlarmAdd() try { alarmEntry = session.FindElementByXPath($"//ListItem[starts-with(@Name, \"{AlarmInfo}\")]"); } catch { AlarmAdd(); alarmEntry = session.FindElementByXPath($"//ListItem[starts-with(@Name, \"{AlarmInfo}\")]"); } Assert.IsNotNull(alarmEntry); touchScreen.LongPress(alarmEntry.Coordinates); session.FindElementByName("Usuń").Click(); }
protected static bool OpenEditor() { try { new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform(); //editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]"); editorWindow = session.FindElementByName("FancyZones Editor"); Assert.IsNotNull(editorWindow, "Couldn't find editor window"); return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="OnboardingScreen"/> class. /// </summary> /// <param name="vpnSession">VPN session.</param> /// <param name="viewClassName">onboarding screen view class name.</param> public OnboardingScreen(WindowsDriver <WindowsElement> vpnSession, string viewClassName) { var onboardingView = vpnSession.FindElementByClassName(viewClassName); var textBlocks = onboardingView.FindElementsByClassName("TextBlock"); Assert.IsTrue(textBlocks.Count > 3); this.closeButton = vpnSession.FindElementByName("Close"); this.skip = textBlocks[0]; this.image = vpnSession.FindElementByClassName("Image"); this.title = textBlocks[1]; this.subtitle = textBlocks[2]; this.nextButton = vpnSession.FindElementByName("Next"); Assert.IsNotNull(this.closeButton); Assert.IsNotNull(this.skip); Assert.IsNotNull(this.image); Assert.IsNotNull(this.title); Assert.IsNotNull(this.subtitle); Assert.IsNotNull(this.nextButton); }
public void ViewUserTest() { 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); }
/// <summary> /// Dispose the browser session and close the browser. /// </summary> public void Dispose() { // Close the application and delete the session if (this.Session != null) { this.Session.Close(); try { WindowsElement closeButton = this.Session.FindElementByName("Close Tabs"); closeButton.Click(); } catch (InvalidOperationException) { } this.Session.Quit(); this.Session = null; } }
public static void DrawRectangle(WindowsDriver <WindowsElement> session) { OpenQA.Selenium.Appium.Interactions.PointerInputDevice penDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Pen); // Select the Brushes toolbox to have the Brushes Pane sidebar displayed and ensure that Marker is selected session.FindElementByAccessibilityId("Toolbox").FindElementByAccessibilityId("TopBar_ArtTools").Click(); session.FindElementByAccessibilityId("SidebarWrapper").FindElementByAccessibilityId("PixelPencil3d").Click(); // Locate the drawing surface WindowsElement inkCanvas = session.FindElementByAccessibilityId("InteractorFocusWrapper"); Point canvasCoordinate = inkCanvas.Coordinates.LocationInViewport; Size squareSize = new Size(inkCanvas.Size.Width * 3 / 5, inkCanvas.Size.Height * 3 / 5); Point A = new Point(canvasCoordinate.X + inkCanvas.Size.Width / 5, canvasCoordinate.Y + inkCanvas.Size.Height / 5); TimeSpan howFast = TimeSpan.FromMilliseconds(300.0); ActionSequence sequence = new ActionSequence(penDevice, 0); // Draw line AB from point A to B sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X, A.Y, TimeSpan.Zero)); sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact)); sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X + squareSize.Width, A.Y, howFast)); sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact)); // Draw line BC from point B to C sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact)); sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X + squareSize.Width, A.Y + squareSize.Height, howFast)); sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact)); // Draw line CD from point C to D sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact)); sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X, A.Y + squareSize.Height, howFast)); sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact)); // Draw line DA from point D to A sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact)); sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, A.X, A.Y, howFast)); sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact)); session.PerformActions(new List <ActionSequence> { sequence }); }
/// <summary> /// Waits for an element to be displayed until the timeout is reached. /// </summary> /// <param name="element">WindowsElement in the Calculator application.</param> /// <param name="timeout">Timeout in ms.</param> public static void WaitForDisplayed(this WindowsElement element, int timeout = 2000) { Stopwatch timer = new Stopwatch(); timer.Reset(); timer.Start(); while (timer.ElapsedMilliseconds < timeout) { if (element.Displayed) { timer.Stop(); return; } Logger.LogMessage("Waiting for 10ms in WaitForDisplayed"); Thread.Sleep(10); } timer.Stop(); Assert.Fail(String.Format("{0} was not displayed in {1} ms", element, timeout)); }
public void AlarmDelete() { WindowsElement alarmEntry = null; // Check if an alarm entry has been created previously. Otherwise create one by calling AddAlarmEntry(); try { alarmEntry = session.FindElementByXPath($"//ListItem[starts-with(@Name, \"{NewAlarmName}\")]"); } catch { AlarmAdd(); alarmEntry = session.FindElementByXPath($"//ListItem[starts-with(@Name, \"{NewAlarmName}\")]"); } Assert.IsNotNull(alarmEntry); touchScreen.LongPress(alarmEntry.Coordinates); session.FindElementByName("Delete").Click(); }
/// <summary> /// Initializes a new instance of the <see cref="WindowsNotificationScreen"/> class. /// </summary> /// <param name="desktopSession">Desktop session.</param> public WindowsNotificationScreen(WindowsDriver <WindowsElement> desktopSession) { try { WindowsElement notification = Utils.WaitUntilFindElement(desktopSession.FindElementByAccessibilityId, "NormalToastView"); this.titleText = notification.FindElementByAccessibilityId("TitleText"); this.messageText = notification.FindElementByAccessibilityId("MessageText"); this.dismissButton = notification.FindElementByAccessibilityId("DismissButton"); } catch (Exception) { Utils.WaitUntilFindElement(desktopSession.FindElementByName, "Action Center").Click(); var notification = Utils.WaitUntilFindElement(desktopSession.FindElementByName, "Notifications from Firefox Private Network VPN"); var latestNotification = notification.FindElementByClassName("ListViewItem"); this.titleText = latestNotification.FindElementByAccessibilityId("Title"); this.messageText = latestNotification.FindElementByAccessibilityId("Content"); this.dismissButton = latestNotification.FindElementByAccessibilityId("DismissButton"); } }
public virtual void TestInit() { // Attempt to go back to the main page in case Alarms & Clock app is started in EditAlarm view try { alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem"); } catch { DismissAddAlarmPage(); alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem"); } Assert.IsNotNull(alarmTabElement); if (!alarmTabElement.Selected) { alarmTabElement.Click(); } }
public void GetActiveElement_NonFocusableElement() { WindowsElement recallMemoryButton = session.FindElementByAccessibilityId("MemRecall"); recallMemoryButton.Click(); WindowsElement activeElement = session.SwitchTo().ActiveElement() as WindowsElement; Assert.IsNotNull(activeElement); Assert.AreNotEqual(recallMemoryButton, activeElement); WindowsElement clearMemoryButton = session.FindElementByAccessibilityId("ClearMemoryButton"); clearMemoryButton.Click(); WindowsElement activeElementAfter = session.SwitchTo().ActiveElement() as WindowsElement; Assert.IsNotNull(activeElementAfter); Assert.AreNotEqual(clearMemoryButton, activeElementAfter); Assert.AreEqual(activeElement, activeElementAfter); }
public void GetActiveElement_FocusableElement() { WindowsElement num8Button = session.FindElementByAccessibilityId("num8Button"); num8Button.Click(); WindowsElement activeElement = session.SwitchTo().ActiveElement() as WindowsElement; Assert.IsNotNull(activeElement); Assert.AreEqual(num8Button, activeElement); WindowsElement plusButton = session.FindElementByAccessibilityId("plusButton"); plusButton.Click(); WindowsElement activeElementAfter = session.SwitchTo().ActiveElement() as WindowsElement; Assert.IsNotNull(activeElementAfter); Assert.AreEqual(plusButton, activeElementAfter); Assert.AreNotEqual(activeElement, activeElementAfter); }
public void ClickElementError_ElementNotVisible() { // Navigate to Stopwatch tab and attempt to click on addAlarmButton that is no longer displayed WindowsElement addAlarmButton = session.FindElementByAccessibilityId("AddAlarmButton"); session.FindElementByAccessibilityId("StopwatchPivotItem").Click(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.IsFalse(addAlarmButton.Displayed); try { addAlarmButton.Click(); Assert.Fail("Exception should have been thrown"); } catch (InvalidOperationException exception) { Assert.AreEqual(ErrorStrings.ElementNotVisible, exception.Message); } }
public static void ClassCleanup() { CloseSettings(); try { WindowsElement exitDialogButton = session.FindElementByName("Exit"); if (exitDialogButton != null) { exitDialogButton.Click(); } } catch (OpenQA.Selenium.WebDriverException) { //element couldn't be located } TearDown(); }
public void MouseClick() { // Locate the calculatorResult element WindowsElement calculatorResult = session.FindElementByAccessibilityId("CalculatorResults"); Assert.IsNotNull(calculatorResult); // Implicitly invoke /session/:sessionId/moveto and /session/:sessionId/click WindowsElement num8Button = session.FindElementByAccessibilityId("num8Button"); session.Mouse.Click(num8Button.Coordinates); Assert.AreEqual("8", calculatorResult.Text.Replace("Display is", string.Empty).Trim()); // Explicitly invoke /session/:sessionId/moveto and then /session/:sessionId/click on the current position WindowsElement clearButton = session.FindElementByAccessibilityId("clearButton"); session.Mouse.MouseMove(clearButton.Coordinates); session.Mouse.Click(null); Assert.AreEqual("0", calculatorResult.Text.Replace("Display is", string.Empty).Trim()); // Open a context menu on the application title bar to expose the context menu and verify that it contains minimize. // The context menu is parented on the desktop instead of the application. Thus, a desktop session is used to find it. // This command implicitly invoke /session/:sessionId/moveto and /session/:sessionId/click with button 2 parameter WindowsElement appNameTitle = session.FindElementByAccessibilityId("AppNameTitle"); session.Mouse.ContextClick(appNameTitle.Coordinates); Thread.Sleep(TimeSpan.FromSeconds(1.5)); WindowsDriver <WindowsElement> desktopSession = Utility.CreateNewSession(CommonTestSettings.DesktopAppId); try { Assert.IsNotNull(desktopSession.FindElementByName("System").FindElementByName("Minimize")); clearButton.Click(); // Dismiss the context menu } finally { if (desktopSession != null) { desktopSession.Quit(); } } }
public void Touch_Scroll_Horizontal() { WindowsElement homePagePivot = session.FindElementByAccessibilityId("HomePagePivot"); WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem"); WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem"); Assert.IsNotNull(homePagePivot); Assert.IsNotNull(alarmPivotItem); Assert.IsNotNull(worldClockPivotItem); Assert.IsTrue(alarmPivotItem.Selected); Assert.IsFalse(worldClockPivotItem.Selected); // Perform scroll left touch action to switch from Alarm to WorldClock tab PointerInputDevice touchDevice = new PointerInputDevice(PointerKind.Touch); ActionSequence sequence = new ActionSequence(touchDevice, 0); sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero)); sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact)); sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, -session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5))); sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact)); session.PerformActions(new List <ActionSequence> { sequence }); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.IsFalse(alarmPivotItem.Selected); Assert.IsTrue(worldClockPivotItem.Selected); // Perform scroll right touch action to switch back from WorldClock to Alarm tab sequence = new ActionSequence(touchDevice, 0); sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero)); sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact)); sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5))); sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact)); session.PerformActions(new List <ActionSequence> { sequence }); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.IsTrue(alarmPivotItem.Selected); Assert.IsFalse(worldClockPivotItem.Selected); }
public void Touch_Click_OriginViewport() { WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem"); WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem"); int x = worldClockPivotItem.Location.X; // x coordinate of UI element relative to application window int y = worldClockPivotItem.Location.Y; // y coordinate of UI element relative to application window Assert.IsNotNull(alarmPivotItem); Assert.IsNotNull(worldClockPivotItem); Assert.IsTrue(alarmPivotItem.Selected); Assert.IsFalse(worldClockPivotItem.Selected); // Perform touch click action using viewport coordinate origin to switch from Alarm to WorldClock tab PointerInputDevice touchDevice = new PointerInputDevice(PointerKind.Touch); ActionSequence sequence = new ActionSequence(touchDevice, 0); sequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, x, y, TimeSpan.Zero)); sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact)); sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact)); session.PerformActions(new List <ActionSequence> { sequence }); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.IsFalse(alarmPivotItem.Selected); Assert.IsTrue(worldClockPivotItem.Selected); // Perform touch click action using viewport coordinate origin to switch from WorldClock to Alarm tab sequence = new ActionSequence(touchDevice, 0); x = alarmPivotItem.Location.X; y = alarmPivotItem.Location.Y; sequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, x, y, TimeSpan.Zero)); sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact)); sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact)); session.PerformActions(new List <ActionSequence> { sequence }); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.IsTrue(alarmPivotItem.Selected); Assert.IsFalse(worldClockPivotItem.Selected); }
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); } } }