在C#中为多个测试类扩展报告不起作用?

在C#中为多个测试类扩展报告不起作用?,c#,visual-studio,testing,automation,extentreports,C#,Visual Studio,Testing,Automation,Extentreports,基类是Report类和其他两个测试类1.TelerikOutlook和2.UnitTest1 我在两个类中都扩展了报告类,但在html报告文件中只显示最后的测试报告详细信息 它工作不正常。报告已生成,但只包含最后一个测试类 using AventStack.ExtentReports; using AventStack.ExtentReports.Reporter; using NUnit.Framework; using NUnit.Framework.Inte

基类是Report类和其他两个测试类1.TelerikOutlook和2.UnitTest1 我在两个类中都扩展了报告类,但在html报告文件中只显示最后的测试报告详细信息

它工作不正常。报告已生成,但只包含最后一个测试类

    using AventStack.ExtentReports;
    using AventStack.ExtentReports.Reporter;
    using NUnit.Framework;
    using NUnit.Framework.Interfaces;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Outlook
    {
    public class Report
    {

        protected ExtentReports _extent;
        protected ExtentTest _test;

        public Report()
        { }

        [OneTimeSetUp]
        public void BeforeClass()
        {
            try
            {
                //To create report directory and add HTML report into it

                _extent = new ExtentReports();
                var dir = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug", "");
                DirectoryInfo di = Directory.CreateDirectory(dir + "\\Test_Execution_Reports");
                var htmlReporter = new ExtentHtmlReporter(dir + "\\Test_Execution_Reports" + "\\Automation_Report" + ".html");
                _extent.AddSystemInfo("Environment", "Journey of Quality");
                _extent.AddSystemInfo("User Name", "Sanoj");
                _extent.AttachReporter(htmlReporter);
            }
            catch (Exception e)
            {
                throw (e);
            }

        }

        [SetUp]
        public void BeforeTest()
        {
            try
            {
                _test = _extent.CreateTest(TestContext.CurrentContext.Test.Name);
            }
            catch (Exception e)
            {
                throw (e);
            }
        }


        [TearDown]
        public void AfterTest()
        {
            try
            {
                var status = TestContext.CurrentContext.Result.Outcome.Status;
                var stacktrace = "" + TestContext.CurrentContext.Result.StackTrace + "";
                var errorMessage = TestContext.CurrentContext.Result.Message;
                Status logstatus;
                switch (status)
                {
                    case TestStatus.Failed:
                        logstatus = Status.Fail;
                        //  string screenShotPath = Capture(driver, 
      TestContext.CurrentContext.Test.Name);
                        _test.Log(logstatus, "Test ended with " + logstatus + " – " + errorMessage);
                        // _test.Log(logstatus, "Snapshot below: " 
      +_test.AddScreenCaptureFromPath(screenShotPath));
                        break;
                    case TestStatus.Skipped:
                        logstatus = Status.Skip;
                        _test.Log(logstatus, "Test ended with " + logstatus);
                        break;
                    default:
                        logstatus = Status.Pass;
                        _test.Log(logstatus, "Test ended with " + logstatus);
                        break;
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }

        [OneTimeTearDown]
        public void AfterClass()
        {
            try
            {
                _extent.Flush();
            }
            catch (Exception e)
            {
                throw (e);
            }
        }




    }
}
Telerik类扩展了Report类


Test case 1 ->


    using NUnit.Framework;
    using System;
    using System.Threading;
    using System.Windows;
    using System.Windows.Automation;
    using TestStack.White;
    using TestStack.White.Configuration;
    using TestStack.White.InputDevices;
    using TestStack.White.UIItems;
    using TestStack.White.UIItems.Finders;
    using TestStack.White.UIItems.WindowItems;

    namespace Outlook
    {

    [TestFixture]
      public class TelerikOutlook : Report
    {



        [Test]
        public void TestMethod()
        {
          _test =  _extent.CreateTest("TestMethod");

            var outlook_path ="C:\\jUsers\\ajay.b\\AppData\\Local\\Apps\\2.0\\
                            OA613NLD.BW2\\PTQ504M2.OJL\\tele..tion_0ec16cac1aa370e1_0    
                   7e2.0002_8d746ee446d800cb\\TelerikOutlookInspiredApp.EXE";


            // launch the application
            var application = Application.Launch(outlook_path);
            //Thread.Sleep(70000);

            //Application Window
            var window = application.GetWindow("My Application");


            // wait till window visible
            window.WaitTill(delegate () { return window.Visible; });

            var calendarBtn = window.Get(SearchCriteria.ByText("Calendar"));
            Mouse.Instance.Location = calendarBtn.ClickablePoint;
            Mouse.Instance.Click();

            //Calendar window
            var calendar = application.GetWindow("mark@telerikdomain.com - calendar");


            #region Current Month View
            var day = calendar.Get(SearchCriteria.ByText("26"));
            Mouse.Instance.Location = day.ClickablePoint;
            Mouse.Instance.Click();
            #endregion


            #region Create Appointment

            //to enable Create Appointment Button
            Point p = new Point(674, 377);
            Mouse.Instance.Click(p);

            //click on create appointment Buttton
            var appointment = calendar.Get(SearchCriteria.ByText("Create appointment"));
            // var list = calendar.Get(SearchCriteria.ByText("03-02-2020 00:00:00"));
            Mouse.Instance.Location = appointment.ClickablePoint;
            Mouse.Instance.Click();

            //Get Window of Create Appointment
            var appointmentWindows = application.GetWindows();
            Window appointmentWindow = null;
            foreach (var item in appointmentWindows)
            {
                if (item.Name == "Telerik.Windows.Controls.AppointmentDialogViewModel")
                {
                    appointmentWindow = item;
                }
            }
            //appointmentWindow = application.GetWindow("Appointment-Untitled");

            //Subject Input field
            var subject = appointmentWindow.Get<TextBox>( 
           SearchCriteria.ByAutomationId("SubjectTextBox"));
            // CoreAppXmlConfiguration.Instance.BusyTimeout = 20000;
            // subject.ClickAtCenter();
            Mouse.Instance.Location = subject.ClickablePoint;
            Mouse.Instance.Click();
            Thread.Sleep(1000);
            Keyboard.Instance.Enter("Automated Subject of appointment");

            //Description Input field
            var description = appointmentWindow.Get<TextBox> 
         (SearchCriteria.ByAutomationId("DescriptionTextBox"));
            Mouse.Instance.Location = description.ClickablePoint;
            Mouse.Instance.Click();
            Thread.Sleep(1000);
            Keyboard.Instance.Enter("Automated Description of appointment");

            //Start time input
            var startDate = appointmentWindow.Get(SearchCriteria.ByAutomationId("PART_DateTimeInput"));
            Mouse.Instance.Location = startDate.ClickablePoint;
            Mouse.Instance.Click();
            Thread.Sleep(1000);
            Keyboard.Instance.Enter("06-02-2020 00:00");


            //save n close of appointment
            var okBtn = appointmentWindow.Get(SearchCriteria.ByAutomationId("OKButton"));
            Mouse.Instance.Location = okBtn.ClickablePoint;
            Mouse.Instance.Click();
            #endregion

            #region Drag N Drop Element

            //getting appointment element and drop at any date 
            var drag = calendar.Get(SearchCriteria.ByText("abcd : 06-02-2020 00:00:00 - 06-02-2020 
          00:00:00"));
            var drop = calendar.Get(SearchCriteria.ByText("03-02-2020 00:00:00"));
            Point d = drag.ClickablePoint;
            Thread.Sleep(2000);
            application.WaitWhileBusy();
            Thread.Sleep(2000);
            // drag.Click();
            // Mouse.Instance.DragAndDrop(drag,drop);
            // Thread.Sleep(2000);
            Mouse.Instance.Click(d);
            Mouse.LeftDown();
            // Thread.Sleep(2000);
            var stepCount = 30;
            var stepAmount = (float)(drag.ClickablePoint.Y - drop.ClickablePoint.Y) / stepCount;
            for (var i = 0; i < stepCount; i++)
            {
                Mouse.Instance.Location = new Point(Mouse.Instance.Location.X, Mouse.Instance.Location.Y 
        - stepAmount);
                Thread.Sleep(75);
            }
            Thread.Sleep(2000);
            Mouse.LeftUp();
            Thread.Sleep(2000);
            #endregion

            application.Close();


        }

      }
     }


测试用例1->
使用NUnit.Framework;
使用制度;
使用系统线程;
使用System.Windows;
使用System.Windows.Automation;
使用TestStack.White;
使用TestStack.White.Configuration;
使用TestStack.White.InputDevices;
使用TestStack.White.ui项;
使用TestStack.White.UIItems.Finders;
使用TestStack.White.UIItems.WindowItems;
命名空间Outlook
{
[测试夹具]
公共类TelerikOutlook:报告
{
[测试]
公共void TestMethod()
{
_test=_extent.CreateTest(“TestMethod”);
var outlook\u path=“C:\\jUsers\\ajay.b\\AppData\\Local\\Apps\\2.0\\
OA613NLD.BW2\\PTQ504M2.OJL\\tele.tion\u 0ec16cac1aa370e1\u 0
7e2.0002_8d746ee446d800cb\\TelerikOutlookInspiredApp.EXE”;
//启动应用程序
var application=application.Launch(outlook\u路径);
//睡眠(70000);
//应用程序窗口
var window=application.GetWindow(“我的应用程序”);
//等待窗口可见
waitill(委托(){return window.Visible;});
var calendarBtn=window.Get(SearchCriteria.ByText(“日历”);
Mouse.Instance.Location=calendarBtn.ClickablePoint;
Mouse.Instance.Click();
//日历窗口
var calendar=application.GetWindow(“mark@telerikdomain.com-日历);
#区域当月视图
var day=calendar.Get(SearchCriteria.ByText(“26”));
Mouse.Instance.Location=day.ClickablePoint;
Mouse.Instance.Click();
#端区
#区域创建约会
//启用“创建约会”按钮
点p=新点(674377);
鼠标。实例。点击(p);
//单击创建约会按钮
var约会=calendar.Get(SearchCriteria.ByText(“创建约会”);
//var list=calendar.Get(SearchCriteria.ByText(“03-02-2020 00:00:00”);
Mouse.Instance.Location=appointment.ClickablePoint;
Mouse.Instance.Click();
//获取创建约会的窗口
var appointmentWindows=application.GetWindows();
窗口指定窗口=null;
foreach(任命窗口中的变量项)
{
if(item.Name==“Telerik.Windows.Controls.AppointmentDialogViewModel”)
{
任命窗口=项目;
}
}
//appointmentWindow=application.GetWindow(“约会未命名”);
//主题输入字段
var subject=appointmentWindow.Get(
SearchCriteria.ByAutomationId(“主题文本框”);
//CoreAppXmlConfiguration.Instance.BusyTimeout=20000;
//subject.ClickAtCenter();
Mouse.Instance.Location=subject.ClickablePoint;
Mouse.Instance.Click();
睡眠(1000);
键盘.Instance.Enter(“自动预约主题”);
//描述输入字段
var description=appointmentWindow.Get
(SearchCriteria.ByAutomationId(“DescriptionTextBox”);
Mouse.Instance.Location=description.ClickablePoint;
Mouse.Instance.Click();
睡眠(1000);
输入(“约会的自动描述”);
//开始时间输入
var startDate=appointmentWindow.Get(SearchCriteria.ByAutomationId(“PART_DateTimeInput”);
Mouse.Instance.Location=startDate.ClickablePoint;
Mouse.Instance.Click();
睡眠(1000);
键盘。实例。输入(“06-02-2020 00:00”);
//保存并结束约会
var-okBtn=appointmentWindow.Get(SearchCriteria.ByAutomationId(“OKButton”);
Mouse.Instance.Location=okBtn.ClickablePoint;
Mouse.Instance.Click();
#端区
#区域拖放元素
//获取约会元素并在任何日期放弃
var drag=calendar.Get(SearchCriteria.ByText(“abcd:06-02-2020 00:00:00-06-02-2020
00:00:00"));
var drop=calendar.Get(SearchCriteria.ByText(“03-02-2020 00:00:00”);
点d=拖动。可单击点;
《睡眠》(2000年);
application.WaitWhileBusy();
《睡眠》(2000年);
//拖动。单击();
//Mouse.Instance.dragandrop(拖放);
//《睡眠》(2000年);
鼠标。实例。点击(d);
Mouse.LeftDown();
//《睡眠》(2000年);
var阶跃计数=30;
var stepaument=(float)(drag.ClickablePoint.Y-drop.ClickablePoint.Y)/stepCount;
对于(变量i=0;i
UnitTest1扩展了报表类

Testcase 2-

     using System;
    using System.IO;
    using TestStack.White;
    using TestStack.White.UIItems.Finders;
    using TestStack.White.Factory;
    using System.Runtime.InteropServices;
    using Outlook1 = Microsoft.Office.Interop.Outlook;
    using System.Threading;
    using System.Linq;
    using TestStack.White.UIItems;
    using TestStack.White.UIItems.WindowItems;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using AventStack.ExtentReports;
    using AventStack.ExtentReports.Reporter;

    namespace Outlook
    {
     [TestClass]
      public class UnitTest1 : Report
     {




       [TestMethod]
        public void TestMethod12()
        {


        _test = _extent.CreateTest("TestMethod12");
            //var outlookPath = Path.Combine(
            //    Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
            //    @"Microsoft Office\Office16\OUTLOOK.EXE");
            //var application = Application.Launch(outlookPath);
            var outlook_path = "C:\\jProgram Files\\Microsoft Office\\root\\Office16\\OUTLOOK.EXE";

            //verify the path 
            Assert.AreEqual(outlook_path, "C:\\Program Files\\Microsoft 
                          Office\\root\\Office16\\OUTLOOK.EXE");

            // launch the application
            var application = Application.Launch(outlook_path);
            Thread.Sleep(2000);

            //verify the launched application
            Assert.AreEqual(application.Name, "OUTLOOK");

            // var windows1 = application.GetWindows();
            // get explorer window
            var explorer = application.GetWindow("Inbox - ajay.bhosale@afourtech.com - Outlook");
            explorer.DisplayState = DisplayState.Maximized;
            //verify the screen 
            Assert.AreEqual(explorer.Name, "Inbox - ajay.bhosale@afourtech.com - Outlook");

            // click "New E-mail" button to start composing new email
            var newEmailBtn = explorer.Get(SearchCriteria.ByText("New Email"));
            newEmailBtn.Click();
            //verify  "New E-mail" Button is clicked
            Assert.IsTrue(newEmailBtn.Enabled);

            // get composer window
            var composer = application.GetWindow(
            SearchCriteria.ByText("Untitled - Message (HTML) "),
            InitializeOption.NoCache);


            //verify create appointment window
            Assert.AreEqual(composer.Name, "Untitled - Message (HTML) ");

            // fill out "To" field
            var toField = composer.Get<TextBox> 
       (SearchCriteria.ByClassName("RichEdit20WPT").AndByText("To"));
            toField.Enter("ajay.bhosale@afourtech.com");

            //verify input text of "To" field
            Assert.IsTrue(toField.Text.Equals("ajay.bhosale@afourtech.com"));

            // fill out "Subject" field
            var subjectField = composer.Get<TextBox> 
         (SearchCriteria.ByClassName("RichEdit20WPT").AndByText("Subject"));
            subjectField.Enter("Test Automated UI email");

            //verify input text of "Subject" field
            Assert.IsTrue(subjectField.Text.Equals("Test Automated UI email"));

            //var message = composer.Get(SearchCriteria.ByText("Untitled Message"));
            //message.Enter("asdfghjklkjhgfdsasdfghjkkjhgfdssdfghjklkjhgfds");
            //Thread.Sleep(2000);

            //var message = composer.Get(SearchCriteria.ByText("Message"));
            //message.GetType();
            //message.SetValue("Automated appointment message");
            //message.Enter("Automated appointment message");

            //change focus to get Outlook process registered in running object table

            Thread.Sleep(5000);
            var windows = WindowFactory.Desktop.DesktopWindows();
            //Thread.Sleep(20000);
            var desktop = windows.Last().GetElement(SearchCriteria.ByClassName("SysListView32"));
            // Thread.Sleep(15000);
            desktop.SetFocus();


            Thread.Sleep(15000);
            Outlook1.Application outlookCom = Marshal.GetActiveObject("Outlook.Application") as Outlook1.Application;
            var sentMailItem = outlookCom.ActiveInspector().CurrentItem as Outlook1.MailItem;
            var body = sentMailItem.Body;
            //var body = sentMailItem.HTMLBody;
            //var index = body.IndexOf(@"</body", StringComparison.InvariantCultureIgnoreCase);
            //var index1 = body.IndexOf(@"</p", StringComparison.InvariantCultureIgnoreCase);
            var bodydata = "Hi, " + "     " + "\n      This is an Automated Email.  \n" + "Thanks & Regards   \n" + "Afourtech Pvt Ltd.  ";

            //sentMailItem.HTMLBody = body.Insert(bodydata);
            sentMailItem.Body = body.Insert(1, bodydata);

            //click on send button
            var send = composer.Get(SearchCriteria.ByText("Send").AndByClassName("Button"));
            Thread.Sleep(3000);
            send.Click();


            //verify save and close button is clicked
            Assert.IsFalse(send.Visible);

            // give Outlook time to send off the email
            Thread.Sleep(TimeSpan.FromSeconds(5));

            application.WaitWhileBusy();
            explorer.Close();
            application.Close();
        }





    }
}

testcase2-
使用制度;
使用System.IO;
使用TestStack.White;
使用TestStack.White.UIItems.Finders;
使用TestStack.White.Factory;
使用System.Runtime.InteropServices;
使用Outlook1=Microsoft.Office。