当前视图不支持使用 Qt WebDriver 和 Selenium 的 Qml 应用程序的此命令
Current view doesn't support this command for Qml application with Qt WebDriver and Selenium
我想用 Qt WebDriver 测试 Qml 应用程序。
我安装了Qt 5.2.1版本和Qt驱动
根据Use QtWebDriver to run your application.
,在它与QtWebDriver集成了一个应用程序之后
main.cc
如下所示:
#define WD_ENABLE_WEB_VIEW 0
#define QT_NO_SAMPLES 1
#include "mainwindow.h"
#include <QApplication>
#include "Headers.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
wd_setup(argc, argv);
w.show();
return a.exec();
}
应用程序看起来像:
当应用程序是运行时,我可以检查Qt驱动程序状态:
{ ~ } » curl localhost:9517/status ~
{"status":0,"value":{"build":{"revision":"WebDriver-cisco-cmt-1.3.0-87-g965f9466de-dirty","time":"Nov 15 2017 17:02:18 PST","version":"1.3.3"},"os":{"arch":"x86","name":"Windows NT","version":"6.2"}}}
为了访问 Qml 元素,我根据这个 post: QML Specifics:
Rectangle {
id: buttonDirect
objectName: "vradio_direct_button"
property string text: "Direct"
...
Text {
id: buttonDirectLabel; text: buttonDirect.text; anchors.centerIn: buttonDirect; color: activePalette.buttonText; font.pixelSize: 24
objectName: "vradio_direct_button"
}
}
驱动配置如下:
@Override
public RemoteWebDriver getDriver() {
RemoteWebDriver remoteWebDriver = null;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("maximize", true);
//specify reuseUI to have WebDriver terminate any previous session and reuse its windows
cap.setCapability("reuseUI", true);
//specify to select the first found window
cap.setCapability("browserStartWindow", "*");
LoggingPreferences logs = new LoggingPreferences();
Level level = Level.ALL;
logs.enable(LogType.DRIVER, level);
logs.enable(LogType.BROWSER, level);
logs.enable(LogType.PERFORMANCE, level);
// specify log level
cap.setCapability(CapabilityType.LOGGING_PREFS, logs);
try {
URL url = new URL("http://localhost:9517");
remoteWebDriver = new RemoteWebDriver(url, cap);
Logger.debug("Native Page Sources:\n" + remoteWebDriver.getPageSource());
} catch (MalformedURLException e) {
e.printStackTrace();
}
return remoteWebDriver;
}
}
但是,当我要执行时:
Object object = Driver.getDefault().executeScript("var v = ObjectNameUtils.findChild('vradio_direct_button'); return v.text;");
Logger.info("Here is JS output:" + object);
我得到了:
org.openqa.selenium.WebDriverException: Script execution failed. Script: var v = ObjectNameUtils.findChild('vradio_direct_button'); return v.text;;
Current view doesnt support this command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.7.0', revision: '2321c73', time: '2017-11-02T22:22:35.584Z'
System info: host: 'LVL1305001', ip: '172.22.73.100', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptSslCerts: false, applicationCacheEnabled: true, browserConnectionEnabled: true, browserName: QtWebkit, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hybrid: {qml2: true, qtVersion: 5.2.1, widget: true}, javascriptEnabled: true, locationContextEnabled: false, nativeEvents: true, platform: XP, platformName: XP, remotePlayerEnabled: true, reuseUI: true, rotatable: false, takesElementScreenshot: true, takesScreenshot: true, webStorageEnabled: true}
Session ID: bfa073ee2e334f4977281996f3240b90
本机页面源看起来:
<?xml version="1.0" encoding="UTF-8"?>
<MainWindow elementId="2312dc5007f290f9bf4f3f92d3aa6884" className="MainWindow">
<QRubberBand id="qt_rubberband" elementId="45050a91d64ad4cde3e3df8091813f54" className="QRubberBand"/>
<QDeclarativeView elementId="3c4890eed00091c95bde9a653f59d22e" className="QDeclarativeView">
<QWidget id="qt_scrollarea_hcontainer" elementId="ff075abbbeb5fe23501c7da3241def96" className="QWidget">
<QScrollBar elementId="51188e66ef541bc0563bea5780cf8ed2" className="QScrollBar"/>
</QWidget>
<QWidget id="qt_scrollarea_vcontainer" elementId="3692bfb1340019907b7982f1ef2f821f" className="QWidget">
<QScrollBar elementId="e76434466faf78d008ca5b096719e188" className="QScrollBar"/>
</QWidget>
<QWidget elementId="ac4c1e620945ad4784fbbcd3c60ae3f1" className="QWidget"/>
</QDeclarativeView>
</MainWindow>
更新:
我在做这个 post 之前读过这个 post。但是,我没有得到完整的想法。
我知道我必须直接连接到我的 QDeclarativeView
,因此,我必须指定它具有 QtDriver 的功能:
cap.setCapability("browserClass", "MyWebView");
此外,我必须在服务器端设置它:
int main(int argc, char *argv[])
{
//Configure web support
webdriver::ViewCreator* webCreator = new webdriver::QWebViewCreator();
//Register custom web view subclass
webCreator->RegisterViewClass<QDeclarativeView>("MyWebView");
我说得对吗?或者在让它发挥作用的过程中缺少了什么?
如何解决这个错误并点击按钮?
cap.setCapability("browserStartWindow", "*");
将使 QtWebdriver select 成为它找到的第一个 window。
在您的情况下,从本机源代码来看,它将是 MainWindow,它是一个不支持 JS 的 QWidget,因此会出现错误消息。
你需要 select 显式 QDeclarativeview。
这个link:https://github.com/cisco-open-source/qtwebdriver/wiki/Hybridity-And-View-Management
提供了有关如何执行此操作的更多详细信息以及代码示例
我想用 Qt WebDriver 测试 Qml 应用程序。
我安装了Qt 5.2.1版本和Qt驱动
根据Use QtWebDriver to run your application.
main.cc
如下所示:
#define WD_ENABLE_WEB_VIEW 0
#define QT_NO_SAMPLES 1
#include "mainwindow.h"
#include <QApplication>
#include "Headers.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
wd_setup(argc, argv);
w.show();
return a.exec();
}
应用程序看起来像:
当应用程序是运行时,我可以检查Qt驱动程序状态:
{ ~ } » curl localhost:9517/status ~
{"status":0,"value":{"build":{"revision":"WebDriver-cisco-cmt-1.3.0-87-g965f9466de-dirty","time":"Nov 15 2017 17:02:18 PST","version":"1.3.3"},"os":{"arch":"x86","name":"Windows NT","version":"6.2"}}}
为了访问 Qml 元素,我根据这个 post: QML Specifics:
Rectangle {
id: buttonDirect
objectName: "vradio_direct_button"
property string text: "Direct"
...
Text {
id: buttonDirectLabel; text: buttonDirect.text; anchors.centerIn: buttonDirect; color: activePalette.buttonText; font.pixelSize: 24
objectName: "vradio_direct_button"
}
}
驱动配置如下:
@Override
public RemoteWebDriver getDriver() {
RemoteWebDriver remoteWebDriver = null;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("maximize", true);
//specify reuseUI to have WebDriver terminate any previous session and reuse its windows
cap.setCapability("reuseUI", true);
//specify to select the first found window
cap.setCapability("browserStartWindow", "*");
LoggingPreferences logs = new LoggingPreferences();
Level level = Level.ALL;
logs.enable(LogType.DRIVER, level);
logs.enable(LogType.BROWSER, level);
logs.enable(LogType.PERFORMANCE, level);
// specify log level
cap.setCapability(CapabilityType.LOGGING_PREFS, logs);
try {
URL url = new URL("http://localhost:9517");
remoteWebDriver = new RemoteWebDriver(url, cap);
Logger.debug("Native Page Sources:\n" + remoteWebDriver.getPageSource());
} catch (MalformedURLException e) {
e.printStackTrace();
}
return remoteWebDriver;
}
}
但是,当我要执行时:
Object object = Driver.getDefault().executeScript("var v = ObjectNameUtils.findChild('vradio_direct_button'); return v.text;");
Logger.info("Here is JS output:" + object);
我得到了:
org.openqa.selenium.WebDriverException: Script execution failed. Script: var v = ObjectNameUtils.findChild('vradio_direct_button'); return v.text;;
Current view doesnt support this command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.7.0', revision: '2321c73', time: '2017-11-02T22:22:35.584Z'
System info: host: 'LVL1305001', ip: '172.22.73.100', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptSslCerts: false, applicationCacheEnabled: true, browserConnectionEnabled: true, browserName: QtWebkit, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hybrid: {qml2: true, qtVersion: 5.2.1, widget: true}, javascriptEnabled: true, locationContextEnabled: false, nativeEvents: true, platform: XP, platformName: XP, remotePlayerEnabled: true, reuseUI: true, rotatable: false, takesElementScreenshot: true, takesScreenshot: true, webStorageEnabled: true}
Session ID: bfa073ee2e334f4977281996f3240b90
本机页面源看起来:
<?xml version="1.0" encoding="UTF-8"?>
<MainWindow elementId="2312dc5007f290f9bf4f3f92d3aa6884" className="MainWindow">
<QRubberBand id="qt_rubberband" elementId="45050a91d64ad4cde3e3df8091813f54" className="QRubberBand"/>
<QDeclarativeView elementId="3c4890eed00091c95bde9a653f59d22e" className="QDeclarativeView">
<QWidget id="qt_scrollarea_hcontainer" elementId="ff075abbbeb5fe23501c7da3241def96" className="QWidget">
<QScrollBar elementId="51188e66ef541bc0563bea5780cf8ed2" className="QScrollBar"/>
</QWidget>
<QWidget id="qt_scrollarea_vcontainer" elementId="3692bfb1340019907b7982f1ef2f821f" className="QWidget">
<QScrollBar elementId="e76434466faf78d008ca5b096719e188" className="QScrollBar"/>
</QWidget>
<QWidget elementId="ac4c1e620945ad4784fbbcd3c60ae3f1" className="QWidget"/>
</QDeclarativeView>
</MainWindow>
更新:
我在做这个 post 之前读过这个 post。但是,我没有得到完整的想法。
我知道我必须直接连接到我的 QDeclarativeView
,因此,我必须指定它具有 QtDriver 的功能:
cap.setCapability("browserClass", "MyWebView");
此外,我必须在服务器端设置它:
int main(int argc, char *argv[])
{
//Configure web support
webdriver::ViewCreator* webCreator = new webdriver::QWebViewCreator();
//Register custom web view subclass
webCreator->RegisterViewClass<QDeclarativeView>("MyWebView");
我说得对吗?或者在让它发挥作用的过程中缺少了什么?
如何解决这个错误并点击按钮?
cap.setCapability("browserStartWindow", "*");
将使 QtWebdriver select 成为它找到的第一个 window。
在您的情况下,从本机源代码来看,它将是 MainWindow,它是一个不支持 JS 的 QWidget,因此会出现错误消息。
你需要 select 显式 QDeclarativeview。
这个link:https://github.com/cisco-open-source/qtwebdriver/wiki/Hybridity-And-View-Management 提供了有关如何执行此操作的更多详细信息以及代码示例