Example #1
0
        protected T InvokeReturn <T>(DelegateRet <T> action)
        {
            T result = default(T);

            _error  = null;
            _thread = new System.Threading.Thread((System.Threading.ThreadStart) delegate {
                try {
                    result = action();
                } catch (ThreadAbortException) {
                    return;
                } catch (NotSupportedException) {
                    _error = "Method not supported by the Selenium .Net web driver";
                } catch (System.Exception ex) {
                    _error = ex.GetType().Name + ": " + ex.Message;
                }
            });
            _thread.Start();
            bool succeed = _thread.Join(_timeout + 1000);

            this.CheckCanceled();
            if (!succeed)
            {
                throw new ApplicationException(GetErrorPrefix(action.Method.Name) + "\nTimed out running command after " + _timeout + " milliseconds");
            }
            if (_error != null)
            {
                throw new ApplicationException(GetErrorPrefix(action.Method.Name) + "\n" + _error);
            }
            //if (EndOfCommand != null) EndOfCommand();
            return(result);
        }
Example #2
0
        protected void InvokeAssert <T>(DelegateRet <T> action, object expected, bool match)
        {
            T result = InvokeReturn(action);

            if (match ^ Utils.ObjectEquals(result, expected))
            {
                throw new ApplicationException(
                          string.Format("{0}\nexp{1}<{2}>\ngot=<{3}> ",
                                        GetErrorPrefix(action.Method.Name),
                                        match ? "=" : "!=",
                                        Utils.ToStrings(expected),
                                        Utils.ToStrings(result)
                                        )
                          );
            }
        }
Example #3
0
        protected void InvokeWaitFor <T>(DelegateRet <T> action, T expected, bool match)
        {
            T result = default(T);

            _error  = null;
            _thread = new System.Threading.Thread((System.Threading.ThreadStart) delegate {
                while (!_canceled && (match ^ Utils.ObjectEquals(result, expected)))
                {
                    try {
                        result = action();
                    } catch (ThreadAbortException) {
                        break;
                    } catch (NotSupportedException) {
                        _error = "Method not supported by the Selenium .Net web driver";
                    } catch (System.Exception ex) {
                        _error = ex.GetType().Name + ": " + ex.Message;
                    }
                    Thread.Sleep(100);
                    if (_onwait != null)
                    {
                        _onwait();
                    }
                }
            });
            _thread.Start();
            bool succed = _thread.Join(_timeout + 1000);

            this.CheckCanceled();
            if (!succed || _error != null)
            {
                var sb = new StringBuilder();
                sb.Append(GetErrorPrefix(action.Method.Name));
                if (expected != null)
                {
                    sb.Append(" Expected" + (match ? "=" : "!=") + "<" + expected.ToString() + "> result=<" + string.Format("{0}", result) + ">.");
                }
                if (!succed)
                {
                    sb.Append(" Timed out after " + _timeout + " ms.");
                }
                if (_error != null)
                {
                    sb.Append(_error);
                }
                throw new ApplicationException(sb.ToString());
            }
        }
Example #4
0
        protected String InvokeVerify <T>(DelegateRet <T> action, object expected, bool match)
        {
            T result = InvokeReturn(action);

            if (match ^ Utils.ObjectEquals(result, expected))
            {
                return(string.Format("KO, {0} exp{1}<{2}> got<{3}> ",
                                     GetErrorPrefix(action.Method.Name),
                                     match ? "=" : "!=",
                                     Utils.ToStrings(expected),
                                     Utils.ToStrings(result)
                                     ));
            }
            else
            {
                return("OK");
            }
        }
Example #5
0
        /// <summary>Repeatedly applies this instance's input value to the given function until one of the following</summary>
        /// <param name="function"></param>
        /// <param name="timeoutms"></param>
        /// <returns></returns>
        internal T WaitNotNullOrTrue <T>(DelegateRet <T> function, int timeoutms)
        {
            var endTime = DateTime.Now.AddMilliseconds(timeoutms == -1 ? this._timeout : timeoutms);

            while (true)
            {
                var result = function();
                if (!(result == null || (result is bool && (bool)(object)result == false)))
                {
                    return(result);
                }
                this.CheckCanceled();
                if (DateTime.Now > endTime)
                {
                    throw new TimeoutException("The operation has timed out!");
                }
                Thread.Sleep(25);
                if (_onwait != null)
                {
                    _onwait();
                }
            }
        }