コード例 #1
0
ファイル: VSSeleniumTest.cs プロジェクト: NanaShenley/sel
        /// <summary>
        /// Initialises a unit test instance - typically called from TestCleanup, passing in the test context.
        /// </summary>
        public static void Cleanup(TestContext testContext)
        {
            var        placeToExec = TestDefaults.Default.MethodOfExecution;
            IWebDriver driver      = null;

            if (placeToExec.ToLower().Contains("local"))
            {
                gridManager.CloseSeleniumGrid();
            }
            else if (placeToExec.ToLower().Contains("remote"))
            {
                //driver = new RemoteCaps(instance, testContext).RunOnRemoteMachine();
            }
            WebDriverContext context = WebContext.GetThreadLocalContext();

            context.Driver.Quit();
            context.Result.StopWatch();
            Debug.WriteLine("Test {0} completed. {1}", testContext.TestName, context.Result.ToString());
        }
コード例 #2
0
        private void InvokeWithTimeout(TestMethodInstance instance, ITestResult result)
        {
            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;
            var timeOut     = instance.Attr.TimeoutSeconds * 1000;

            var context = WebContext.GetThreadLocalContext();
            var task    = Task.Factory.StartNew(() =>
            {
                WebContext.Set(context);
                TestResultReporter.Set(result);
                instance.Invoke();
            }, token);

            if (!task.Wait(timeOut, token))
            {
                throw new WebDriverTimeoutException("test timed out after " + instance.Attr.TimeoutSeconds + " sec");
            }
        }