Get chrome's console log

后端 未结 8 1428
感动是毒
感动是毒 2020-11-28 09:05

I want to build an automation testing, so I have to know the errors that appear in the console of chrome.

there is an option to get the error lines that appear in th

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 09:23

    This is the c# code for logging the brower log from chrome.

    private void CheckLogs()
        {
            List logs = Driver.Manage().Logs.GetLog(LogType.Browser).ToList();
            foreach (LogEntry log in logs)
            {
                Log(log.Message);
            }
        }
    

    here is my code for the actual log:

            public void Log(string value, params object[] values)
        {
            // allow indenting
            if (!String.IsNullOrEmpty(value) && value.Length > 0 && value.Substring(0, 1) != "*")
            {
                value = "      " + value;
            }
    
            // write the log
            Console.WriteLine(String.Format(value, values));
        }
    

提交回复
热议问题