Base class is Report Class and Other two Test classes 1.TelerikOutlook and 2.UnitTest1 I am Extended Report class in to Both Classes but in html Report file only last test report details is displayed
it is Not working properly the Report is Generated but contains only last test class
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 class extends Report class
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();
}
}
}
UnitTest1 extends Report class
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();
}
}
}
Aucun commentaire:
Enregistrer un commentaire