0

Basically I am trying to automate if a player receives data from OBS.
Besides manual, the best way I can think of how to automate would be to read and confirm that the player is receiving data from OBS. Is it possible?

Is selenium able to read the inspect -> console on the browser?

I am only working with Google Chrome, so no need of a work around on Firefox.

What I've tried so far is:

using FirstTestCase.PageObjectMethods;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Threading;

namespace FirstTestCase
{
    [TestFixture]
    class TestClassLog
    {
        class NUnitTest
        {
            private IWebDriver _driver;
            
            [TestCase(TestName = "test")]
            public void Initialize()
            {
                ChromeOptions options = new ChromeOptions();
                options.SetLoggingPreference(LogType.Browser, LogLevel.All);

                var driver = new ChromeDriver(options);
                driver.Manage().Window.Maximize();
                driver.Url = "test.test";
                var homePage = new HomePage(driver);

                homePage.SignIn().Click();                
                homePage.Email("email");
                homePage.Password("pw");
                homePage.LogIn();
                var logs = driver.Manage().Logs.GetLog(LogType.Browser);
                foreach (var log in logs)
                {
                    Console.WriteLine(log.ToString());
                }
            }
        }
    }
}

The URL is hidden due to privacy policies with my employer.

With this log in script I get an exception on the line:

var logs = driver.Manage().Logs.GetLog(LogType.Browser);  

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Any ideas?

9
  • Try to break the line Manage().Logs.GetLog to one call by line. You may see which call returns null. Commented Jul 14, 2021 at 13:08
  • @JoãoFarias that was a good idea. I split that line in 3 lines the exception happens on GetLog(LogType.Browser).
    – DjNewma
    Commented Jul 14, 2021 at 14:05
  • It means you don't have any logs. Commented Jul 15, 2021 at 10:14
  • @JoãoFarias to confirm, this code get's the console logs in the inspect right? As in when you inspect and see the console entries
    – DjNewma
    Commented Jul 15, 2021 at 10:24
  • A browser Inspect tab may have a different implementation and show logs differently. What you gonna get it's Selenium logs, which probably will be the same, but may be different. Commented Jul 15, 2021 at 10:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.