0

我正在使用硒进行 ERP 动态 ax 7 的测试自动化。所以我用任务记录器在动态 ax 365 上记录场景,并生成我使用 extentreports 2.41.0 的报告,为此我创建了 BasicReport 类:

  using NUnit.Framework;
 using RelevantCodes.ExtentReports;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
  using System.Threading.Tasks;

 namespace GettingStartedWithLoadTesting
 {
[TestFixture]
public class BasicReport
{
    public ExtentReports extent;
    public ExtentTest test;

    [OneTimeSetUp]
    public void StartReport()
    {
        string pth = 
 System.Reflection.Assembly.GetCallingAssembly().CodeBase;
        string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
        string projectPath = new Uri(actualPath).LocalPath;

        string reportPath = projectPath + "Reports\\MyOwnReport.html";

        extent = new ExtentReports(reportPath, true);

        extent.AddSystemInfo("Host Name", "MININT-F36S5EH")
            .AddSystemInfo("Environment", "QA")
            .AddSystemInfo("User Name", "Mohamed Amine");

        extent.LoadConfig(projectPath + "extent-config.xml");

    }

    [Test]
    public void DemoReportPass()
    {
        test = extent.StartTest("DemoReportPass");
        Assert.IsTrue(true);
        test.Log(LogStatus.Pass, "Assert Pass as condition is True");
    }

    [Test]
    public void DemoReportFail()
    {
        test = extent.StartTest("DemoReportFail");
        Assert.IsTrue(false);
        test.Log(LogStatus.Pass, "Assert Pass as condition is Fail");

    }

    [TearDown]
    public void GetResult()
    {
        var status = TestContext.CurrentContext.Result.Outcome.Status;
        var stackTrace = "<pre>" + 
    TestContext.CurrentContext.Result.StackTrace + "</pre>";
        var errorMessage = TestContext.CurrentContext.Result.Message;

        if (status == NUnit.Framework.Interfaces.TestStatus.Failed)

        {
            test.Log(LogStatus.Fail, stackTrace + errorMessage);
        }
        extent.EndTest(test);
    }

    [OneTimeTearDown]
    public void EndReport()
    {
        extent.Flush();
        extent.Close();
    }


 }
 }

当我运行项目时,这个类被忽略了。然后在我要运行的上面的测试类中,我实例化了该类,但是我不能调用该类中包含的方法

using System;
using GettingStartedWithLoadTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.ObjectModel;
using MS.Dynamics.TestTools.CloudCommonTestUtilities.Authentication;
using MS.Dynamics.TestTools.CloudCommonTestUtilities.Enums;
using Microsoft.Dynamics.TestTools.Dispatcher.Client;
using MS.Dynamics.TestTools.DispatcherProxyLibrary.ApplicationForms;
using MS.Dynamics.Performance.Framework.TaskRecorder;
using MS.Dynamics.TestTools.CloudCommonTestUtilities;
using System.Text;
using System.IO;
using RelevantCodes.ExtentReports;

namespace TatAutomationFramework.Web

{
[TestClass]
public sealed class TestFullScenarioBase
{
    StringBuilder sb;


    /// <summary>
    /// Gets the test context. Use the property for setting test transactions 
  in the performance tests.
    /// </summary>
    public TestContext TestContext
    {
        get;
        set;
    }

    [TestCleanup]
    public void TestCleanup()
    {
        Client.Close();
        Client.Dispose();
        _userContext.Dispose();
    }

    private DispatchedClient Client;
    private UserContext _userContext;
    private TimerProvider timerProvider;
    [TestInitialize​]
    public void TestSetup()
    {



        // For multi-user uncomment following lines
        //if (this.TestContext != null)
        //{
        //   timerProvider = new TimerProvider(this.TestContext);
        //}
        SetupData();
        _userContext = new UserContext(UserManagement.AdminUser);
        // For multi-user testing use this line
        // Client = new DispatchedClientHelper().GetClient();
        Client = DispatchedClient.DefaultInstance;
        Client.ForceEditMode = false;
        Client.Company = WellKnownCompanyID.USMF.ToString();
        Client.Open();
    }

    private ClientContext CreateClientContext()
    {
        if (timerProvider != null)
        {
            return ClientContext.Create(Client, timerProvider.OnBeginTimer, 
 timerProvider.OnEndTimer);
        }

        return ClientContext.Create(Client);
    }

