Esempio n. 1
0
        public override TestMethodAttribute GetTestMethodAttribute(TestMethodAttribute testMethodAttribute)
        {
            TestMethodAttribute testMethod;
            ReporterAttribute   reporter;

            reporter = this.GetType().GetCustomAttribute <ReporterAttribute>();

            if (reporter != null)
            {
                if (ReporterManager.Get() != null && ReporterManager.Get().Test != null)
                {
                    // Closing the previous running test
                    TestInfo test = ReporterManager.Get().Test;
                    while (test != null)
                    {
                        test = ReporterManager.Get().TestEnd(test);
                    }
                }
            }

            if (testMethodAttribute is DataTestMethodAttribute)
            {
                testMethod = new DataTestMethodExAttribute(this.DisplayName);
            }
            else if (testMethodAttribute is TestMethodAttribute)
            {
                testMethod = new TestMethodExAttribute(testMethodAttribute.DisplayName, this.DisplayName);
            }
            else
            {
                throw new InternalTestFailureException("TestClassExAttribute supports only test cases with TestMethodAttribute attribute.");
            }

            return(base.GetTestMethodAttribute(testMethod));
        }
Esempio n. 2
0
 public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters)
 {
     ReporterManager.Initialize(TestingFramework.SpecFlow, new GhprSpecFlowTestDataProvider());
     var specFlowHelper = new GhprSpecFlowHelper();
     GhprPluginHelper.Init(specFlowHelper);
     runtimePluginEvents.CustomizeTestThreadDependencies += CustomizeTestThreadDependencies;
 }
 public void OnScenarioEnd()
 {
     lock (Lock)
     {
         var te         = _engine.ScenarioContext?.TestError;
         var testOutput = _outputWriter.GetOutput();
         var fc         = _engine.FeatureContext;
         var sc         = _engine.ScenarioContext;
         var finish     = DateTime.Now;
         _currentTestRun.TestInfo.Finish = finish;
         var testOutputDto = new TestOutputDto
         {
             Output         = testOutput,
             SuiteOutput    = "",
             TestOutputInfo = new SimpleItemInfoDto
             {
                 Date     = finish,
                 ItemName = "Test output"
             }
         };
         _currentTestRun.Output = testOutputDto.TestOutputInfo;
         _currentTestRun        = GhprPluginHelper.TestExecutionEngineHelper.UpdateTestRunOnScenarioEnd(
             _currentTestRun, te, testOutputDto, fc, sc);
         ReporterManager.TestFinished(_currentTestRun, testOutputDto);
         _runner.OnScenarioEnd();
         _outputWriter.Flush();
     }
 }
Esempio n. 4
0
 private void InitializeReporter()
 {
     if (ReporterManager.Get() == null)
     {
         ReporterManager.AttachReporters("", _reporterTypes);
     }
 }
        public void CanCreateWithSettings()
        {
            ReporterManager.TearDown();
            var s = new ReporterSettings
            {
                DefaultSettings = new ProjectSettings
                {
                    RunGuid            = Guid.NewGuid().ToString(),
                    DataServiceFile    = "Ghpr.LocalFileSystem.dll",
                    LoggerFile         = "",
                    OutputPath         = @"\\server\folder",
                    ProjectName        = "cool project",
                    RealTimeGeneration = true,
                    ReportName         = "report name",
                    Retention          = new RetentionSettings
                    {
                        Amount = 3,
                        Till   = DateTime.Now
                    },
                    RunName       = "run name",
                    RunsToDisplay = 7
                }
            };

            ReporterManager.Initialize(s, new MockTestDataProvider());
            Assert.AreEqual(s.DefaultSettings.OutputPath, ReporterManager.OutputPath);
        }
        public override TestResult[] Execute(ITestMethod testMethod)
        {
            TestResult[] results = null;

            if (_testInfo == null)
            {
                //_testInfo = ((ITestClass)Activator.CreateInstance(Type.GetType($"{testMethod.TestClassName},{testMethod.MethodInfo.Module.Assembly.FullName}"))).GetTestInfo($"{testMethod.TestClassName}.{testMethod.TestMethodName}");
                _testInfo = new TestInfo()
                {
                    // testMethod.MethodInfo.DeclaringType.FullName
                    Class = new ClassObject()
                    {
                        FullName = testMethod.TestClassName, Assembly = testMethod.MethodInfo.Module.Name, Description = _classDisplayName
                    },
                    Test = new TestObject()
                    {
                        FullName = $"{testMethod.TestClassName}.{testMethod.TestMethodName}", Description = GetTestDescription(testMethod.MethodInfo), Categories = GetTestCategories(testMethod.MethodInfo)
                    },
                    Iteration = 0,
                    IsChild   = false,
                };
            }

            _testInfo = ReporterManager.Get().AddTest(_testInfo);

            results = base.Execute(testMethod);

            ReporterManager.Get().TestEnd(_testInfo);

            return(results);
        }
