The extent report is only reporting the last test suite that has been run.
I have set up selenium tests with 10 different suits that is run in order. The problem is that the Extent Report is only logging the results of the last suite. I have tried different ways of implementing the report to compile all of the results.
The code structure:
BaseSetUp Class - initialze the driver (OneTimeSetUp, SetUp, TearDown, OnetimeTearDown)
Generalmethod calls - inherits from BaseSetUp
PageObject Page - get all Page Objects
TestSuits - Inherits from General methods.
I have the report in the BaseSetUp class like this:
[OneTimeSetUp]
public void Setup()
{
try
{
extent = new ExtentReports();
var dir = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug", "");
var htmlReporter = new ExtentHtmlReporter(dir + "\\Test_Execution_Reports" + "\\Automation_Report" + ".html");
extent.AddSystemInfo("Environment", "Xylect AT");
extent.AddSystemInfo("User Name", "Lucas");
extent = new ExtentReports();
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 TearDown()
{
try
{
//zip();
//Email();
extent.Flush();
driver.Close();
driver.Quit();
}
catch (Exception e)
{
throw (e);
}
}
Ive seen a couple of methods where the prevous report is added to the "new" created one, but i did not get this to work.
Example of a testcase in one of the testsuites
[TestCase(TestName = "01_LogIn"), Order(1)]
public void LogIn()
{
LogIn();
string loginAssert = HomePage.expLoginName.Text;
Assert.IsTrue(loginAssert.Contains("Hi, " + username + ""), "Login falied");
}
Any ideas on how i should move forward?
Running extent report V4
You just follow this link. I hope it solves your problem.
You must create 3 classes.
BaseFixture.cs
ExtentManager.cs
ExtentTestManager.cs
After that, you can initialize the BaseFixture in every test class.
[TestFixture, Parallelizable(ParallelScope.Fixtures)]
public class MemberLogInOut : BaseFixture
https://github.com/anshooarora/extentreports-csharp/tree/master/ExtentReports/ExtentReports.Tests/Parallel
Related
I have followed instructions found on this site, which was found when I researched Stack Overflow and found this question. However, I can't seem to figure out why my code is hitting the catch block. I have a break at the IInstallationResult line, which the code hits but then goes to the catch, stating 0x80240024 (There are no updates), even though there are certainly updates available and I list them in the text box.
What am I missing here?
using System;
using System.Windows.Forms;
using WUApiLib;
namespace TEST.DetectWindowsUpdate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void GetUpdates(bool downloadUpdates, bool installUpdates)
{
UpdateSession uSession = new UpdateSession();
IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
UpdateCollection updatesToInstall = new UpdateCollection();
UpdateDownloader downloader = uSession.CreateUpdateDownloader();
IUpdateInstaller installer = uSession.CreateUpdateInstaller();
uSearcher.Online = true;
try
{
ISearchResult sResult = uSearcher.Search("IsInstalled=0 And Type='Software'");
lblUpdateCount.Text = sResult.Updates.Count.ToString();
foreach (IUpdate update in sResult.Updates)
{
txtUpdatesList.AppendText("Title: " + update.Title + Environment.NewLine);
txtUpdatesList.AppendText("IsInstalled: " + update.IsInstalled.ToString() + Environment.NewLine);
txtUpdatesList.AppendText("Downloaded: " + update.IsDownloaded.ToString() + Environment.NewLine);
txtUpdatesList.AppendText("IsMandatory: " + update.IsMandatory.ToString() + Environment.NewLine);
txtUpdatesList.AppendText(Environment.NewLine);
if (downloadUpdates)
{
if (update.IsDownloaded == false)
{
do
{
downloader.Updates.Add(update);
downloader.Download();
}
while (update.IsDownloaded == false);
if (update.IsDownloaded == true)
{
updatesToInstall.Add(update);
}
}
else
{
updatesToInstall.Add(update);
}
}
if (installUpdates)
{
installer.Updates = updatesToInstall;
IInstallationResult installationRes = installer.Install();
for (int i = 0; i < updatesToInstall.Count; i++)
{
txtUpdatesList.AppendText("Installing " + updatesToInstall[i].Title + "...");
if (installationRes.GetUpdateResult(i).HResult == 0)
{
txtUpdatesList.AppendText("INSTALL SUCCESS FOR " + updatesToInstall[i].Title);
}
else
{
txtUpdatesList.AppendText("INSTALL FAIL FOR " + updatesToInstall[i].Title);
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message + ": " + ex.HelpLink);
}
}
private void btnGetUpdates_Click(object sender, EventArgs e)
{
base.OnLoad(e);
txtUpdatesList.Clear();
GetUpdates(false, false);
}
private void btnInstallUpdates_Click(object sender, EventArgs e)
{
base.OnLoad(e);
txtUpdatesList.Clear();
GetUpdates(true, true );
}
}
}
Turns out it was an issue with privileges. I ran as administrator and it functioned appropriately.
i am trying to add screenshot to my extent report.
I have applied exception to one of my test methods, and giving screenshot taking in exception.
Then i have called the screenshot function in teardown, so screenshot can show up in case it is failed. All good. but when i run the code that should be failing, it marks it pass due to exception, and in extent report it displays it as pass.How do i make it appear fail in extent report and display the fail screenshot with it?
namespace CreateTeamSpeed
{
class ReportsGenerationClass
{
protected ExtentReports extent;
protected ExtentTest test;
[OneTimeSetUp]
protected void Setup()
{
string path = TestContext.CurrentContext.TestDirectory + "\\";
string fileName = this.GetType().ToString() + "report.html";
var htmlReporter = new ExtentHtmlReporter(path + fileName);
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
}
[SetUp]
public void BeforeTest()
{
test = extent.CreateTest(TestContext.CurrentContext.Test.Name);
}
[TearDown]
public void AfterTest()
{
var status = TestContext.CurrentContext.Result.Outcome.Status;
var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace) ? "" : string.Format("{0}", TestContext.CurrentContext.Result.StackTrace);
Status logstatus;
switch (status)
{
case TestStatus.Failed:
logstatus = Status.Fail;
test.AddScreenCaptureFromPath("screenshot.png");
break;
case TestStatus.Inconclusive:
logstatus = Status.Warning;
break;
case TestStatus.Skipped:
logstatus = Status.Skip;
break;
default:
logstatus = Status.Pass;
break;
}
var mediaModel = MediaEntityBuilder.CreateScreenCaptureFromPath("screenshot.png").Build();
test.Log(logstatus, "Test ended with " + logstatus + stacktrace + mediaModel);
extent.Flush();
}
[Test]
public void Test1()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://www.google.com");
driver.FindElement(By.Name("q")).SendKeys("Test");
driver.FindElement(By.Name("btnK")).SendKeys(Keys.Enter);
driver.Quit();
}
[Test]
public void Test2()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
IWebDriver driver = new ChromeDriver(options);
try{
driver.Navigate().GoToUrl("https://www.google.com");
driver.FindElement(By.Name("qt")).SendKeys("Test");
driver.FindElement(By.Name("btnK")).SendKeys(Keys.Enter);
driver.Quit();
}
catch (Exception ex)
{
((ITakesScreenshot)driver).GetScreenshot().SaveAsFile("screenshot.png", ScreenshotImageFormat.Png);
}
}
}
}'''
If you handle exception, it does not fail test.
To make it fail for external running tools, you can add call of Assert.Fail(); after screenshot.
Trying to add a hostname to a domain group, and I'm getting the exception There is a naming violation.
I've seen several accepted answers covering this exact thing and as far as I know my syntax is correct.
try
{
DirectoryEntry de = new DirectoryEntry("LDAP://aa.bbbbb.com/CN=Group,OU=Application,OU=Groups,OU=US,DC=aa,DC=bbbbb,DC=com");
string hostname = "CN=" + SystemInformation.ComputerName;
DirectoryEntry add = de.Children.Add(hostname, "Computer");
add.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show("Group join failed" + Environment.NewLine + Environment.NewLine + ex.ToString());
}
Any help would be greatly appreciated.
I figured out what the problem was - I needed to pass the Distinguished Name, rather than just the hostname... that should have been obvious, if I had actually read the MSDN doc... Also, de.Children.Add() may be a valid method to accomplish this (it was an accepted answer on SE, for .Net 3.5 IIRC), but I used de.Properties["member"].Add() to accomplish it.
Updated source code for any Googlers out there:
private void DoStuff(object sender, EventArgs e)
{
using (Process addgroup = new Process())
{
string hostname = Environment.MachineName;
AddMemberToGroup("LDAP://aa.bbbbb.com/CN=Group,OU=Application,OU=Group,OU=US,DC=aa,DC=bbbbb,DC=com", hostname);
}
}
private void AddMemberToGroup(string ldapString, string host)
{
try
{
DirectoryEntry de = new DirectoryEntry(ldapString);
string distHost = GetDistinguishedName(host);
if (!String.IsNullOrEmpty(distHost))
{
de.Properties["member"].Add(distHost);
de.CommitChanges();
}
else
{
MessageBox.Show("Distinguished Host Name returned NULL");
}
}
catch(Exception ex)
{
MessageBox.Show("Group join failed" + Environment.NewLine + Environment.NewLine + ex.ToString());
}
}
private string GetDistinguishedName(string compName)
{
try
{
PrincipalContext pContext = new PrincipalContext(ContextType.Domain);
ComputerPrincipal compPrincipal = ComputerPrincipal.FindByIdentity(pContext, compName);
return compPrincipal.DistinguishedName;
}
catch (Exception ex)
{
MessageBox.Show("Failed to get the Distinguished Hostname from Active Directory" + Environment.NewLine + Environment.NewLine + ex.ToString());
return null;
}
}
I want to create a service for Wifi Direct. If I try to add Reference, I don't see core->windows option in VS2013. I have updated the winSDK.
How do I add the Windows.Devices.WifiDirect api ?
you can use
public sealed class WiFiDirectDevice : IDisposable
this is a sample code to handle connections
Windows.Devices.WiFiDirect.WiFiDirectDevice wfdDevice;
private async System.Threading.Tasks.Task<String> Connect(string deviceId)
{
string result = "";
try
{
// No device Id specified.
if (String.IsNullOrEmpty(deviceId)) { return "Please specify a Wi- Fi Direct device Id."; }
// Connect to the selected Wi-Fi Direct device.
wfdDevice = await Windows.Devices.WiFiDirect.WiFiDirectDevice.FromIdAsync(deviceId);
if (wfdDevice == null)
{
result = "Connection to " + deviceId + " failed.";
}
// Register for connection status change notification.
wfdDevice.ConnectionStatusChanged += new TypedEventHandler<Windows.Devices.WiFiDirect.WiFiDirectDevice, object>(OnConnectionChanged);
// Get the EndpointPair information.
var EndpointPairCollection = wfdDevice.GetConnectionEndpointPairs();
if (EndpointPairCollection.Count > 0)
{
var endpointPair = EndpointPairCollection[0];
result = "Local IP address " + endpointPair.LocalHostName.ToString() +
" connected to remote IP address " + endpointPair.RemoteHostName.ToString();
}
else
{
result = "Connection to " + deviceId + " failed.";
}
}
catch (Exception err)
{
// Handle error.
result = "Error occurred: " + err.Message;
}
return result;
}
private void OnConnectionChanged(object sender, object arg)
{
Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus status =
(Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus)arg;
if (status == Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus.Connected)
{
// Connection successful.
}
else
{
// Disconnected.
Disconnect();
}
}
private void Disconnect()
{
if (wfdDevice != null)
{
wfdDevice.Dispose();
}
}
I am trying to add some logging functionality to a service, however I want it to create a new log, copy the old log into the new one and delete the original.
Sudo for ClearLog: if log1 full create log2, delete contents of log1
Please see code below, currently the ClearLog function is not doing what I want.
Can anyone see what I'm doing wrong?
public static void WriteLog(string txt)
{
string fp = _AppPath + #"\Logging";
try
{
File.AppendAllText(fp + #"\Log1.txt", txt);
}
catch (IOException iex)
{
Debug.Print("Error writing log" + iex.ToString());
}
}
private static void ClearLog()
{
string fp = _AppPath + #"\Logging";
try
{
if (!File.Exists(fp + #"\Log1.txt"))
{
WriteErrorLog("");
}
else
{
File.AppendAllText(fp + #"\Log1.txt", fp + #"\Log2.txt");
File.Delete(fp + #"\Log1.txt");
WriteLog("");
}
}
catch (Exception ex)
{
WriteLog("Clear log failed " + ex.ToString());
}
}
Try creating a public static field of the file path, as you're opening the same file twice it seems.
IE: public static string logfp = _AppPath + #"\Logging";
Then rename everything in those two functions logfp.
Improved example (can use paths in both or declared throughout)
private static void ClearLog()
{
string logfp = _AppPath + #"\Logging";
try
{
if (File.Exists(logfp + #"\Log2.txt"))
{
File.Delete(logfp + #"\Log2.txt");
if (File.Exists(logfp + #"\Log1.txt"))
{
File.Copy(logfp + #"\Log1.txt", logfp + #"\Log2.txt");
File.Delete(logfp + #"\Log1.txt");
}
else
{
File.AppendAllText(logfp + #"\Log1.txt", "New Log created: " + DateTime.Now.ToString());//showing you when it was created
}
}
else
{
File.Copy(logfp + #"\Log1.txt", logfp + #"\Log2.txt");
File.Delete(logfp + #"\Log1.txt");
}
}
catch (Exception ex)
{
WriteErrorLog("Clear log failed " + ex.ToString());
}
}