Get chrome's console log

后端 未结 8 1413
感动是毒
感动是毒 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:27

    public void Test_DetectMissingFilesToLoadWebpage()
        {
            try
            {
                List logs = driver.Manage().Logs.GetLog(LogType.Browser).ToList();
                foreach (LogEntry log in logs)
                {
                    while(logs.Count > 0)
                    {
                        String logInfo = log.ToString();
                        if (log.Message.Contains("Failed to load resource: the server responded with a status of 404 (Not Found)"))
                        {
                            Assert.Fail();
                        }
                        else
                        {
                            Assert.Pass();
                        }
                    }
                }
            }
            catch (NoSuchElementException e)
            {
                test.Fail(e.StackTrace);
            }
        }
    

    You could do something like this in C#. It is a complete test case. Then print the console output as String i.e logInfo in your report. For some reason, Log(log.Message) from the solution above this one gave me build errors.So, I replaced it.

提交回复
热议问题