Esempio n. 7
0
 public void OnTestRunEnd()
 {
     lock (Lock)
     {
         ReporterManager.RunFinished();
         _engine.OnTestRunEnd();
     }
 }
Esempio n. 8
0
 public void OnTestRunStart()
 {
     lock (Lock)
     {
         ReporterManager.RunStarted();
         _engine.OnTestRunStart();
     }
 }
Esempio n. 9
0
        private void DirectoryExistsFailure(string oFile)
        {
            IReporter             reporter  = ReporterManager.GetReporter();
            ActionReportContainer container = new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed,
                                                                        "The source directory " + Path.GetDirectoryName(oFile) + " does not exist.  It cannot be watched.");

            reporter.AddReport(container);
            this.reporter.AddReport(container);
        }
Esempio n. 10
0
        private void Timer_Tick(object sender, System.Timers.ElapsedEventArgs args)
        {
            JobContainer jContainer  = this.wcontainer.Container;
            string       destination = SharedBO.CalculateDestination(
                jContainer.SourceDirectory, fullpath, jContainer.DestinationDirectory);                // Path.Combine(jContainer.DestinationDirectory, Path.GetFileName(this.fullpath));

            try {
                if (DoneTrying())
                {
                    IReporter reporter = ReporterManager.GetReporter();
                    reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, "Attempted to copy file " + this.RetryCount + " times.", this.fullpath, destination));
                    this.QTimer.Stop();
                    this.OnFinished(EventArgs.Empty);
                }
                else
                {
                    if (!File.Exists(this.fullpath))
                    {
                        if (wcontainer.ChangeType == WatcherChangeTypes.Renamed)
                        {
                            string relativeOldDir = SharedBO.CalculateDestination(
                                wcontainer.OldFullPath,
                                jContainer.SourceDirectory,
                                jContainer.DestinationDirectory);
                            Directory.Move(relativeOldDir, destination);
                        }
                        else
                        {
                            if (!Directory.Exists(destination))
                            {
                                Directory.CreateDirectory(destination);
                            }
                        }

                        this.QTimer.Stop();
                        this.OnFinished(EventArgs.Empty);
                    }
                    else
                    {
                        this.Copier.Copy(this.fullpath, destination, true);
                        this.QTimer.Stop();
                        this.OnFinished(EventArgs.Empty);
                    }
                }
            }
            catch (System.IO.FileNotFoundException) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, "File Not Found", this.fullpath, destination));
                this.QTimer.Stop();
                this.OnFinished(EventArgs.Empty);
            }
            catch (System.Exception ex) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, ex.ToString(), this.fullpath, destination));
                this.RetryCount++;
            }
        }
Esempio n. 11
0
        public TestInfo AddTestNode(TestInfo test)
        {
            string id;
            // Get current timestamp
            DateTime currentTime = DateTime.UtcNow;

            // Getting a new test ID
            //if (_currentTest.Parent == null)
            //{
            //    if(_currentTest.Children.Count == 0)
            //        id = String.Format("{0}_{1}", _testTree.Value.Id, 1.ToString("X4"));
            //    else
            //        id = String.Format("{0}_{1}", _testTree.Value.Id, (_currentTest.Children.Count + 1).ToString("X4"));
            //}
            //else
            //{
            //    id = $"{_currentTest.Parent.Value.Id}_{(_currentTest.Parent.Children.Count + 1).ToString("X4")}";
            //}
            //test.Id = id;
            test.Id = ReporterManager.GenerateTestId();

            // Setting the test start time
            test.SetStartTime(currentTime);
            // The test is a child of the calling test (_testTree.Value)
            test.IsChild = true;
            test.Section = String.Format("{0}/test[@id='{1}']", _testTree.Value.Section, test.Id);

            id = ReporterManager.GenerateStepId();
            // Adding the called test as a step to the paret test
            StepInfo step = new StepInfo()
            {
                Id          = id,                                      // Convert.ToString(_currentTest.Value.Steps.Count + 1),
                Name        = _testTree.Value.GetStepName(),           // Convert.ToString(_currentTest.Value.Steps.Count + 1),
                Outcome     = StepStatusEnum.Done,
                Section     = $"{_testTree.Value.Section}/step[{id}]", // String.Format("{0}/step[{1}]", _testTree.Value.Section, _currentTest.Value.Steps.Count + 1),
                Description = String.Format("Calling Test: {0}", test.Name),
                ExtraInfo   = new List <SerializableKeyValue <string, string> >(new SerializableKeyValue <string, string>[] {
                    new SerializableKeyValue <string, string>("AssociatedTest", test.Id)
                }),
            };

            step.SetStartTime(currentTime);

            _testTree.Value.Steps.Add(step);

            _currentTest.Value.TestEnded -= CurrentTest_OnTestEnded;
            _currentTest.Value.StepAdded -= CurrentTest_OnStepAdded;
            _currentTest = _testTree.AddChild(test);
            _currentTest.Value.StepAdded += CurrentTest_OnStepAdded;
            _currentTest.Value.TestEnded += CurrentTest_OnTestEnded;

            this.Reporters.FindAll(i => i.EventReportingType.Equals(EventReportingTypeEnum.Online)).ForEach(x => x.AddTestNode(_currentTest.Value));

            return(_currentTest.Value);
        }
