Closed GHJJOV closed 7 years ago
Hi,
Once the dialog appears you must make your selenium test select it explicitely. For this you should use selenium's window handling functions:
Set<String> windowHandles = driver.getWindowHandles();
You can call it before and after opening the dialog
driver.switchTo().window(someWindowHandle);
Same thing to return to your main window. This works exactly the same as it would with web ui/dialogs
Hi,
First of all thank you for your quick response. I know getWindowHandles() and switchTo() functions. Maybe I didn't explain the problem correctly.
After creating the driver:
WebDriver driver = new RemoteWebDriver(new URL("http://IPAddress:9517"), capability);
I perform a click on a menu option that opens a QDialog:
System.out.println("Qdialog is going to be opened");
driver.findElement(By.xpath("//QAction[@text='Add dock widget...']")).click();
System.out.println("This message does not appear unless opened Qdialog is closed manually");
Select windows...
Then the QDialog is opened but test gets stuck and nothing below this line of code is executed, unless the opened QDialog is manually closed. So, I cannot select new window after opening it, that's the problem. Maybe I should change something in Header.h inside mainwindow QT project.
I see. To automate widgets, qtwebdriver converts their child hierarchy or menu actions to xml, and then selenium can be used on them. Since dialogs (input,file etc...) do not use such hierarchy and rather build their own UI, they are often converted to something like this:
<?xml version="1.0" encoding="UTF-8"?>
<QFileDialog name="Open File" elementId="3c51c7e60de05fe60877815135ad3af6" className="QFileDialog"/>
Not many actions can be performed on this from selenium except switchTo(window)
and window.close()
etc.. which would return to your main UI. This is what I reproduced.
However I do not observe the selenium being blocked. (In fact there is no reason for selenium to block, since its not in the same process as the dialog). Any possibility an exception occurs in your test?
No exception occurs in my test.
Here can be found an example of the app, the test and a short video example.
Any clue about why the test gets stuck after opening a dialog??
Just a quick check. Do you observe the same behavior if you dont start mainwindow.exe in the main? Eg: is it the same if you comment the code that starts the process in Test.java and start mainwindow.exe from a separate command prompt?
public static void main(String... args) throws IOException, InterruptedException {
//Process process = new ProcessBuilder(".\\mainwindowApp\\mainwindow.exe").start();
Yes, same behavior if I start mainwindow.exe manually.
The issue is reproduced.
The menu action call dialog.exec
which blocks Qt's main event loop.
Since WD processes selenium requests in Qt's main loop, it appears blocked.
When the dialog is closed, any events sent while it was open are processed.
Note: The previous tests did not reproduced this because they called dialog.show
instead of exec.
Well, that was the explanation. If/how it can be fixed will require further investigation.
@GHJJOV Please rebuild Qtwebriver with the previous commit to fix your issue
@hekra01 Wow, great job, now it works perfectly. Thank you very much!
Hi,
Don't know if I'm missing something. I'm trying to create a little example using QTWebDriver in Windows and Selenium (Java). I followed steps in Add QtWebDriver support to qtbase/examples/widgets/mainwindows/mainwindow section, but I'm having problems with QT/Windows dialogs. Once the dialog appears, Selenium test stops until dialog is closed. How can I interact with Windows/QT dialogs and then return to application main window?