Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium + DevTools #43

Open
remote-specialist opened this issue May 14, 2020 · 0 comments
Open

Selenium + DevTools #43

remote-specialist opened this issue May 14, 2020 · 0 comments

Comments

@remote-specialist
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant