mirror of
https://github.com/teampoltergeist/poltergeist.git
synced 2022-11-09 12:05:00 -05:00
Add go_back and go_forward implementation in poltergeist capybara driver
Added in capybara 2.2.0
This commit is contained in:
parent
d15e2b582d
commit
8ba76e875f
6 changed files with 54 additions and 2 deletions
|
@ -277,6 +277,14 @@ module Capybara::Poltergeist
|
|||
raise
|
||||
end
|
||||
|
||||
def go_back
|
||||
command 'go_back'
|
||||
end
|
||||
|
||||
def go_forward
|
||||
command 'go_forward'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log(message)
|
||||
|
|
|
@ -361,3 +361,11 @@ class Poltergeist.Browser
|
|||
# This command is purely for testing error handling
|
||||
browser_error: ->
|
||||
throw new Error('zomg')
|
||||
|
||||
go_back: ->
|
||||
this.page.goBack() if this.page.canGoBack
|
||||
this.sendResponse(true)
|
||||
|
||||
go_forward: ->
|
||||
this.page.goForward() if this.page.canGoForward
|
||||
this.sendResponse(true)
|
||||
|
|
|
@ -481,6 +481,20 @@ Poltergeist.Browser = (function() {
|
|||
throw new Error('zomg');
|
||||
};
|
||||
|
||||
Browser.prototype.go_back = function() {
|
||||
if (this.page.canGoBack) {
|
||||
this.page.goBack();
|
||||
}
|
||||
return this.sendResponse(true);
|
||||
};
|
||||
|
||||
Browser.prototype.go_forward = function() {
|
||||
if (this.page.canGoForward) {
|
||||
this.page.goForward();
|
||||
}
|
||||
return this.sendResponse(true);
|
||||
};
|
||||
|
||||
return Browser;
|
||||
|
||||
})();
|
||||
|
|
|
@ -6,7 +6,7 @@ Poltergeist.WebPage = (function() {
|
|||
|
||||
WebPage.CALLBACKS = ['onAlert', 'onConsoleMessage', 'onLoadFinished', 'onInitialized', 'onLoadStarted', 'onResourceRequested', 'onResourceReceived', 'onError', 'onNavigationRequested', 'onUrlChanged', 'onPageCreated'];
|
||||
|
||||
WebPage.DELEGATES = ['open', 'sendEvent', 'uploadFile', 'release', 'render', 'renderBase64'];
|
||||
WebPage.DELEGATES = ['open', 'sendEvent', 'uploadFile', 'release', 'render', 'renderBase64', 'goBack', 'goForward'];
|
||||
|
||||
WebPage.COMMANDS = ['currentUrl', 'find', 'nodeCall', 'documentSize', 'beforeUpload', 'afterUpload'];
|
||||
|
||||
|
@ -391,6 +391,14 @@ Poltergeist.WebPage = (function() {
|
|||
}
|
||||
};
|
||||
|
||||
WebPage.prototype.canGoBack = function() {
|
||||
return this["native"].canGoBack;
|
||||
};
|
||||
|
||||
WebPage.prototype.canGoForward = function() {
|
||||
return this["native"].canGoForward;
|
||||
};
|
||||
|
||||
return WebPage;
|
||||
|
||||
}).call(this);
|
||||
|
|
|
@ -3,7 +3,7 @@ class Poltergeist.WebPage
|
|||
'onLoadStarted', 'onResourceRequested', 'onResourceReceived',
|
||||
'onError', 'onNavigationRequested', 'onUrlChanged', 'onPageCreated']
|
||||
|
||||
@DELEGATES = ['open', 'sendEvent', 'uploadFile', 'release', 'render', 'renderBase64']
|
||||
@DELEGATES = ['open', 'sendEvent', 'uploadFile', 'release', 'render', 'renderBase64', 'goBack', 'goForward']
|
||||
|
||||
@COMMANDS = ['currentUrl', 'find', 'nodeCall', 'documentSize', 'beforeUpload', 'afterUpload']
|
||||
|
||||
|
@ -278,3 +278,9 @@ class Poltergeist.WebPage
|
|||
throw new Poltergeist.BrowserError(result.error.message, result.error.stack)
|
||||
else
|
||||
result.value
|
||||
|
||||
canGoBack: ->
|
||||
@native.canGoBack
|
||||
|
||||
canGoForward: ->
|
||||
@native.canGoForward
|
||||
|
|
|
@ -262,5 +262,13 @@ module Capybara::Poltergeist
|
|||
def invalid_element_errors
|
||||
[Capybara::Poltergeist::ObsoleteNode, Capybara::Poltergeist::MouseEventFailed]
|
||||
end
|
||||
|
||||
def go_back
|
||||
browser.go_back
|
||||
end
|
||||
|
||||
def go_forward
|
||||
browser.go_forward
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue