/*// <summary> * /// Initializes a new instance of the <see cref="CommandEnvironment"/> class. * /// </summary> * /// <param name="root">The root control</param> * public CommandEnvironment(IntPtr hwnd) * { * _hwnd = hwnd; * _windowHwnd = hwnd; * * SwitchToWindow(AutomationElement.FromHandle(hwnd)); * //Cache = new ElementCache(hwnd, AutomationElement.FromHandle(hwnd)); * }*/ public CommandEnvironment(string sessionId, Dictionary <string, object> desiredCapabilities) { SessionId = sessionId; _hwnd = new IntPtr(int.Parse(sessionId)); var element = AutomationElement.FromHandle(_hwnd); _desiredCapabilities = desiredCapabilities ?? new Dictionary <string, object>(); SwitchToWindow(_hwnd, element); if (!desiredCapabilities.TryGetValue(OpenQA.Selenium.Remote.CapabilityType.UnexpectedAlertBehavior, out var unexpectedAlertBehavior) || !Enum.TryParse(unexpectedAlertBehavior?.ToString(), true, out _unexpectedAlertBehavior)) { _unexpectedAlertBehavior = UnexpectedAlertBehaviorReaction.DismissAndNotify; } Cache.AddHandler(Behaviors.UnexpectedAlertBehavior.CreateHandler(element, _hwnd, this)); CacheStore.CommandStore.AddOrUpdate(sessionId, this, (k, c) => c); }