Esempio n. 12
0
        public void Copy(string original, string copy, bool overwrite)
        {
            FileInfo fiOriginal = new FileInfo(original);

            fiOriginal.CopyTo(copy, overwrite);

            IReporter reporter = ReporterManager.GetReporter();

            reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Succeeded,
                                                         "Copy succeeded", original, copy));
        }
Esempio n. 13
0
        public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters)
        {
            ReporterManager.Initialize(TestingFramework.SpecFlow, new GhprMSTestSpecFlowTestDataProvider());
            ILogger logger = new EmptyLogger();

            ReporterManager.Action(r => { logger = r.Logger; });
            var specFlowHelper = new GhprMSTestSpecFlowHelper(logger);

            GhprPluginHelper.Init(specFlowHelper);
            runtimePluginEvents.CustomizeTestThreadDependencies += CustomizeTestThreadDependencies;
        }
Esempio n. 14
0
 private void Copy(string oFile, string cFile)
 {
     try {
         this.copier.Copy(oFile, cFile, true);
         this.reporter.AddReport(
             new ActionReportContainer(ActionType.Copy, ActionReportResult.Succeeded, "Copy succeeded", oFile, cFile));
     }
     catch (Exception ex) {
         IReporter             reporter  = ReporterManager.GetReporter();
         ActionReportContainer container = new ActionReportContainer(
             ActionType.Copy, ActionReportResult.Failed, ex.ToString(), oFile, cFile);
         reporter.AddReport(container);
         this.reporter.AddReport(container);
     }
 }
Esempio n. 15
0
 public void OnScenarioStart()
 {
     lock (Lock)
     {
         if (GhprPluginHelper.TestExecutionEngineHelper.UpdateTestDataProvider)
         {
             var provider = GhprPluginHelper.TestExecutionEngineHelper.GetTestDataProvider(_currentFeatureInfo,
                                                                                           _engine.ScenarioContext?.ScenarioInfo, _engine.FeatureContext, _engine.ScenarioContext);
             ReporterManager.SetTestDataProvider(provider);
         }
         _runner.OnScenarioStart();
         _currentTestRun = GhprPluginHelper.TestExecutionEngineHelper.GetTestRunOnScenarioStart(_runner, _currentFeatureInfo,
                                                                                                _engine.ScenarioContext?.ScenarioInfo, _engine.FeatureContext, _engine.ScenarioContext);
         ReporterManager.TestStarted(_currentTestRun);
     }
 }
Esempio n. 16
0
 public void OnScenarioEnd()
 {
     lock (Lock)
     {
         var te         = _engine.ScenarioContext?.TestError;
         var testOutput = _outputWriter.GetOutput();
         var fc         = _engine.FeatureContext;
         var sc         = _engine.ScenarioContext;
         _runner.OnScenarioEnd();
         TestOutputDto runOutput;
         _currentTestRun = GhprPluginHelper.TestExecutionEngineHelper.UpdateTestRunOnScenarioEnd(
             _currentTestRun, te, testOutput, fc, sc, out runOutput);
         ReporterManager.TestFinished(_currentTestRun, runOutput);
         _outputWriter.Flush();
     }
 }
Esempio n. 17
0
        public override TestResult[] Execute(ITestMethod testMethod)
        {
            TestResult[]       iterationResults = null;
            DataDrivenTypeEnum dataDrivenType   = DataDrivenTypeEnum.None;

            _testInfo = new TestInfo()
            {
                // testMethod.MethodInfo.DeclaringType.FullName
                Class = new ClassObject()
                {
                    FullName = testMethod.TestClassName, Assembly = testMethod.MethodInfo.Module.Name, Description = _classDisplayName
                },
                Test = new TestObject()
                {
                    FullName = $"{testMethod.TestClassName}.{testMethod.TestMethodName}", Description = GetTestDescription(testMethod.MethodInfo), Categories = GetTestCategories(testMethod.MethodInfo)
                },
                Iteration = 0,
                IsChild   = false,
            };

            if (_rowIndex == 0)
            {
                _testInfo = ReporterManager.Get().AddTest(_testInfo);
                _rowIndex = 0;
                _rows     = GetRows(testMethod.MethodInfo, out dataDrivenType);
            }

            TestInfo childTest = (TestInfo)_testInfo.DeepCopy();

            childTest.Iteration        = ++_rowIndex;
            childTest.IsChild          = true;
            childTest.Test.Description = String.Copy(((DataRowAttribute)_rows[_rowIndex - 1]).DisplayName ?? $"{_testInfo.Test.Description} (Row #{_rowIndex})");

            childTest = ReporterManager.Get().AddTestNode(childTest);

            iterationResults = base.Execute(testMethod);
            results.AddRange(iterationResults);

            _testInfo = ReporterManager.Get().TestEnd(childTest);

            if (_rows.Count == _rowIndex)
            {
                ReporterManager.Get().TestEnd(_testInfo);
            }

            return(iterationResults);
        }
Esempio n. 18
0
        private void Watcher_Event(object sender, FileSystemEventArgs args)
        {
            string         dir        = Path.GetDirectoryName(args.FullPath);
            JobContainer   container  = AcquireJobContainerByDirectory(dir);         // (JobContainer)this.WatcherContainers[dir];
            WriteContainer wcontainer = new WriteContainer(container.SourceDirectory, container);

            try {
                if (WatcherChangeTypes.Deleted != args.ChangeType)
                {
                    this.ProcessFile(args.FullPath, wcontainer);
                }
                //TODO: Give users the option to copy a "delete" action
            }
            catch (Exception ex) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
            }
        }
Esempio n. 19
0
 public void Process()
 {
     ReporterManager.TearDown();
     ReporterManager.Initialize(new MockTestDataProvider());
     ReporterManager.RunStarted();
     ReporterManager.TestStarted(new TestRunDto());
     ReporterManager.TestFinished(new TestRunDto(), new TestOutputDto
     {
         Output         = "test output",
         SuiteOutput    = "suite output",
         TestOutputInfo = new SimpleItemInfoDto
         {
             Date     = DateTime.Now,
             ItemName = "item name"
         }
     });
     ReporterManager.RunFinished();
 }
Esempio n. 20
0
        public void StartListeners()
        {
            if (this.Started)
            {
                return;
            }

            JobsBO jbo = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));

            foreach (JobContainer container in jbo.JContainer.Jobs)
            {
                if (container.SourceDirectory.Length > 0 && container.DestinationDirectory.Length > 0)
                {
                    if (Directory.Exists(container.SourceDirectory) && Directory.Exists(container.DestinationDirectory))
                    {
                        try {
                            FileSystemWatcher watcher = new FileSystemWatcher(container.SourceDirectory);
                            watcher.NotifyFilter          = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName | NotifyFilters.CreationTime;
                            watcher.IncludeSubdirectories = container.WatchSubDirectories;
                            watcher.Created += new FileSystemEventHandler(Watcher_Event);
                            //watcher.Deleted += new FileSystemEventHandler(Watcher_Event);
                            watcher.Renamed            += new RenamedEventHandler(Watcher_Renamed);
                            watcher.Changed            += new FileSystemEventHandler(Watcher_Event);
                            watcher.EnableRaisingEvents = true;
                            lock (this.Watchers) { Watchers.Add(container, watcher); }
                            lock (this.WatcherContainers) { this.WatcherContainers.Add(container.SourceDirectory, container); }
                        }
                        catch (Exception ex) {
                            IReporter reporter = ReporterManager.GetReporter();
                            reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
                        }
                    }
                    else
                    {
                        IReporter reporter = ReporterManager.GetReporter();
                        reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted,
                                                                     "There was an error finding one or more of the two following directories:\n" +
                                                                     container.SourceDirectory + "\n" + container.DestinationDirectory));
                    }
                }
            }
            this.Started = true;
            OnStatusChanged(EventArgs.Empty);
        }
