Support Capybara 3 current_url/title being for top level browsing context requirement
This commit is contained in:
parent
778ec7f43c
commit
7b25bf986d
|
@ -2,8 +2,7 @@
|
|||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "capybara", github: "jnicklas/capybara"
|
||||
gem "capybara", github: "teamcapybara/capybara"
|
||||
gem "puma"
|
||||
|
||||
gem 'byebug'
|
||||
gemspec path: "../"
|
||||
|
|
|
@ -28,6 +28,10 @@ module Capybara::Webkit
|
|||
command("Title")
|
||||
end
|
||||
|
||||
def frame_title
|
||||
command("FrameTitle")
|
||||
end
|
||||
|
||||
def find_xpath(query)
|
||||
command("FindXpath", query).split(",")
|
||||
end
|
||||
|
@ -81,6 +85,10 @@ module Capybara::Webkit
|
|||
command("CurrentUrl")
|
||||
end
|
||||
|
||||
def frame_url
|
||||
command("FrameUrl")
|
||||
end
|
||||
|
||||
def frame_focus(selector=nil)
|
||||
if selector.respond_to?(:base)
|
||||
selector.base.invoke("focus_frame")
|
||||
|
|
|
@ -43,7 +43,15 @@ module Capybara::Webkit
|
|||
end
|
||||
|
||||
def current_url
|
||||
@browser.current_url
|
||||
if Capybara::VERSION.to_f < 3.0
|
||||
@browser.frame_url
|
||||
else
|
||||
@browser.current_url
|
||||
end
|
||||
end
|
||||
|
||||
def frame_url
|
||||
@browser.frame_url
|
||||
end
|
||||
|
||||
def visit(path)
|
||||
|
@ -73,7 +81,15 @@ module Capybara::Webkit
|
|||
end
|
||||
|
||||
def title
|
||||
@browser.title
|
||||
if Capybara::VERSION.to_f < 3.0
|
||||
frame_title
|
||||
else
|
||||
@browser.title
|
||||
end
|
||||
end
|
||||
|
||||
def frame_title
|
||||
@browser.frame_title
|
||||
end
|
||||
|
||||
def execute_script(script, *args)
|
||||
|
|
|
@ -35,6 +35,7 @@ describe Capybara::Webkit::Driver do
|
|||
<<-HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Main</title>
|
||||
<style type="text/css">
|
||||
#display_none { display: none }
|
||||
</style>
|
||||
|
@ -172,7 +173,11 @@ describe Capybara::Webkit::Driver do
|
|||
|
||||
it "returns the current URL" do
|
||||
driver.within_frame("f") do
|
||||
expect(driver.current_url).to eq driver_url(driver, "/iframe")
|
||||
if Capybara::VERSION.to_f < 3.0
|
||||
expect(driver.current_url).to eq driver_url(driver, "/iframe")
|
||||
else
|
||||
expect(driver.current_url).to eq driver_url(driver, "/")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -210,9 +215,24 @@ describe Capybara::Webkit::Driver do
|
|||
end
|
||||
end
|
||||
|
||||
it "returns the document title" do
|
||||
if Capybara::VERSION.to_f < 3.0
|
||||
it "returns the document title" do
|
||||
driver.within_frame("f") do
|
||||
expect(driver.title).to eq 'Title'
|
||||
end
|
||||
end
|
||||
else
|
||||
it "returns the top level browsing context text" do
|
||||
driver.within_frame("f") do
|
||||
expect(driver.title).to eq 'Main'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "returns the title for the current frame" do
|
||||
expect(driver.frame_title).to eq 'Main'
|
||||
driver.within_frame("f") do
|
||||
expect(driver.title).to eq "Title"
|
||||
expect(driver.frame_title).to eq 'Title'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,6 +53,8 @@
|
|||
#include "SetUnknownUrlMode.h"
|
||||
#include "AllowUrl.h"
|
||||
#include "BlockUrl.h"
|
||||
#include "FrameTitle.h"
|
||||
#include "FrameUrl.h"
|
||||
|
||||
CommandFactory::CommandFactory(WebPageManager *manager, QObject *parent) : QObject(parent) {
|
||||
m_manager = manager;
|
||||
|
|
|
@ -7,7 +7,7 @@ CurrentUrl::CurrentUrl(WebPageManager *manager, QStringList &arguments, QObject
|
|||
|
||||
void CurrentUrl::start() {
|
||||
QStringList arguments;
|
||||
QVariant result = page()->currentFrame()->evaluateJavaScript("window.location.toString()");
|
||||
QVariant result = page()->mainFrame()->evaluateJavaScript("window.location.toString()");
|
||||
QString url = result.toString();
|
||||
finish(true, url);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#include "FrameTitle.h"
|
||||
#include "SocketCommand.h"
|
||||
#include "WebPage.h"
|
||||
#include "WebPageManager.h"
|
||||
|
||||
FrameTitle::FrameTitle(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
|
||||
}
|
||||
|
||||
void FrameTitle::start() {
|
||||
finish(true, page()->currentFrame()->title());
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#include "SocketCommand.h"
|
||||
|
||||
class FrameTitle : public SocketCommand {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FrameTitle(WebPageManager *, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#include "FrameUrl.h"
|
||||
#include "SocketCommand.h"
|
||||
#include "WebPage.h"
|
||||
#include "WebPageManager.h"
|
||||
|
||||
FrameUrl::FrameUrl(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
|
||||
}
|
||||
|
||||
void FrameUrl::start() {
|
||||
QVariant result = page()->currentFrame()->evaluateJavaScript("window.location.toString()");
|
||||
QString url = result.toString();
|
||||
finish(true, url);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#include "SocketCommand.h"
|
||||
|
||||
class FrameUrl : public SocketCommand {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FrameUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
|
@ -7,5 +7,5 @@ Title::Title(WebPageManager *manager, QStringList &arguments, QObject *parent) :
|
|||
}
|
||||
|
||||
void Title::start() {
|
||||
finish(true, page()->currentFrame()->title());
|
||||
finish(true, page()->mainFrame()->title());
|
||||
}
|
||||
|
|
|
@ -55,3 +55,5 @@ CHECK_COMMAND(FindModal)
|
|||
CHECK_COMMAND(SetUnknownUrlMode)
|
||||
CHECK_COMMAND(AllowUrl)
|
||||
CHECK_COMMAND(BlockUrl)
|
||||
CHECK_COMMAND(FrameTitle)
|
||||
CHECK_COMMAND(FrameUrl)
|
||||
|
|
|
@ -10,6 +10,8 @@ PRECOMPILED_DIR = $${BUILD_DIR}
|
|||
OBJECTS_DIR = $${BUILD_DIR}
|
||||
MOC_DIR = $${BUILD_DIR}
|
||||
HEADERS = \
|
||||
FrameUrl.h \
|
||||
FrameTitle.h \
|
||||
BlockUrl.h \
|
||||
AllowUrl.h \
|
||||
SetUnknownUrlMode.h \
|
||||
|
@ -95,6 +97,8 @@ HEADERS = \
|
|||
UnknownUrlHandler.h
|
||||
|
||||
SOURCES = \
|
||||
FrameUrl.cpp \
|
||||
FrameTitle.cpp \
|
||||
BlockUrl.cpp \
|
||||
AllowUrl.cpp \
|
||||
SetUnknownUrlMode.cpp \
|
||||
|
|
Loading…
Reference in New Issue