示例#1
0
        /// <summary>
        /// Change focus to another window.
        /// </summary>
        /// <param name="name">The name of the window</param>
        /// <param name="timeout"></param>
        public Window SwitchToWindowByName(string name, int timeout = -1)
        {
            var endTime = _session.GetEndTime(timeout);

            while (true)
            {
                try {
                    string handle = WindowContext.ActivateWindow(_session, name);
                    _previousWindow = _currentWindow;
                    foreach (Window win in _cachedWindows)
                    {
                        if (win.Handle == handle)
                        {
                            _currentWindow = win;
                            return(_currentWindow);
                        }
                    }
                    _currentWindow = new Window(_session, this, null);
                    _cachedWindows.Add(_currentWindow);
                    return(_currentWindow);
                } catch (Errors.NoSuchWindowError) { }

                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.NoSuchWindowError(name);
                }

                SysWaiter.Wait();
            }
        }
示例#2
0
        /// <summary>
        /// Change focus to another window.
        /// </summary>
        /// <param name="title">The name of the window</param>
        /// <param name="timeout"></param>
        public Window SwitchToWindowByTitle(string title, int timeout = -1)
        {
            var endTime = _session.GetEndTime(timeout);

            while (true)
            {
                List windows, handles;
                this.ListWindows(out windows, out handles);
                foreach (Window win in windows)
                {
                    if (win.Handle == _currentWindow.Handle)
                    {
                        continue;
                    }
                    WindowContext.ActivateWindow(_session, win.Handle);
                    string winTitle = GetCurrentTitle(_session);
                    if (winTitle == title)
                    {
                        _previousWindow = _currentWindow;
                        _currentWindow  = win;
                        return(win);
                    }
                }

                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.NoSuchWindowError(title);
                }

                SysWaiter.Wait();
            }
        }
示例#3
0
        /// <summary>
        /// Repeatedly call the send function until the predicate function returns true
        /// or until the timeout is reached.
        /// </summary>
        /// <param name="timeout">Timeout in ms</param>
        /// <param name="sendfn">Send function</param>
        /// <param name="predicate">Predicate function</param>
        /// <returns>Result of the send function</returns>
        internal T SendUntil <T>(int timeout, Func <T> sendfn, Func <T, bool> predicate)
        {
            DateTime endTime = GetEndTime(timeout);
            bool     retry   = false;

            while (true)
            {
                T result;
                if (retry)
                {
                    result = (T)SendAgain();
                }
                else
                {
                    retry  = true;
                    result = sendfn();
                }
                if (predicate(result))
                {
                    return(result);
                }
                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.TimeoutError(timeout);
                }
                SysWaiter.Wait();
            }
        }
 private static void On_UnhandledException(object sender, UnhandledExceptionEventArgs ex_arg)
 {
     if (ex_arg.ExceptionObject is ThreadAbortException)
     {
         return;
     }
     //Display the exception message box on another thread
     _thread = new Thread(new ParameterizedThreadStart((ex) =>
                                                       ExceptionDialog.ShowDialog((Exception)ex)
                                                       ));
     _thread.IsBackground = true;
     SysWaiter.Signal();
     _thread.Start(ex_arg.ExceptionObject);
 }
示例#5
0
        /// <summary>
        /// Switch to the next available window
        /// </summary>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public Window SwitchToNextWindow(int timeout = -1)
        {
            DateTime endTime        = _session.GetEndTime(timeout);
            string   currentHandle  = _currentWindow.Handle;
            string   previousHandle = _previousWindow.Handle;

            while (true)
            {
                List windows, handles;
                this.ListWindows(out windows, out handles);
                int count = handles.Count;
                if (count > 1)   // need more than one window
                //search index of the current windows
                {
                    int i = count;
                    while (i-- > 0 && (string)handles[i] != currentHandle)
                    {
                        ;
                    }

                    //search and activate the next window
                    for (int ii = count; ii-- > 0;)
                    {
                        if (++i == count)
                        {
                            i = 0;
                        }
                        var handle = (string)handles[i];
                        if (handle != currentHandle && handle != previousHandle)
                        {
                            return(ActivateWindow((Window)windows[i]));
                        }
                    }
                }

                //handle time out
                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.NoSuchWindowError();
                }

                SysWaiter.Wait();
                handles = (List)_session.SendAgain();
            }
        }
示例#6
0
        public void StartApplication(string firefoxPath, IEnumerable arguments, string profilePath)
        {
            Hashtable env = ProcessExt.GetStdEnvironmentVariables();

            env["TEMP"]                      = _working_dir;
            env["TMP"]                       = _working_dir;
            env["XRE_PROFILE_PATH"]          = profilePath;
            env["MOZ_NO_REMOTE"]             = "1";
            env["MOZ_CRASHREPORTER_DISABLE"] = "1";
            env["NO_EM_RESTART"]             = "1";

            //start the process
            _firefox_process = ProcessExt.Start(firefoxPath, arguments, null, env, false, true);

            //Waits for the port to be listening
            SysWaiter.Wait(200);
            if (!_endpoint.WaitForListening(15000, 100))
            {
                throw new Errors.TimeoutError("Firefox failed to open the listening port {0} within 15s", _endpoint);
            }
        }
示例#7
0
        /// <summary>
        /// Switches focus to the specified frame, by index, name or WebElement.
        /// </summary>
        /// <param name="identifier">The name, id, or WebElement of the frame to switch.</param>
        /// <param name="timeout">Optional timeout in milliseconds</param>
        public void SwitchToFrame(object identifier, int timeout)
        {
            if (identifier == null)
            {
                throw new Errors.ArgumentError("Invalid type for argument identifier");
            }

            var element = identifier as WebElement;

            if (element != null)
            {
                identifier = element.SerializeJson();
            }

            try {
                _session.Send(RequestMethod.POST, "/frame", "id", identifier);
            } catch (Errors.NoSuchFrameError) {
                if (timeout == 0)
                {
                    throw;
                }
                var endTime = _session.GetEndTime(timeout);
                while (true)
                {
                    SysWaiter.Wait();
                    try {
                        _session.SendAgain();
                        break;
                    } catch (Errors.NoSuchFrameError) {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw;
                        }
                    }
                }
            }
        }