/// <summary> /// Creates a chrome driver instance in modile emulation mode /// </summary> /// <param name="height">The height of the screen</param> /// <param name="width">The width of the screen</param> /// <param name="userAgent">The user agent returned by the device</param> /// <param name="pixelRatio">The pixel ratio of the screen</param> /// <param name="touch">(Optional Parameter) Whether touch actions are enabled</param> /// <param name="driverSettings">Settings file for the Driver being instantiated.</param> /// <param name="performanceTimings">Whether to obtain performance timings for the browser.</param> public RatDriver(long height, long width, string userAgent, double pixelRatio, [Optional, DefaultParameterValue(false)] bool touch, [Optional, DefaultParameterValue(null)] ChromeSettings driverSettings, [Optional, DefaultParameterValue(false)] bool performanceTimings) { try { RecordPerformance = performanceTimings; if (performanceTimings) { InitialiseRatWatch(performanceTimings); } string driverType = typeof(TWebDriver).Name; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationStart); } if (typeof(TWebDriver) == typeof(ChromeDriver)) { EstablishDriverSettings(driverType); if (!_runTests) { throw new LiberatorOSException(_browserError); } ChromeDriverControl controller = new ChromeDriverControl(driverSettings); Driver = (TWebDriver)controller.StartMobileDriver(height, width, userAgent, pixelRatio, touch); WindowHandles.Add(Driver.CurrentWindowHandle, Driver.Title); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationEnd); } } else { Console.Out.WriteLine("{0} does not currently allow the loading of profiles.", driverType); Console.Out.WriteLine("Please switch to Chrome if mobile emulation is required"); } if (performanceTimings) { RatTimerCollection.StopTimer(EnumTiming.Instantiation); } } catch (Exception ex) { if (ex.GetType() != typeof(LiberatorOSException)) { Console.Out.WriteLine("An unexpected error has been detected."); } HandleErrors(ex); } }
/// <summary> /// Creates a firefox instance using a profile directory path /// </summary> /// <param name="profileDirectory">The path of the profile directory</param> /// <param name="cleanDirectory">Whether to clean the directory</param> /// <param name="driverSettings">Settings file for the Driver being instantiated.</param> /// <param name="performanceTimings">Whether to obtain performance timings for the browser.</param> public RatDriver(string profileDirectory, bool cleanDirectory, [Optional, DefaultParameterValue(null)] FirefoxSettings driverSettings, [Optional, DefaultParameterValue(false)] bool performanceTimings) { try { RecordPerformance = performanceTimings; if (performanceTimings) { InitialiseRatWatch(performanceTimings); } string driverType = typeof(TWebDriver).Name; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationStart); } if (typeof(TWebDriver) == typeof(FirefoxDriver)) { EstablishDriverSettings(driverType); if (!_runTests) { throw new LiberatorOSException(_browserError); } FirefoxDriverControl controller = new FirefoxDriverControl(driverSettings); Driver = (TWebDriver)controller.StartDriverLoadProfileFromDisk(profileDirectory, cleanDirectory); WindowHandles.Add(Driver.CurrentWindowHandle, Driver.Title); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationEnd); } } else { Console.Out.WriteLine("{0} does not currently allow the loading of profiles.", driverType); Console.Out.WriteLine("Please switch to Firefox if named profile loading is required"); } if (performanceTimings) { RatTimerCollection.StopTimer(EnumTiming.Instantiation); } } catch (Exception ex) { if (ex.GetType() != typeof(LiberatorOSException)) { Console.Out.WriteLine("An unexpected error has been detected."); } HandleErrors(ex); } }
/// <summary> /// Base constructor for RatDriver /// </summary> /// <param name="driverSettings">Settings file for the Driver being instantiated.</param> /// <param name="performanceTimings">Whether to obtain performance timings for the browser.</param> public RatDriver([Optional, DefaultParameterValue(null)] IDriverSettings driverSettings, [Optional, DefaultParameterValue(false)] bool performanceTimings) { try { RecordPerformance = performanceTimings; if (performanceTimings) { InitialiseRatWatch(performanceTimings); } string driverType = typeof(TWebDriver).Name; EstablishDriverSettings(driverType); if (!_runTests) { throw new LiberatorOSException(_browserError); } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationStart); } string type = "Liberator.Driver.BrowserControl." + driverType + "Control"; IBrowserControl controller = (IBrowserControl)Activator.CreateInstance(Type.GetType(type), driverSettings); Driver = (TWebDriver)controller.StartDriver(); if (performanceTimings) { RatTimerCollection.StopTimer(EnumTiming.Instantiation); } WaitForPageToLoad(null); WindowHandles.Add(Driver.CurrentWindowHandle, Driver.Title); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationEnd); } } catch (Exception ex) { if (ex.GetType() != typeof(LiberatorOSException)) { Console.Out.WriteLine("An unexpected error has been detected."); } HandleErrors(ex); } }
/// <summary> /// Opens a new window using the send keys command /// </summary> public void OpenNewView() { try { LastPage = FindElementByTag("body"); Driver.ExecuteJavaScript("window.open();"); Driver.SwitchTo().Window(Driver.WindowHandles.Last()); WindowHandles.Add(Driver.CurrentWindowHandle, Driver.Title); Console.Out.WriteLine("Opened a new view"); } catch (Exception ex) { Console.Out.WriteLine("Unable to open a new window."); HandleErrors(ex); } }
/// <summary> /// Closes the currently selected window /// </summary> public void CloseView() { try { var winHandle = Driver.CurrentWindowHandle; LastPage = FindElementByTag("body"); Driver.Close(); Driver.SwitchTo().Window(WindowHandles.Last().Value); WindowHandles.Remove(winHandle); Console.Out.WriteLine("Closed the selected view"); } catch (Exception ex) { Console.Out.WriteLine("Unable to close the current window."); HandleErrors(ex); } }
/// <summary> /// Close the current window, quitting the browser if it is the last window currently open. /// </summary> public void Close() { // exception conditions var isKey = Capabilities.ContainsKey(MockCapabilities.ThrowOnClose); var isException = isKey && (bool)Capabilities[MockCapabilities.ThrowOnClose]; if (isException) { throw new WebDriverException(); } // exit conditions if (WindowHandles.Count == 0) { return; } // remove current windows var windowHandles = WindowHandles.ToList(); windowHandles.Remove(CurrentWindowHandle); WindowHandles = new ReadOnlyCollection <string>(windowHandles); }
private bool EnumerateWindows(IntPtr hwnd, IntPtr lParam) { var windowInfo = new WindowInfoWithHandle(hwnd); var windowLong = GetWindowLong(hwnd, GWL_STYLE); var windowTitle = windowInfo.WindowTitle; var isVisible = (windowLong & WS_VISIBLE) == WS_VISIBLE; var isOverlappedwindow = (windowLong & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW; var isUwp = (windowLong & WS_UWP) == WS_UWP; //var isMinimized = (windowLong & WS_MINIMIZE) == WS_MINIMIZE; //var isClipchildren = (windowLong & WS_POPUP & WS_CLIPCHILDREN) == (WS_POPUP & WS_CLIPCHILDREN); //DwmGetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE.Cloaked, out var isCloaked, Marshal.SizeOf(typeof(bool))); /* * Biscute.exe は以下の状態なので、WS_OVERLAPPEDWINDOW - WS_SYSMENU なのかも * Window add: ********* : 15c70000 */ //Debug.WriteLine("Window add: " + windowTitle + " : " + windowLong.ToString("x8")); if (!WindowHandles.Contains(windowInfo)) { //if (isVisible && isOverlappedwindow && isClipchildren && !isMinimized && windowTitle != null) //if (isVisible && isOverlappedwindow && !isCloaked && windowTitle != null) if (isVisible && isOverlappedwindow && !isUwp && windowTitle != null) //if (isVisible && isOverlappedwindow && windowTitle != null) { //Debug.WriteLine("Window add: " + windowTitle + " : " + windowLong.ToString("x8")); WindowHandles.Add(windowInfo); OnAddEvent(windowInfo); } } return(true); }
/// <summary> /// Gets all the windows that have the specified class name. /// </summary> /// <param name="className">The class name string.</param> /// <returns>A collection of <see cref="RemoteWindow" />.</returns> public IEnumerable <IWindow> GetWindowsByClassName(string className) { return(WindowHandles .Where(handle => WindowHelper.GetClassName(handle) == className) .Select(handle => new RemoteWindow(_process, handle))); }
/// <summary> /// Gets all the windows that contain the specified title. /// </summary> /// <param name="windowTitle">A part a window title string.</param> /// <returns>A collection of <see cref="RemoteWindow" />.</returns> public IEnumerable <IWindow> GetWindowsByTitleContains(string windowTitle) { return(WindowHandles .Where(handle => WindowHelper.GetWindowText(handle).Contains(windowTitle)) .Select(handle => new RemoteWindow(_process, handle))); }
public IEnumerable <RemoteWindow> GetWindowsByClassName(string className) { return(WindowHandles .Where(handle => WindowHelper.GetClassName(handle).Equals(className, StringComparison.Ordinal)) .Select(handle => new RemoteWindow(m_Process, handle))); }
public IEnumerable <RemoteWindow> GetWindowsByTitle(string windowTitle) { return(WindowHandles .Where(handle => WindowHelper.GetWindowText(handle).Equals(windowTitle, StringComparison.Ordinal)) .Select(handle => new RemoteWindow(m_Process, handle))); }
/// <summary> /// Gets all the windows that have the same specified title. /// </summary> /// <param name="windowTitle">The window title string.</param> /// <returns>A collection of <see cref="ARemoteWindow" />.</returns> public IEnumerable <IAWindow> GetWindowsByTitle(string windowTitle) { return(WindowHandles .Where(handle => AWindowHelper.GetWindowText(handle) == windowTitle) .Select(handle => new ARemoteWindow(_process, handle))); }
public override void HookProcedure(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { var eventName = EventMapConverter.CodeToName((int)eventType); if ((uint)idObject != OBJID_WINDOW) { return; } if (eventName == EventName.UNKNOWN) { return; } var windowInfo = new WindowInfoWithHandle(hwnd); var windowLong = GetWindowLong(hwnd, GWL_STYLE); var windowTitle = windowInfo.WindowTitle; var isVisible = (windowLong & WS_VISIBLE) == WS_VISIBLE; var isOverlappedwindow = (windowLong & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW; var isUwp = (windowLong & WS_UWP) == WS_UWP; if (windowLong == 0) { return; } if ((windowLong & WS_CHILD) == WS_CHILD) { return; } if (!WindowHandles.Contains(windowInfo)) { if (isVisible && isOverlappedwindow && !isUwp && (eventName == EventName.EVENT_OBJECT_SHOW || eventName == EventName.EVENT_OBJECT_NAMECHANGE)) { //Debug.WriteLine("Window created: " + windowTitle + " : " + windowLong.ToString("x8")); WindowHandles.Add(windowInfo); OnAddEvent(windowInfo); OnShowEvent(windowInfo); /* * Debug.WriteLine("---"); * Debug.WriteLine(windowTitle + ":" + is_visible + ":" + eventName + ":" + windowLong); * Debug.WriteLine("WS_VISIBLE = " + ((windowLong & WS_VISIBLE) == WS_VISIBLE)); * Debug.WriteLine("WS_OVERLAPPEDWINDOW = " + ((windowLong & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW)); */ } } else { //Debug.WriteLine( " - " + windowTitle + " : " + eventName + ": " + windowLong.ToString("x8")); if (eventName == EventName.EVENT_OBJECT_DESTROY) { // Window がなくなった //Debug.WriteLine("Window destroyed: " + windowTitle + " : " + windowLong.ToString("x8")); WindowHandles.Remove(windowInfo); OnRemoveEvent(windowInfo); OnDestroyEvent(windowInfo); } else if (eventName == EventName.EVENT_OBJECT_HIDE) { // Window が HIDDEN //Debug.WriteLine("Window hide: " + windowTitle + " : " + windowLong.ToString("x8")); WindowHandles.Remove(windowInfo); OnRemoveEvent(windowInfo); OnHideEvent(windowInfo); } else if (eventName == EventName.EVENT_SYSTEM_MOVESIZESTART) { // Window がマウスでドラッグ開始 //Debug.WriteLine("Window mouse drag start: " + windowTitle + " : " + windowLong.ToString("x8")); MouseDraggingWindowHandle = windowInfo; OnMouseDragStartEvent(windowInfo); } else if (eventName == EventName.EVENT_SYSTEM_MOVESIZEEND) { // Window がマウスでドラッグ終了 if (MouseDraggingWindowHandle.Equals(windowInfo)) { //Debug.WriteLine("Window mouse drag end: " + windowTitle + " : " + windowLong.ToString("x8")); MouseDraggingWindowHandle = null; OnMouseDragEndEvent(windowInfo); } } else if (eventName == EventName.EVENT_OBJECT_LOCATIONCHANGE) { // ショートカットキーだけで場所移動 if (MouseDraggingWindowHandle == null) { //Debug.WriteLine("Window location change: " + windowTitle + " : " + windowLong.ToString("x8")); OnLocationChangeEvent(windowInfo); } } } if (WindowHandles.Contains(windowInfo)) { // Debug.WriteLine(" - " + eventName + " : " + windowTitle); } /* * Debug.WriteLine("----"); * Debug.WriteLine("hWinEventHook:" + hWinEventHook); * Debug.WriteLine("eventType:"+eventName); * Debug.WriteLine("hwnd:" + hwnd); * Debug.WriteLine("title:" + GetCurrentWindowTitle(hwnd)); * Debug.WriteLine("idObject:" + idObject); * Debug.WriteLine("idChild:" + idChild); * Debug.WriteLine("dwEventThread:" + dwEventThread); * Debug.WriteLine("dwmsEventTime:" + dwmsEventTime); */ }