cisco-open-source / qtwebdriver

WebDriver implementation for Qt
https://github.com/cisco-open-source/qtwebdriver/wiki
197 stars 59 forks source link

Call control dialog #36

Closed GHJJOV closed 7 years ago

GHJJOV commented 7 years ago

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?

hekra01 commented 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:

GHJJOV commented 7 years ago

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.

hekra01 commented 7 years ago

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?

GHJJOV commented 7 years ago

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??

hekra01 commented 7 years ago

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();
GHJJOV commented 7 years ago

Yes, same behavior if I start mainwindow.exe manually.

hekra01 commented 7 years ago

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.

hekra01 commented 7 years ago

Fixed in https://github.com/cisco-open-source/qtwebdriver/pull/37, commit https://github.com/cisco-open-source/qtwebdriver/commit/21f67d2c80ea04525440fce11fd08b1b7f56ee32

hekra01 commented 7 years ago

@GHJJOV Please rebuild Qtwebriver with the previous commit to fix your issue

GHJJOV commented 7 years ago

@hekra01 Wow, great job, now it works perfectly. Thank you very much!