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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰 Bug]: WebDriver throws NullReferenceException when calling StartEventMonitoring with EventFiringWebDriver #10776

Closed
elgatov opened this issue Jun 16, 2022 · 2 comments 路 Fixed by #10819

Comments

@elgatov
Copy link
Contributor

elgatov commented Jun 16, 2022

What happened?

Creating a JavaScriptEngine with an EventFiringWebDriver as parameter will throw a NullReferenceException when calling monitor.StartEventMonitoring();

I believe line 57 in

public JavaScriptEngine(IWebDriver driver)
{
// Use of Lazy<T> means this exception won't be thrown until the user first
// attempts to access the DevTools session, probably on the first call to
// StartEventMonitoring() or in adding scripts to the instance.
this.driver = driver;
this.session = new Lazy<DevToolsSession>(() =>
{
IDevTools devToolsDriver = driver as IDevTools;
if (session == null)
{
throw new WebDriverException("Driver must implement IDevTools to use these features");
}
return devToolsDriver.GetDevToolsSession();
});
}

should be changed to if (devToolsDriver == null) to correctly throw a WebDriverException when trying to use a non-compatible webdriver

How can we reproduce the issue?

using (var driver = new EventFiringWebDriver(new ChromeDriver()))
            {
                IJavaScriptEngine monitor = new JavaScriptEngine(driver);
                await monitor.StartEventMonitoring();
            }

Relevant log output

Message: 
Test method WebDriver.JavascriptEngine.Tests.UnitTest2.TestMethod1 threw exception: 
System.NullReferenceException: Object reference not set to an instance of an object.

  Stack Trace: 
<.ctor>b__0() line 62
Lazy`1.CreateValue()
Lazy`1.LazyInitValue()
Lazy`1.get_Value()
<StartEventMonitoring>d__24.MoveNext() line 116
--- End of stack trace from previous location where exception was thrown ---
TaskAwaiter.ThrowForNonSuccess(Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
TaskAwaiter.GetResult()
<TestMethod1>d__5.MoveNext() line 80
--- End of stack trace from previous location where exception was thrown ---
TaskAwaiter.ThrowForNonSuccess(Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
ThreadOperations.ExecuteWithAbortSafety(Action action)

Operating System

Windows 10

Selenium version

.Net Framework 4.8

What are the browser(s) and version(s) where you see this issue?

Chrome 102

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 102.0.5005.6102

Are you using Selenium Grid?

No response

@github-actions
Copy link

@elgatov, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

elgatov added a commit to elgatov/selenium that referenced this issue Jun 16, 2022
When using a driver like EventFiringWebDriver as a parameter for JavaScriptEngine and trying to use StartEventMonitoring the constructor will throw a NullReferenceException. This is caused by casting the driver to IDevTools using "as" which will return null if the casting failed, and incorrectly checking the field "session" instead of "devToolsDriver" for null value.

fixes SeleniumHQ#10776
elgatov added a commit to elgatov/selenium that referenced this issue Jun 27, 2022
When using a driver like EventFiringWebDriver as a parameter for JavaScriptEngine and trying to use StartEventMonitoring the constructor will throw a NullReferenceException. This is caused by casting the driver to IDevTools using "as" which will return null if the casting failed, and incorrectly checking the field "session" instead of "devToolsDriver" for null value.

fixes SeleniumHQ#10776
elgatov added a commit to elgatov/selenium that referenced this issue Jun 27, 2022
@github-actions
Copy link

github-actions bot commented Aug 5, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants