Appium won't log the test results (of the UI-tests, executed with adb emulator) to the debug output (Deug.WriteLine).
According to the documentation, get test logs is possible with the following line
ILogs logs = driver.Manage().Logs;
Hower, Appium has different log types:
Browser
Client
Driver
Profiler
Server
I tried every single log type with the following code. But by executing I don't get any result and the test will (where I put the code) fail. Does anyone have a solution for this problem?
ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Browser);
// ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Client);
// ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Driver);
// ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Profiler);
// ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Server);
foreach (var log in logs)
{
Debug.WriteLine("Time: " + log.Timestamp);
Debug.WriteLine("Message: " + log.Message);
Debug.WriteLine("Level: " + log.Level);
}
I just figure out.
Check this article first
relaxed Security AppiumService
Get the log type
IReadOnlyCollection<string> logTypes = driver.Manage().Logs.AvailableLogTypes;
foreach (string logType in logTypes)
{
Console.WriteLine(logType);
//logcat
//bugreport
//server
}
Print logs
public static void PrintLogs(string logType)
{
try
{
ILogs _logs = driver.Manage().Logs;
var browserLogs = _logs.GetLog(logType);
if (browserLogs.Count > 0)
{
foreach (var log in browserLogs)
{
//log the message in a file
Console.WriteLine(log);
}
}
}
catch(Exception e)
{
//There are no log types present
Console.WriteLine(e.ToString());
}
Picture : C# Console Print appium log
In java I am doing it using the following code:
List<LogEntry> logEntries = driver.manage().logs().get("logcat").getAll();
for (LogEntry logEntry : logEntries) {
System.out.println(logEntry);
}
Not sure if this method works for C#. Please give it a try
List<LogEntry> logEntries = _driver.Manage().Logs().Get("logcat").GetAll();
Related
I am using scriptcs.net to host dynamic scripts, and I would like to capture the output from Console.WriteLine() into my log as information, and Console.Error.WriteLine() as errors. Same as the way Octopus Deploy custom script logging.
The reason I would like to capture the Console.WriteLine() output is to make it easy for script writers to log information using a familiar tool.
Here is my script hosting function:
public static dynamic RunScript()
{
var logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
var scriptServicesBuilder = new ScriptServicesBuilder(new ScriptConsole(), logger).
LogLevel(LogLevel.Info).Cache(false).Repl(false).ScriptEngine<RoslynScriptEngine>();
var scriptcs = scriptServicesBuilder.Build();
scriptcs.Executor.Initialize(new[] { "System.Web" }, Enumerable.Empty<IScriptPack>());
scriptcs.Executor.AddReferences(Assembly.GetExecutingAssembly());
var result = scriptcs.Executor.Execute("Hello.csx");
scriptcs.Executor.Terminate();
if (result.CompileExceptionInfo != null)
return new { error = result.CompileExceptionInfo.SourceException.Message };
if (result.ExecuteExceptionInfo != null)
return new { error = result.ExecuteExceptionInfo.SourceException.Message };
return result.ReturnValue;
}
The contents of my Hello.csx file:
Console.WriteLine("This output is lost forever");
So my question is how can I capture the text written to Console.WriteLine() and save it?
I am working on a simple C# Windows Service that listens to the EventLog via the "EntryWrittenEventHandler" handler and watch for logon logoff events and then write them to a DB.
The service was working as expected for a few days and then suddenly I am not seeing anything get written on logon and logoff events. I am seeing the EntryWrittenEventHandler handler be triggered on each new Security EventLog write...but within the EntryWrittenEventArgs class...I am seeing every entry be reported as "Event ID 0" and this message:
"
Message
"The description for Event ID '0' in Source '' cannot be found. The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have permission to access them. The following information is part of the event:"
string
message
"The description for Event ID '0' in Source '' cannot be found. The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have permission to access them. The following information is part of the event:"
string
+ owner
{System.Diagnostics.EventLogInternal}
System.Diagnostics.EventLogInternal
ReplacementStrings
{string[0]} string[]
Source
"" string
+ TimeGenerated
{12/31/1969 7:00:00 PM}
System.DateTime
+ TimeWritten
{12/31/1969 7:00:00 PM}
System.DateTime
UserName
null string"
Not sure whats going on. Opening the EventLog on the server in question...I can see all the entries as expected. The date is also from 1969...which is weird as well.
Here is my code of what is going on so far:
public Audit()
{
CanHandleSessionChangeEvent = true;
//Start the EventLog Watcher
startEventLogWatch();
}
private void startEventLogWatch()
{
EventLog eLog = new EventLog("Security");
eLog.EntryWritten += new EntryWrittenEventHandler(EventLog_OnEntryWritten);
eLog.EnableRaisingEvents = true;
}
private void EventLog_OnEntryWritten(object source, EntryWrittenEventArgs e)
{
try
{
if (e.Entry.InstanceId.ToString() == "4624")
{
EventAudit eventAuditEntry = new EventAudit();
eventAuditEntry = LogonEvent(e);
if (eventAuditEntry.ADUserName != null)
{
WriteDBEntry(eventAuditEntry);
}
}
else if (e.Entry.InstanceId.ToString() == "4647")
{
EventAudit eventAuditEntry = new EventAudit();
eventAuditEntry = LogoffEvent(e);
if (eventAuditEntry.ADUserName != null)
{
WriteDBEntry(eventAuditEntry);
}
}
}
catch (Exception ex)
{
eventLog1.WriteEntry("A general error has occured. The error message is as follows: " + ex.Message.ToString(), EventLogEntryType.Error, 2001);
}
}
I have a simple program designed to send Event Logs when used. I managed to get most of the event logs out of the system, but there are some that throw an Exception (EventLogException : {"The system cannot find the path specified"}).
This program works for every file, except the ones with a "%4" in their names (example : Microsoft-Windows-Wired-AutoConfig%4Operational.evtx)
The code is the following :
EventLogSession Session = new EventLogSession();
Console.WriteLine("Collecting Info started %4");
Console.WriteLine("Creating Temp Folder");
Directory.CreateDirectory(Environment.CurrentDirectory + "\\Temp");
Console.WriteLine("Acquiring System logs");
foreach (string #item in Session.GetLogNames())
{
try
{
Session.ExportLogAndMessages(#item, PathType.LogName, "*", Environment.CurrentDirectory + "\\Temp\\" + #item + ".evtx");
}
catch(EventLogException EvLgEx)
{
{ }
}
}
Console.WriteLine("Done aquiring logs");
Any help is greatly appreciated.
I have an application which (among other things) needs to call the New-MailContact cmdlet and create contacts in Active Directory. I have followed a handful of tech articles to get as far as I have, but it is still not working.
I have verified my service account being used has the proper authentication based on this TechNet page. I am able to find and invoke the cmdlet from powershell, and I recieve no errors.
However, after running I inspect my OU and my contact was not created. I found this KB article which I think may be suspect, but since the cmdlet doesn't return any errors after the invoke, I can't be sure that this will solve my problem.
Here is a snippet of what I am doing:
public bool CreateMailContactObject(ADExchangeContact adExchangeContacts)
{
Collection<PSObject> results;
Pipeline pipeLine = null;
try
{
var runspaceConfiguration = RunspaceConfiguration.Create();
PSSnapInException snapInException;
var snapInInfo = runspaceConfiguration.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);
using (var runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
{
var newMailBoxContact = new Command("New-MailContact");
newMailBoxContact.Parameters.Add("Name", adExchangeContacts.DisplayName);
newMailBoxContact.Parameters.Add("ExternalEmailAddress", adExchangeContacts.ExternalEmailAddress);
newMailBoxContact.Parameters.Add("OrganizationalUnit", adExchangeContacts.OrganizationalUnit);
newMailBoxContact.Parameters.Add("Alias", adExchangeContacts.Alias);
runspace.Open();
pipeLine = runspace.CreatePipeline();
pipeLine.Commands.Add(newMailBoxContact);
results = pipeLine.Invoke();
_log.DebugFormat("results.Count = {0}", results.Count);
results.ForEach(x => x.Properties.ForEach(y => _log.DebugFormat("{0}: {1}", y.Name, y.Value)));
pipeLine.Stop();
runspace.Close();
}
return true;
}
catch (Exception ex)
{
// Add log statement
_log.ErrorFormat("Creation of Mail Contact in AD Failed. Error: {0}", ex);
return false;
}
}
I do not get any exceptions, and my result list is empty from the Pipeline invoke. Is there something I am missing? If the cmdlet fails due to permissions when creating the contact in AD, wouldn't I expect to recieve some sort of error in the result set from pipeLine.Invoke() ??
I am new with running Powershell, so if there is another issue (beyond the KB article) that could be at hand, please let me know.
if (pipeline.Error != null && pipeline.Error.Count > 0)
{
StringBuilder pipelineError = new StringBuilder();
pipelineError.AppendFormat("Error calling Add-MailboxPermission.");
foreach (object item in thisPipeline.Error.ReadToEnd())
{
pipelineError.AppendFormat("{0}\n", item.ToString());
}
ErrorText = ErrorText + "Error: " + pipelineError.ToString() + Environment.NewLine;
}
Please Put this code after pipeline.Invoke() and check if there is any error in there
Update:
I think this is erro with giving right permission to user,some solutions for this:
http://boardreader.com/thread/Microsoft_Exchange_2010_wont_allow_new_M_1w69j__37ad9f8a-cdcf-4d26-9384-00ad1a3d0f91.html
http://blogs.technet.com/b/richardroddy/archive/2010/07/12/exchange-2010-and-the-exchange-trusted-subsystem.aspx
I have this code in my ASP.NET application written in C# that is trying to read the eventlog, but it returns an error.
EventLog aLog = new EventLog();
aLog.Log = "Application";
aLog.MachineName = "."; // Local machine
foreach (EventLogEntry entry in aLog.Entries)
{
if (entry.Source.Equals("tvNZB"))
Label_log.Text += "<p>" + entry.Message;
}
One of the entries it returns is "The description for Event ID '0' in Source 'tvNZB' cannot be found. The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have permission to access them. The following information is part of the event:'Service started successfully.'"
I only want the 'Service started successfully'. Any ideas?
Try this :)
EventLog aLog = new EventLog();
aLog.Log = "Application";
aLog.MachineName = "."; // Local machine
string message = "\'Service started\'";
foreach (EventLogEntry entry in aLog.Entries)
{
if (entry.Source.Equals("tvNZB")
&& entry.EntryType == EventLogEntryType.Information)
{
if (entry.Message.EndsWith(message))
{
Console.Out.WriteLine("> " + entry.Message);
//do stuff
}
}
}
It works on Win XP home. The message might be different on another OS.
Best way: dump entry.Message by System.Diagnostics.Trace.Write and see the exact message.
Hope it works smoothly :)