Esempio n. 21
0
        private void Watcher_Renamed(object sender, RenamedEventArgs args)
        {
            string dir = Path.GetDirectoryName(args.FullPath);

            if (WatcherChangeTypes.Renamed == args.ChangeType)
            {
                //at this point the renamed item could be a directory
                try {
                    JobContainer   container  = AcquireJobContainerByDirectory(dir);                  //(JobContainer)this.WatcherContainers[dir];
                    WriteContainer wcontainer = new WriteContainer(container.SourceDirectory, container);
                    wcontainer.ChangeType  = args.ChangeType;
                    wcontainer.OldFullPath = args.OldFullPath;
                    this.ProcessFile(args.FullPath, wcontainer);
                }
                catch (Exception ex) {
                    IReporter reporter = ReporterManager.GetReporter();
                    reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
                }
            }
        }
Esempio n. 22
0
        //public void UpdateIteration(int iterationNum)
        //{
        //    _currentTest.Value.Iteration = iterationNum;
        //}

        #region IReportService interface Implementation
        public TestInfo AddTest(TestInfo test)
        {
            // Getting a new root test ID
            string id = ReporterManager.GenerateTestId();
            // Get current timestamp
            DateTime currentTime = DateTime.UtcNow;

            // Get current datetime
            test.SetStartTime(currentTime);
            test.Id      = id;
            test.Section = String.Format("/report/test[@id='{0}']", id);

            _testTree    = new TreeNode <TestInfo>(test);
            _currentTest = _testTree;
            _currentTest.Value.TestEnded += CurrentTest_OnTestEnded;
            _currentTest.Value.StepAdded += CurrentTest_OnStepAdded;

            this.Reporters.FindAll(i => i.EventReportingType.Equals(EventReportingTypeEnum.Online)).ForEach(x => x.AddTest(test));

            return(_currentTest.Value);
        }
Esempio n. 23
0
        public TestStepHandler(string pathReportXml = "")
        {
            _iReporter      = ReporterManager.GeReporter(pathReportXml);
            _resultTestInfo = new ResultTestInfo
            {
                AttrProject     = "CM",
                AttrOs          = UtilOs.GetOsVersion(),
                AttrLanguage    = System.Globalization.CultureInfo.InstalledUICulture.Name.Replace("-", "_"),
                AttrRegion      = System.Globalization.CultureInfo.InstalledUICulture.Name.Split('-')[1],
                AttrDeviceModel = DefaultContent,
                AttrDeviceName  = DefaultContent,
                AttrVersion     = DefaultContent,
                AttrTotalCases  = 0,
                AttrPasses      = 0,
                AttrFailures    = 0,
                AttrTbds        = 0,
                AttrBlocks      = 0
            };

            //(string project, string os, string language, string region, string time, string deviceModel, string deviceName, string testTotalNumber, string version, string name, string testName
            //, string testName, string testName, string testName, string testName, string testName)
            // _pathReportFile = pathReportXml;
        }
Esempio n. 24
0
 public void OnTestRunEnd()
 {
     _runner.OnTestRunEnd();
     ReporterManager.Action(r => r.CleanUpJob());
     ReporterManager.Action(r => r.TearDown());
 }
Esempio n. 25
0
 public ReportEventArgs(ReporterManager reporter)
 {
     Reporter = reporter;
     Report   = reporter.Report;
 }
Esempio n. 26
0
 public void CanSetTestDataProvider()
 {
     ReporterManager.TearDown();
     ReporterManager.Initialize(new MockTestDataProvider());
     Assert.DoesNotThrow(() => ReporterManager.SetTestDataProvider(new MockTestDataProviderWithException()));
 }
Esempio n. 27
0
 public void CanCreateByFramework(TestingFramework framework, string outputPath)
 {
     ReporterManager.TearDown();
     ReporterManager.Initialize(framework, new MockTestDataProvider());
     Assert.AreEqual(outputPath, ReporterManager.OutputPath);
 }
Esempio n. 28
0
 public void CreationTest()
 {
     ReporterManager.TearDown();
     ReporterManager.Initialize(new MockTestDataProvider());
     Assert.AreEqual("C:\\_GHPReporter_Core_Report", ReporterManager.OutputPath);
 }
Esempio n. 29
0
 public void SaveScreenshot(byte[] screenBytes, string format)
 {
     ReporterManager.SaveScreenshot(screenBytes, format);
 }
Esempio n. 30
0
 public ScenarioEventArgs(ReporterManager reporter)
     : base(reporter)
 {
     Scenario = Reporter.CurrentScenario;
 }