-
Notifications
You must be signed in to change notification settings - Fork 58
Use QtWebDriver to run your application
hekra01 edited this page Jan 14, 2017
·
26 revisions
Then using the prebuilt Webdriver out of the box is enough.
- Start WebDriver
$ ./WebDriver --verbose
- Use Selenium to open the application
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.24.1:9517"), capabilities);
driver.get("http://example.com/example.html");
// or
driver.get("http://example.com/example.qml");
System.out.println("Plain HTML or QML page source:\n" + driver.getPageSource());
There are 2 ways:
- Add the QtWebDriver headers and librairies in the application build environment
- In the application code, include the headers: Headers.h
- Call the
wd_setup(argc, argv)
function with the parameters you want (See ful argument list: Command Line Switches) - Rebuild an run your application, thi swill start QtWebDriver
- Use Selenium to open the application
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.24.1:9517"), capabilities);
System.out.println("Native page source:\n" + driver.getPageSource());
WebElement elt = driver.findElement(By.xpath("//QTextEdit"));
- Example 1: A basic example of an application using QtWebDriver main.cc
- Example 2: Add QtWebDriver support to
Qt-5.5//Src/qtbase/examples/widgets/mainwindows/mainwindow
- mainwindow.pro
--- mainwindowold.pro 2017-01-13 15:02:41.981524867 -0800
+++ mainwindow.pro 2017-01-13 15:06:53.048081230 -0800
@@ -1,6 +1,17 @@
TEMPLATE = app
-QT += widgets
+QT += widgets quick
+INCLUDEPATH += /home/hekra01/qtwebdriver/out/dist/desktop/release/Test
+INCLUDEPATH += /home/hekra01/qtwebdriver/out/dist/desktop/release/h
+LIBS += -L/home/hekra01/qtwebdriver/out/dist/desktop/release/libs
+LIBS += -lchromium_base -lWebDriver_core -lWebDriver_extension_qt_base -lWebDriver_extension_qt_quick -lWebDriver_extension_qt_quick_web -lWebDriver_extension_qt_web
+DEFINES += QT_NO_SAMPLES="1"
- main.cpp
--- mainold.cpp 2017-01-13 15:46:00.327079422 -0800
+++ main.cpp 2017-01-13 15:45:33.663764896 -0800
@@ -32,6 +32,7 @@
****************************************************************************/
#include "mainwindow.h"
+#include "Headers.h"
#include <QApplication>
#include <QPainterPath>
@@ -149,6 +150,7 @@ int main(int argc, char **argv)
{
QApplication app(argc, argv);
QMap<QString, QSize> customSizeHints = parseCustomSizeHints(argc, argv);
+ wd_setup(argc, argv);
MainWindow mainWin(customSizeHints);
Pros:
- Easy to setup
- The application lifecylce is not impacted. It starts as it should, not on request of WebDriver
Cons:
- Need to modify the application code in order to run webdriver. But a such additional code can be flagged for test build only.
- Modify main.cc to register your application:
int wd_samples_setup(webdriver::ViewCreator* widgetCreator,
webdriver::ViewCreator* webCreator,
webdriver::ViewCreator* qmlCreator,
CommandLine &cmd_line)
{
if(widgetCreator != NULL)
{
widgetCreator->RegisterViewClass<MyWidgetClass>("MyWidgetClass");
...
(See Samples.h )
- Rebuild Webdriver and rerun WebDriver
$ ./build.sh
$ out/dist/desktop/release/bin/WebDriver --verbose
- Use Selenium to make WebDriver create you application:
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.24.1:9517"), capabilities);
// This will trigger creation of a MyWidgetClass
wd.get("qtwidget://MyWidgetClass");
System.out.println("Native page source:\n" + driver.getPageSource());
WebElement elt = driver.findElement(By.xpath("//QTextEdit"));
Pros:
- No need to modify the application code
Cons:
- Need to modify the WebDriver build to add the application classes. It must be possible to build the application using the WebDriver build system
- The application lifecylce can be impacted. WebDriver will call the default constructor of the application class, not knowing about any parameters or preconditions.
Also See
- WebDriverJS
- Command Line Switches
- [Hybridity And View Management](Hybridity And View Management)
Home | Build And Run | Releases | Features
Copyright © 1992-2016 Cisco and/or its affiliates