    private PurchTable PurchTableForm;
    private PurchCreateOrder PurchCreateOrderForm;
    private string PurchCreateOrder_PurchTable_OrderAccount;
    private string PurchTable_PurchLine_ItemId;
    private string PurchTable_InventoryDimensionsGrid_InventSiteId;
    private decimal PurchTable_PurchLine_PurchQtyGrid;
    private decimal PurchTable_PurchLine_PurchPriceGrid;
    private PurchEditLines PurchEditLinesForm;
    private string PurchEditLines_PurchParmTable_Num;
    private void SetupData()
    {
        PurchCreateOrder_PurchTable_OrderAccount = "US_TX_008";
        PurchTable_PurchLine_ItemId = "A0002";
        PurchTable_InventoryDimensionsGrid_InventSiteId = "2";
        PurchTable_PurchLine_PurchQtyGrid = 3m;
        PurchTable_PurchLine_PurchPriceGrid = 20m;
        PurchEditLines_PurchParmTable_Num = "3";
    }

    [TestMethod]
    public void TestFullScenario()
    {



        using (var c = this.CreateClientContext())
        {
            using (var c1 = c.Navigate<PurchTable>("purchtablelistpage", 
 Microsoft.Dynamics.TestTools.Dispatcher.MenuItemType.Display))
            {
                PurchTableForm = c1.Form<PurchTable>();
                using (var c2 = c1.Action("SystemDefinedNewButton_Click"))
                {


 Microsoft.Dynamics.TestTools.Dispatcher
.Client.Controls
.CommandButtonControl.Attach(PurchTableForm,"SystemDefinedNewButton")
.Click();
                    using (var c3 = c2.Attach<PurchCreateOrder>())
                    {
                        PurchCreateOrderForm = c3.Form<PurchCreateOrder>();

 PurchCreateOrderForm.PurchTable_OrderAccount
 .SetValue(PurchCreateOrder_PurchTable_OrderAccount);
                        PurchCreateOrderForm.OK.Click();
                    }
                }

                PurchTableForm.LineSpec.MarkActiveRow();

  PurchTableForm.PurchLine_ItemId.SetValue(PurchTable_PurchLine_ItemId);

  PurchTableForm
 .InventoryDimensionsGrid_InventSiteId
 .SetValue(PurchTable_InventoryDimensionsGrid_InventSiteId);
                PurchTableForm.PurchLine_PurchQtyGrid
 .SetValue(PurchTable_PurchLine_PurchQtyGrid);
                PurchTableForm.PurchLine_PurchPriceGrid
  .SetValue(PurchTable_PurchLine_PurchPriceGrid);
                Microsoft.Dynamics.TestTools.Dispatcher.Client
  .Controls.CommandButtonControl
 .Attach(PurchTableForm,"SystemDefinedSaveButton").Click();
                PurchTableForm.Purchase.Activate();
                PurchTableForm.ButtonConfirm.Click();
                PurchTableForm.Receive.Activate();
                using (var c4 = c1.Action("buttonUpdatePackingSlip_Click"))
                {
                    PurchTableForm.ButtonUpdatePackingSlip.Click();
                    using (var c5 = c4.Attach<PurchEditLines>())
                    {
                        PurchEditLinesForm = c5.Form<PurchEditLines>();
                        PurchEditLinesForm.GridParmTable.MarkActiveRow();
                        PurchEditLinesForm.PurchParmTable_Num
  .SetValue(PurchEditLines_PurchParmTable_Num);
                        PurchEditLinesForm.OK.Click();
                    }
                }
            }
        }
    }

    BasicReport BsRep = new BasicReport();

}

}

4

1 回答 1

1

The scenario which you are following is different and can not help you to archive the desired result: Changes which you should need to make,

-You can not invoke TestNG annotation within same class by send time, You have already invoked annotation for TestClass, So TestNG can't invoke it for BasicReport class.

-In order to make it happen, You need to invoke each required Extent Report object into your Test Class. And you need to call Common methods from Base Class by extending it. Dest class : Baseclass

-If you wants to create single report, for all your Test then only define in Basic Report class. Else, You can invoke Report creation before @Test annotation for each single Test. So your creation has been invoked.

-Manage TestNG annotation with TestClass and call methods from BaseReport, You just need to call it by extending it.

Thus, You have to manually call all Base Class method. You cant invoke it by TestNG within your current execution.

于 2018-06-19T11:08:04.737 回答