Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Show command: display the running page in a live window

  • Loading branch information...
commit 226f34566a76e63f1e443e7535fb493d803a9b33 1 parent 30d90f9
Joe Ferris jferris authored
13 lib/capybara/driver/webkit.rb
View
@@ -45,19 +45,19 @@ def evaluate_script(script)
end
def response_headers
- raise Capybara::NotSupportedByDriverError
+ raise ::Capybara::NotSupportedByDriverError
end
def status_code
- raise Capybara::NotSupportedByDriverError
+ raise ::Capybara::NotSupportedByDriverError
end
def within_frame(frame_id)
- raise Capybara::NotSupportedByDriverError
+ raise ::Capybara::NotSupportedByDriverError
end
def within_window(handle)
- raise Capybara::NotSupportedByDriverError
+ raise ::Capybara::NotSupportedByDriverError
end
def wait?
@@ -75,6 +75,11 @@ def has_shortcircuit_timeout?
false
end
+ # Non-standard: displays the browser in a window
+ def show
+ browser.show
+ end
+
private
def url(path)
4 lib/capybara/driver/webkit/browser.rb
View
@@ -50,6 +50,10 @@ def execute_script(script)
command('Execute', script)
end
+ def show
+ command "Show"
+ end
+
private
def start_server
2  lib/capybara/driver/webkit/node.rb
View
@@ -56,7 +56,7 @@ def visible?
end
def path
- raise NotSupportedByDriverError
+ raise ::Capybara::NotSupportedByDriverError
end
def trigger(event)
1  src/Connection.cpp
View
@@ -9,6 +9,7 @@
#include "Source.h"
#include "Evaluate.h"
#include "Execute.h"
+#include "Show.h"
#include <QTcpSocket>
#include <iostream>
13 src/Show.cpp
View
@@ -0,0 +1,13 @@
+#include "Show.h"
+#include "WebPage.h"
+
+Show::Show(WebPage *page, QObject *parent) : Command(page, parent) {
+}
+
+void Show::start(QStringList &arguments) {
+ Q_UNUSED(arguments);
+ page()->showInWindow();
+ QString response;
+ emit finished(true, response);
+}
+
12 src/Show.h
View
@@ -0,0 +1,12 @@
+#include "Command.h"
+
+class WebPage;
+
+class Show : public Command {
+ Q_OBJECT
+
+ public:
+ Show(WebPage *page, QObject *parent = 0);
+ virtual void start(QStringList &arguments);
+};
+
10 src/WebPage.cpp
View
@@ -1,6 +1,8 @@
#include "WebPage.h"
#include "JavascriptInvocation.h"
#include <QResource>
+#include <QMainWindow>
+#include <QApplication>
#include <iostream>
WebPage::WebPage(QObject *parent) : QWebPage(parent) {
@@ -79,3 +81,11 @@ QString WebPage::failureString() {
return QString("Unable to load URL: ") + mainFrame()->url().toString();
}
+void WebPage::showInWindow() {
+ m_window = new QMainWindow(0, Qt::WindowStaysOnTopHint);
+ m_view = new QWebView(m_window);
+ m_view->setPage(this);
+ m_window->setCentralWidget(m_view);
+ m_window->show();
+}
+
6 src/WebPage.h
View
@@ -1,5 +1,8 @@
#include <QtWebKit>
+class QMainWindow;
+class QWebView;
+
class WebPage : public QWebPage {
Q_OBJECT
@@ -8,6 +11,7 @@ class WebPage : public QWebPage {
QVariant invokeCapybaraFunction(const char *name, QStringList &arguments);
QVariant invokeCapybaraFunction(QString &name, QStringList &arguments);
QString failureString();
+ void showInWindow();
public slots:
bool shouldInterruptJavaScript();
@@ -25,5 +29,7 @@ class WebPage : public QWebPage {
private:
QString m_capybaraJavascript;
bool m_loading;
+ QMainWindow *m_window;
+ QWebView *m_view;
};
1  src/find_command.h
View
@@ -11,3 +11,4 @@ CHECK_COMMAND(Url)
CHECK_COMMAND(Source)
CHECK_COMMAND(Evaluate)
CHECK_COMMAND(Execute)
+CHECK_COMMAND(Show)
4 src/webkit_server.pro
View
@@ -1,8 +1,8 @@
TEMPLATE = app
TARGET = webkit_server
DESTDIR = .
-HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h Url.h Source.h Evaluate.h Execute.h
-SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp Url.cpp Source.cpp Evaluate.cpp Execute.cpp
+HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h Url.h Source.h Evaluate.h Execute.h Show.h
+SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp Url.cpp Source.cpp Evaluate.cpp Execute.cpp Show.cpp
RESOURCES = webkit_server.qrc
QT += network webkit
CONFIG += console
Please sign in to comment.
Something went wrong with that request. Please try again.