public void Start(string videoFileName, ISeleniumTest scenario, int fps = 15)
 {
     this.streamingTask = Task.Factory.StartNew(() =>
     {
         this.StartRecordingThread(videoFileName, scenario, fps);
     });
 }
        private void StartRecordingThread(string videoFileName, ISeleniumTest scenario, int fps)
        {
            fileName = videoFileName;

            using (writer = new AviWriter(videoFileName)
            {
                FramesPerSecond = fps,
                EmitIndex1 = true
            })
            {
                stream = writer.AddVideoStream();
                this.ConfigureStream(stream);

                while (!scenario.IsFinished || forceStop)
                {
                    GetScreenshot(buffer);

                    //Thread safety issues
                    lock (locker)
                    {
                        stream.WriteFrame(true, buffer, 0, buffer.Length);
                    }

                }
            }

        }
Exemplo n.º 3
0
 private void RunInAllBrowsersSequential(ISeleniumTest testClass, string testName, Action <IBrowserWrapper> action, IReadOnlyCollection <SkipBrowserAttribute> skipBrowserAttributes)
 {
     foreach (var testConfiguration in testConfigurations)
     {
         RunSingleTest(testClass, testConfiguration, testName, action, skipBrowserAttributes).Wait();
     }
 }
 /// <summary>
 /// Runs the specified testBody in all configured browsers.
 /// </summary>
 public static void RunInAllBrowsers(this ISeleniumTest executor, Action <IBrowserWrapperFluentApi> testBody, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = 0)
 {
     executor.TestSuiteRunner.ServiceFactory.RegisterTransient <IBrowserWrapper, BrowserWrapperFluentApi>();
     executor.TestSuiteRunner.ServiceFactory.RegisterTransient <IElementWrapper, ElementWrapperFluentApi>();
     executor.TestSuiteRunner.ServiceFactory.RegisterTransient <ISeleniumWrapperCollection, ElementWrapperCollection <IElementWrapperFluentApi, IBrowserWrapperFluentApi> >();
     executor.TestSuiteRunner.RunInAllBrowsers(executor, Convert(testBody), callerMemberName, callerFilePath, callerLineNumber);
 }
Exemplo n.º 5
0
 private void RunInAllBrowsersSequential(ISeleniumTest testClass, string testName, Action <IBrowserWrapper> action)
 {
     foreach (var testConfiguration in testConfigurations)
     {
         RunSingleTest(testClass, testConfiguration, testName, action).Wait();
     }
 }
Exemplo n.º 6
0
        public virtual void RunInAllBrowsers(ISeleniumTest testClass, Action <IBrowserWrapper> action, string callerMemberName, string callerFilePath, int callerLineNumber)
        {
            var testName = callerMemberName;

            this.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) {testName}: Entering RunInAllBrowsers from {callerFilePath}:{callerLineNumber}");

            try
            {
                FormatFinalException(() =>
                {
                    if (Configuration.TestRunOptions.RunInParallel)
                    {
                        RunInAllBrowsersParallel(testClass, testName, action);
                    }
                    else
                    {
                        RunInAllBrowsersSequential(testClass, testName, action);
                    }
                });
            }

            finally
            {
                this.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) {testName}: Leaving RunInAllBrowsers");
            }
        }
Exemplo n.º 7
0
 public TestInstance(TestSuiteRunner runner, ISeleniumTest testClass, TestConfiguration testConfiguration,
                     string testName, Action <IBrowserWrapper> testAction)
 {
     this.TestSuiteRunner   = runner;
     this.TestClass         = testClass;
     this.TestConfiguration = testConfiguration;
     this.TestName          = testName;
     this.testAction        = testAction;
 }
        public override void RunInAllBrowsers(ISeleniumTest testClass, Action <IBrowserWrapper> action, string callerMemberName, string callerFilePath,
                                              int callerLineNumber)
        {
            //TODO: make a review
            var context = (TestContextWrapper)TestContextProvider.GetGlobalScopeTestContext();

            context.TestName = callerMemberName;
            context.FullyQualifiedTestClassName = new System.Diagnostics.StackTrace().GetFrames()?.Select(s => s.GetMethod()?
                                                                                                          .ReflectedType?.FullName).FirstOrDefault(s => !s?.Contains(this.GetType()?.Namespace ?? "") ?? false);
            base.RunInAllBrowsers(testClass, action, callerMemberName, callerFilePath, callerLineNumber);
        }
Exemplo n.º 9
0
        private async Task RunSingleTest(ISeleniumTest testClass, TestConfiguration testConfiguration, string testName, Action <IBrowserWrapper> action)
        {
            var testFullName = $"{testName} for {testConfiguration.BaseUrl} in {testConfiguration.Factory.Name}";

            this.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) {testFullName}: Starting test run");
            try
            {
                var instance = new TestInstance(this, testClass, testConfiguration, testFullName, action);
                await instance.RunAsync();
            }
            finally
            {
                this.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) {testFullName}: Finishing test run");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Runs the test specified by action in all browsers specified in seleniumconfig.json
        /// </summary>
        /// <param name="action">Test definition</param>
        /// <param name="callerMemberName">Name of the method that calls this one. Can be provided by attributes.</param>
        /// <param name="callerFilePath">File name of the method that calls this one. Can be provided by attributes.</param>
        /// <param name="callerLineNumber">Line number of the method that calls this one. Can be provided by attributes.</param>
        public virtual void RunInAllBrowsers(ISeleniumTest testClass, Action <IBrowserWrapper> action, string callerMemberName, string callerFilePath, int callerLineNumber)
        {
            Initialize();
            var testName = callerMemberName;

            this.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) {testName}: Entering RunInAllBrowsers from {callerFilePath}:{callerLineNumber}");

            try
            {
                var skipBrowserAttributes = (
                    testClass.GetType().GetMethod(callerMemberName)?.GetCustomAttributes <SkipBrowserAttribute>()
                    ?? SkipBrowserAttribute.TryToRetrieveFromStackTrace())
                                            .ToList();

                FormatFinalException(() =>
                {
                    if (Configuration.TestRunOptions.RunInParallel)
                    {
                        RunInAllBrowsersParallel(testClass, testName, action, skipBrowserAttributes);
                    }
                    else
                    {
                        RunInAllBrowsersSequential(testClass, testName, action, skipBrowserAttributes);
                    }
                });
                Reporter.ReportSuccessfulTest(testName, callerFilePath, callerLineNumber);
            }
            catch (Exception ex)
            {
                Reporter.ReportFailedTest(ex, testName, callerFilePath, callerLineNumber);
                throw;
            }
            finally
            {
                this.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) {testName}: Leaving RunInAllBrowsers");
            }
        }
Exemplo n.º 11
0
        private async Task RunSingleTest(ISeleniumTest testClass, TestConfiguration testConfiguration, string testName, Action <IBrowserWrapper> action, IReadOnlyCollection <SkipBrowserAttribute> skipBrowserAttributes)
        {
            var skipBrowserAttribute = skipBrowserAttributes.FirstOrDefault(a => a.BrowserName == testConfiguration.Factory.Name);

            if (skipBrowserAttribute != null)
            {
                this.LogInfo($"(#{Thread.CurrentThread.ManagedThreadId}) {testName}: Test was skipped for " +
                             $"browser: {skipBrowserAttribute.BrowserName}, Reason: {skipBrowserAttribute.Reason}");
                return;
            }

            var testFullName = $"{testName} for {testConfiguration.BaseUrl} in {testConfiguration.Factory.Name}";

            this.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) {testFullName}: Starting test run");
            try
            {
                var instance = new TestInstance(this, testClass, testConfiguration, testFullName, action);
                await instance.RunAsync();
            }
            finally
            {
                this.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) {testFullName}: Finishing test run");
            }
        }
Exemplo n.º 12
0
 private void RunInAllBrowsersParallel(ISeleniumTest testClass, string testName, Action <IBrowserWrapper> action, IReadOnlyCollection <SkipBrowserAttribute> skipBrowserAttributes)
 {
     Parallel.ForEach(testConfigurations, c => RunSingleTest(testClass, c, testName, action, skipBrowserAttributes).Wait());
 }
Exemplo n.º 13
0
 public static By SelectByDataUi(this ISeleniumTest testBase, string selector)
 => By.CssSelector($"[data-ui='{selector}']");
 /// <summary>
 /// Runs the specified testBody in all configured browsers.
 /// </summary>
 public static void RunInAllBrowsers(this ISeleniumTest executor, Action <BrowserWrapperLambdaApi> testBody, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = 0)
 {
     executor.TestSuiteRunner.RunInAllBrowsers(executor, wrapper => testBody((BrowserWrapperLambdaApi)wrapper), callerMemberName, callerFilePath, callerLineNumber);
 }
Exemplo n.º 15
0
 private void RunInAllBrowsersParallel(ISeleniumTest testClass, string testName, Action <IBrowserWrapper> action)
 {
     Parallel.ForEach(testConfigurations, c => RunSingleTest(testClass, c, testName, action).Wait());
 }