private AutomationState AddState(AutomationType type, string path) { AutomationState state = new AutomationState(type, path); states.Add(state); return(state); }
public void Initialize(AutomationType selectedAutomationType) { SelectedAutomationType = selectedAutomationType; IsInitialized = true; if (selectedAutomationType == AutomationType.UIA2) { _automation = new UIA2Automation(); } else { _automation = new UIA3Automation(); } _rootElement = _automation.GetDesktop(); var desktopViewModel = new ElementViewModel(_rootElement); desktopViewModel.SelectionChanged += DesktopViewModel_SelectionChanged; desktopViewModel.LoadChildren(false); Elements.Add(desktopViewModel); // Initialize TreeWalker _treeWalker = _automation.TreeWalkerFactory.GetControlViewWalker(); // Initialize hover _hoverMode = new HoverMode(_automation); _hoverMode.ElementHovered += ElementHovered; }
private Rectangle GetRect(Bitmap screenshot, AutomationType type) { Bitmap referenceImage = null; try { foreach (AutomationState state in states) { if (state.Type == type) { DisposeBitmap(referenceImage); try { referenceImage = (Bitmap)Bitmap.FromFile(state.Path); Rectangle rect = state.Find(screenshot, referenceImage); if (rect != Rectangle.Empty) { return(rect); } } catch { } } } } finally { DisposeBitmap(referenceImage); } return(Rectangle.Empty); }
public async Task DynamicRoleAdd(string status, [OverrideTypeReader(typeof(AutomationTypeReader))] AutomationType type, IRole role) { if (string.IsNullOrWhiteSpace(status)) { await ReplyAsync(_localization.GetMessage("Dynamic role invalid add status")); return; } var dynamicRole = await _dynamic.Get(Context.Guild.Id, status, type); if (dynamicRole != null) { try { await _dynamic.Save(new DynamicRoleData { RoleId = role.Id, DynamicRoleId = dynamicRole.Id, DynamicRole = dynamicRole }); } catch (DataExistsException e) { await ReplyAsync(_localization.GetMessage("Dynamic role invalid add role")); return; } } else { dynamicRole = new DynamicRole { ServerId = Context.Guild.Id, Type = type, Status = status.ToLower() }; await _dynamic.Save(dynamicRole); await _dynamic.Save(new DynamicRoleData { RoleId = role.Id, DynamicRoleId = dynamicRole.Id, DynamicRole = dynamicRole }); } switch (type) { case AutomationType.Temporary: await ReplyAsync(_localization.GetMessage("Dynamic role add temp", role.Name, dynamicRole.Status)); break; case AutomationType.Permanent: await ReplyAsync(_localization.GetMessage("Dynamic role add perm", role.Name, dynamicRole.Status)); break; } }
public void Initialize(AutomationType selectedAutomationType) { SelectedAutomationType = selectedAutomationType; IsInitialized = true; _automation = selectedAutomationType == AutomationType.UIA2 ? (AutomationBase) new UIA2Automation() : new UIA3Automation(); _rootElement = _automation.GetDesktop(); var desktopViewModel = new ElementViewModel(_rootElement); desktopViewModel.SelectionChanged += DesktopViewModel_SelectionChanged; desktopViewModel.LoadChildren(false); Elements.Add(desktopViewModel); Elements[0].IsExpanded = true; // Initialize TreeWalker _treeWalker = _automation.TreeWalkerFactory.GetControlViewWalker(); // Initialize hover _hoverMode = new HoverMode(_automation); _hoverMode.ElementHovered += ElementToSelectChanged; // Initialize focus tracking _focusTrackingMode = new FocusTrackingMode(_automation); _focusTrackingMode.ElementFocused += ElementToSelectChanged; }
protected UITestBase(AutomationType automationType, TestApplicationType appType) { AutomationType = automationType; ApplicationType = appType; ScreenshotDir = @"c:\FailedTestsScreenshots"; _wasTestRun = false; Automation = AutomationType == AutomationType.UIA2 ? (AutomationBase) new UIA2Automation() : new UIA3Automation(); }
protected UITestBase(AutomationType automationType, TestApplicationType appType) { AutomationType = automationType; ApplicationType = appType; ScreenshotDir = @"c:\FailedTestsScreenshots"; _wasTestRun = false; Automation = TestUtilities.GetAutomation(automationType); }
protected UITestBase(AutomationType automationType, TestApplicationType appType) { AutomationType = automationType; ApplicationType = appType; FailedTestsData = @"c:\FailedTestsData"; _wasTestRun = false; Automation = TestUtilities.GetAutomation(automationType); Logger.Default = new NUnitProgressLogger(); }
/// <summary> /// Get the settings for dynamic channels. /// Will reset corrupted values to default. /// </summary> /// <param name="serverId">The id of the server.</param> /// <param name="type">The type of the dynamic settings.</param> /// <returns>The dynamic channel settings.</returns> public async Task <DynamicChannel> Load(ulong serverId, AutomationType type) { var channels = await _dbDynamic.List(serverId); var settings = channels.FirstOrDefault(x => x.Type == type); if (settings == null) { settings = new DynamicChannel(type) { ServerId = serverId }; await _dbDynamic.Add(settings); return(settings); } var update = false; if (string.IsNullOrWhiteSpace(settings.Prefix)) { switch (type) { case AutomationType.Temporary: settings.Prefix = "➕"; break; case AutomationType.Permanent: settings.Prefix = "👥"; break; } update = true; } if (string.IsNullOrWhiteSpace(settings.Name)) { switch (type) { case AutomationType.Temporary: settings.Name = "--channel"; break; case AutomationType.Permanent: settings.Name = "{0} channel"; break; } update = true; } if (update) { await _dbDynamic.Update(settings); } return(settings); }
private string GetLogsFilePath(string logsDirectory, AutomationType automationType, string projectName) { string logsFilePath = $"{Path.Combine(logsDirectory, automationType.ToString(), projectName + DateTime.Now.ToString("MMddyyyyhhmmss") + ".txt")}"; if (!Directory.Exists(Path.GetDirectoryName(logsFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(logsFilePath)); } return(logsFilePath); }
public Automation GetAutomation(AutomationType type) { for (int i = 0, j = Automations.Count; i < j; i++) { var automation = Automations[i]; if (automation.Type == type) { return(automation); } } return(null); }
public async Task DynamicRoleRemove(string status, [OverrideTypeReader(typeof(AutomationTypeReader))] AutomationType type, IRole role) { if (string.IsNullOrWhiteSpace(status)) { await ReplyAsync(_localization.GetMessage("Dynamic role invalid remove status")); return; } var dynamicRole = await _dynamic.Get(Context.Guild.Id, status, type); if (dynamicRole == null) { await ReplyAsync(_localization.GetMessage("Dynamic role invalid remove amount")); return; } var dynamicData = dynamicRole.Roles.FirstOrDefault(x => x.RoleId == role.Id); if (dynamicData == null) { await ReplyAsync(_localization.GetMessage("Dynamic role invalid remove role", dynamicRole.Status)); return; } try { await _dynamic.Delete(dynamicData); } catch (Exception e) { await _logs.Write("Crashes", "An unhandled exception has occured.", e); await ReplyAsync(_localization.GetMessage("General error")); return; } switch (type) { case AutomationType.Temporary: await ReplyAsync(_localization.GetMessage("Dynamic role remove game role temp", role.Name, status)); break; case AutomationType.Permanent: await ReplyAsync(_localization.GetMessage("Dynamic role remove game role perm", role.Name, status)); break; } }
public Recorder(AutomationType automationType, CodeProviderFactory codeProviderFactory, string codeProviderName, Process targetProcess) { _automation = automationType == AutomationType.UIA2 ? (AutomationBase) new FlaUI.UIA2.UIA2Automation() : new FlaUI.UIA3.UIA3Automation(); _codeProvider = CreateCodeProvider(codeProviderFactory, codeProviderName, targetProcess); State = RecorderState.Paused; // Initialize workers _workers.Add(new HoverWorker(_automation, targetProcess.Id)); var click = new ClickRecognizeWorker(_automation, targetProcess.Id); click.ElementClicked += Click_ElementClicked; click.ElementRightClicked += Click_ElementRightClicked; _workers.Add(click); }
/// <summary> /// Get the ids-holder or create a new one /// </summary> private static IdentifiersHolder GetIdHolder(AutomationType automationType) { // ReSharper disable InconsistentlySynchronizedField This is on purpose to speed this thing up if (!IdentifiersDict.ContainsKey(automationType)) { // Lock to have thread safety lock (((IDictionary)IdentifiersDict).SyncRoot) { // Double check in case someone already added it while aquiring the lock if (!IdentifiersDict.ContainsKey(automationType)) { IdentifiersDict.Add(automationType, new IdentifiersHolder()); } } } return(IdentifiersDict[automationType]); // ReSharper restore InconsistentlySynchronizedField }
public static AutomationType GetUiaVersion(AutomationType defaultIfNonExistent) { if (!TestContext.Parameters.Exists("uia")) { return(defaultIfNonExistent); } var uiaVersion = Convert.ToInt32(TestContext.Parameters["uia"]); switch (uiaVersion) { case 2: return(AutomationType.UIA2); case 3: return(AutomationType.UIA3); default: throw new ArgumentOutOfRangeException("uia", uiaVersion, null); } }
public DynamicChannel(AutomationType type) { switch (type) { case AutomationType.Temporary: Type = type; Prefix = "➕"; Name = "--channel"; break; case AutomationType.Permanent: Type = type; Prefix = "👥"; Name = "{0} channel"; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public static AutomationBase GetAutomation(AutomationType automationType) { if (TestContext.Parameters.Exists("uia")) { var uiaVersion = Convert.ToInt32(TestContext.Parameters["uia"]); if ((automationType == AutomationType.UIA2 && uiaVersion != 2) || (automationType == AutomationType.UIA3 && uiaVersion != 3)) { Assert.Inconclusive($"UIA parameter set to {uiaVersion} but automation of type {automationType} is requested"); } } switch (automationType) { case AutomationType.UIA2: return(new UIA2Automation()); case AutomationType.UIA3: return(new UIA3Automation()); default: throw new ArgumentOutOfRangeException(nameof(automationType), automationType, null); } }
public static AutomationBase GetAutomation(AutomationType automationType) { // Get and validate the version var uiaVersion = GetUiaVersion(automationType); if ((automationType == AutomationType.UIA2 && uiaVersion != AutomationType.UIA2) || (automationType == AutomationType.UIA3 && uiaVersion != AutomationType.UIA3)) { Assert.Inconclusive($"UIA parameter set to {uiaVersion} but automation of type {automationType} is requested"); } switch (automationType) { case AutomationType.UIA2: return(new UIA2Automation()); case AutomationType.UIA3: return(new UIA3Automation()); default: throw new ArgumentOutOfRangeException(nameof(automationType), automationType, null); } }
public async Task DynamicRoleRemove([OverrideTypeReader(typeof(AutomationTypeReader))] AutomationType type) { var roles = await _dynamic.Get(Context.Guild.Id, type : type); if (roles == null || !roles.Any()) { await ReplyAsync(_localization.GetMessage("Dynamic role invalid remove amount")); return; } try { await _dynamic.Delete(roles); } catch (Exception e) { await _logs.Write("Crashes", "An unhandled exception has occured.", e); await ReplyAsync(_localization.GetMessage("General error")); return; } switch (type) { case AutomationType.Temporary: await ReplyAsync(_localization.GetMessage("Dynamic role remove temp")); break; case AutomationType.Permanent: await ReplyAsync(_localization.GetMessage("Dynamic role remove perm")); break; } }
public DataGridViewTests(AutomationType automationType, TestApplicationType appType) : base(automationType, appType) { }
public TextBoxTests(AutomationType automationType, TestApplicationType appType) : base(automationType, appType) { }
public GridTests(AutomationType automationType, TestApplicationType appType) : base(automationType, appType) { }
public RadioButtonTests(AutomationType automationType, TestApplicationType appType) : base(automationType, appType) { }
public WindowInput(ProcessWindow window, AutomationType automationType, List<InputEvent> inputEvents) { Window = window; AutomationType = automationType; InputEvents = inputEvents; }
public static TextAttributeId Find(AutomationType automationType, int id) { return(FindTextAttribute(automationType, id)); }
public WindowTests(AutomationType automationType, TestApplicationType appType) : base(automationType, appType) { }
public static void SimulateInput(AutomationType automationType, ProcessWindow processWindow, string text) { if (automationType == Automation.AutomationType.Foreground) { NativeMethods.AllowSetForegroundWindow(processWindow.ProcessID); NativeMethods.SetForegroundWindow(processWindow.Handle); Thread.Sleep(10); InputSimulator.Keyboard.TextEntry(text); } else { foreach (var keyChar in text) { SimulateInput(automationType, processWindow, keyChar); } } }
public static TextAttributeId Register(AutomationType automationType, int id, string name) { return(RegisterTextAttribute(automationType, id, name)); }
public InvokePatternTests(AutomationType automationType, TestApplicationType appType) : base(automationType, appType) { }
public static void SimulateInput(AutomationType automationType, ProcessWindow processWindow, char keyChar) { var vkKey = ConvertCharToVirtualKey(keyChar); SimulateInput(automationType, processWindow, vkKey, InputType.Keyboard); }
public Automation GetAutomation(AutomationType type) { for (int i = 0, j = Automations.Count; i < j; i++) { var automation = Automations[i]; if (automation.Type == type) { return automation; } } return null; }
public DateTimePickerTests(AutomationType automationType, TestApplicationType appType) : base(automationType, appType) { }
public static PropertyId Find(AutomationType automationType, int id) { return(FindProperty(automationType, id)); }
public static PropertyId Register(AutomationType automationType, int id, string name) { return(RegisterProperty(automationType, id, name)); }
public static void SimulateInput(AutomationType automationType, ProcessWindow processWindow, VirtualKeyCode vkKey, InputType inputType, KeyState keyState = KeyState.Press) { if (automationType == AutomationType.Foreground) { ActivateWindow(processWindow.ProcessID, processWindow.Handle); } if (keyState == KeyState.Press) { SimulateInput(automationType, processWindow, vkKey, inputType, keyState: KeyState.Down); SimulateInput(automationType, processWindow, vkKey, inputType, keyState: KeyState.Up); } else { uint windowMessage = 0; IntPtr lParam = IntPtr.Zero; switch (inputType) { case InputType.Keyboard: { if (keyState == KeyState.Down) { windowMessage = (uint)Enums.WMessages.KEYDOWN; lParam = GetLParam(1, vkKey, 0, 0, 0, 0); } else if (keyState == KeyState.Up) { windowMessage = (uint)Enums.WMessages.KEYUP; lParam = GetLParam(1, vkKey, 0, 0, 1, 1); } break; } case InputType.Mouse: { windowMessage = (uint)(keyState == KeyState.Down ? Enums.WMessages.KEYDOWN : Enums.WMessages.KEYUP); if (keyState == KeyState.Down) { windowMessage = (uint)Enums.WMessages.KEYDOWN; lParam = GetLParam(1, vkKey, 0, 0, 0, 0); } else if (keyState == KeyState.Up) { windowMessage = (uint)Enums.WMessages.KEYUP; lParam = GetLParam(1, vkKey, 0, 0, 1, 1); } break; } } if (automationType == Automation.AutomationType.Background) { var result = NativeMethods.SendMessage(processWindow.Handle, windowMessage, (IntPtr)vkKey, lParam); if (result != IntPtr.Zero) { if (keyState == KeyState.Down) NativeMethods.SendMessage(processWindow.Handle, (uint)Enums.WMessages.CHAR, (IntPtr)vkKey, lParam); } } else { switch (keyState) { case KeyState.Down: { InputSimulator.Keyboard.KeyDown(vkKey); break; } case KeyState.Up: { InputSimulator.Keyboard.KeyUp(vkKey); break; } } } } }