Skip to content

Selenium + DevTools #43

@remote-specialist

Description

@remote-specialist

Hello I am trying to implement video recording for Selenium tests (headless Chrome)
I start Chrome with Selenium and get WebSocketDebuggerUrl from the driver log.
After this, I am trying to create ChromeSession object but it fails with NullReferenceException

I read entire ReadMe - and check sample - but it still not clear for me - should I Rebuild protocol or do smth else?

`var service = ChromeDriverService.CreateDefaultService();
service.LogPath = $"c:\temp\{Guid.NewGuid()}.log";
service.EnableVerboseLogging = true;

                var chromeOptions = new ChromeOptions();
                chromeOptions.AddArguments("headless");
                chromeOptions.AddArguments("window-size=2560,1440");
                chromeOptions.AddArguments("no-sandbox");
                Driver = new ChromeDriver(service, chromeOptions, _timeout);


                var webSocketDebuggerUrl = string.Empty;
                while (string.IsNullOrEmpty(webSocketDebuggerUrl))
                {
                    try
                    {
                        using (var fs = new FileStream(service.LogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            using (StreamReader reader = new StreamReader(fs))
                            {
                                while (!reader.EndOfStream)
                                {
                                    //"webSocketDebuggerUrl": "ws://localhost:59941/devtools/browser/2ccd43e7-e96a-4432-9d0d-bc29e8f13c5b"
                                    var line = reader.ReadLine();
                                    if (line.Contains("webSocketDebuggerUrl"))
                                    {
                                        var split = line.Split(' ');

                                        webSocketDebuggerUrl = split[split.Length - 1].Replace("\"", string.Empty);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                var chrome = Driver as ChromeDriver;
                var parameters = new Dictionary<string, object>
                                     {
                                         { "format", "png" },
                                         { "everyNthFrame", 1 }
                                     };
                chrome.ExecuteChromeCommand("Page.startScreencast", parameters);
                var chromeSessionFactory = new ChromeSessionFactory();
                var chromeSession = chromeSessionFactory.Create(webSocketDebuggerUrl);`

P.S.
Thx for this great repository!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions