SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.85k stars 8.22k forks source link

[🐛 Bug]: GetDevToolsSession in WPF hangs forever #10008

Closed topfunet closed 1 year ago

topfunet commented 3 years ago

What happened?

GetDevToolsSession in WPF Application hangs forever, but same code in Console Application work fine.

How can we reproduce the issue?

MainWindow.xaml:
<Button Content="Just Click" Click="Button_Click"></Button>

MainWindow.xaml.cs:
private void Button_Click(object sender, RoutedEventArgs e)
{
    IWebDriver driver = new ChromeDriver();
    IDevTools devTools = driver as IDevTools;
    DevToolsSession session = devTools.GetDevToolsSession(); //this line never return
    driver.Navigate().GoToUrl("https://bing.com");
    driver.Quit();
}

Relevant log output

no relevant log output and vs2019 hasn't error log

Operating System

windows 10

Selenium version

.net c# 4.0.1

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

chrome 95.0.4638.69

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

ChromeDriver 95.0.4638.5401

Are you using Selenium Grid?

no

github-actions[bot] commented 3 years ago

@topfunet, 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.

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

Thank you!

jensakejohansson commented 2 years ago

I have the same issue, any news on this?

ihor2005 commented 2 years ago

I have the same issue, any news on this?

I have same problem - goes OK only in console app, on Winform - hangs up

michaelhazm1 commented 2 years ago

I'm also using Winforms and ran into this issue. As a workaround for now, creating a new thread and working with Selenium from there seems OK.

alttabs commented 2 years ago

I have the same issue, it keeps loading forever.

Does someone know how to solve it?


            ChromeOptions options = new ChromeOptions();
            options.AddArguments("--start-maximized");
            options.AddArguments("--test-type");

            IWebDriver driver = new ChromeDriver(@"C:\Drivers\", options);
            var devTools = (IDevTools)driver;

            IDevToolsSession session = devTools.GetDevToolsSession();
mniezgoda1 commented 2 years ago

I was also facing the same issue in my project. I don't think that app type is the problem there, the issue is the context within which you are trying to get the session with DevToolsSession session = devTools.GetDevToolsSession();. Let me explain it on my example. Background I have a custom web testing framework which consist of 2 projects - Web tests project [UITests] + Selenium project [Core]. UITests is the place where I store all the tests written with Specflow library, page objects, steps implementation and all stuff related to the System Under Test [SUT]. Core is the main framework shareable between different SUT projects, it contains common logic such as WebDriver configuration and implementation, additional helper methods etc, not related to any particular SUT.

Problem As by following good coding practices, I wanted to put session initialization inside my Core project, so then it can be reusable across other projects. Because of that, I've initially placed the GetDevToolsSession() method call in main class responsible for handling WebDriver. Unfortunately it's a part of the Core project, so I was getting the same issue as described by OP, the code was just freezing without any error.

Solution For me, the solution to that problem was just simply placing GetDevToolsSession() call inside the project I originally use for running the tests, which was UITests project. I assume if all the above examples are related to multi-project solutions, then probably you're trying to call GetDevToolsSession() inside non-executable namespace, so maybe some external library project, which for selenium is a separate context for some reason. Guess this is a bug as I can easily create new driver instance, regardless the namespace or project I'm in.

matinfathi19 commented 2 years ago

do this :

DevToolsSession session; private void Button_Click(object sender, RoutedEventArgs e) { IWebDriver driver = new ChromeDriver(); IDevTools devTools = driver as IDevTools; Task.Run(() => { session = devTools.GetDevToolsSession(); }); driver.Navigate().GoToUrl("https://bing.com"); driver.Quit(); }

maestroant commented 1 year ago

do this :

DevToolsSession session; private void Button_Click(object sender, RoutedEventArgs e) { IWebDriver driver = new ChromeDriver(); IDevTools devTools = driver as IDevTools; Task.Run(() => { session = devTools.GetDevToolsSession(); }); driver.Navigate().GoToUrl("https://bing.com"); driver.Quit(); }

Running on a thread does not solve the problem!

session == null

hheexx commented 1 year ago

Firefox also.

hheexx commented 1 year ago

do this : DevToolsSession session; private void Button_Click(object sender, RoutedEventArgs e) { IWebDriver driver = new ChromeDriver(); IDevTools devTools = driver as IDevTools; Task.Run(() => { session = devTools.GetDevToolsSession(); }); driver.Navigate().GoToUrl("https://bing.com"); driver.Quit(); }

Running on a thread does not solve the problem!

session == null

try to .Wait() on Task.Run

nvborisenko commented 1 year ago

Should be fixed in 4.12, please verify.

nvborisenko commented 1 year ago

Feel free to reopen this issue if it is still an issue.

github-actions[bot] commented 12 months ago

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.