mirror of
https://github.com/teampoltergeist/poltergeist.git
synced 2022-11-09 12:05:00 -05:00
Merge pull request #344 from juanger/window_handles
New feature. window_handles returns the list of open windows names
This commit is contained in:
commit
79eff09cec
8 changed files with 72 additions and 0 deletions
27
README.md
27
README.md
|
@ -186,6 +186,32 @@ The following methods are used to inspect and manipulate cookies:
|
|||
object.
|
||||
* `page.driver.remove_cookie(name)` - remove a cookie
|
||||
|
||||
### Window switching ###
|
||||
|
||||
The following methods can be used to execute commands inside different windows:
|
||||
|
||||
* `page.driver.window_handles` - an array containing the names of all
|
||||
the open windows.
|
||||
|
||||
* `page.within_window(name) { # actions }` - executes
|
||||
the passed block in the context of the named window.
|
||||
|
||||
Example:
|
||||
|
||||
``` ruby
|
||||
find_link("Login with Facebook").trigger("click")
|
||||
|
||||
sleep(0.1)
|
||||
|
||||
fb_popup = page.driver.window_handles.last
|
||||
page.within_window fb_popup do
|
||||
fill_in "email", :with => "facebook_email@email.tst"
|
||||
fill_in "pass", :with => "my_pass"
|
||||
click_button "Log In"
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
## Customization ##
|
||||
|
||||
You can customize the way that Capybara sets up Poltegeist via the following code in your
|
||||
|
@ -329,6 +355,7 @@ Include as much information as possible. For example:
|
|||
#### Features ####
|
||||
|
||||
* Can set cookies for given domain
|
||||
* Can get open window names with window_handles [Issue #178]
|
||||
|
||||
#### Bug fixes ####
|
||||
|
||||
|
|
|
@ -118,6 +118,10 @@ module Capybara::Poltergeist
|
|||
command 'pop_frame'
|
||||
end
|
||||
|
||||
def window_handles
|
||||
command 'pages'
|
||||
end
|
||||
|
||||
def within_window(name, &block)
|
||||
command 'push_window', name
|
||||
yield
|
||||
|
|
|
@ -171,6 +171,9 @@ class Poltergeist.Browser
|
|||
else
|
||||
@owner.sendError(new Poltergeist.FrameNotFound(name))
|
||||
|
||||
pages: ->
|
||||
this.sendResponse(@page.pages())
|
||||
|
||||
pop_frame: ->
|
||||
this.sendResponse(@page.popFrame())
|
||||
|
||||
|
|
|
@ -228,6 +228,10 @@ Poltergeist.Browser = (function() {
|
|||
}
|
||||
};
|
||||
|
||||
Browser.prototype.pages = function() {
|
||||
return this.sendResponse(this.page.pages());
|
||||
};
|
||||
|
||||
Browser.prototype.pop_frame = function() {
|
||||
return this.sendResponse(this.page.popFrame());
|
||||
};
|
||||
|
|
|
@ -235,6 +235,10 @@ Poltergeist.WebPage = (function() {
|
|||
}
|
||||
};
|
||||
|
||||
WebPage.prototype.pages = function() {
|
||||
return this["native"].pagesWindowName;
|
||||
};
|
||||
|
||||
WebPage.prototype.popFrame = function() {
|
||||
this.frames.pop();
|
||||
return this["native"].switchToParentFrame();
|
||||
|
|
|
@ -155,6 +155,9 @@ class Poltergeist.WebPage
|
|||
else
|
||||
false
|
||||
|
||||
pages: ->
|
||||
@native.pagesWindowName
|
||||
|
||||
popFrame: ->
|
||||
@frames.pop()
|
||||
@native.switchToParentFrame()
|
||||
|
|
|
@ -143,6 +143,10 @@ module Capybara::Poltergeist
|
|||
browser.within_window(name, &block)
|
||||
end
|
||||
|
||||
def window_handles
|
||||
browser.window_handles
|
||||
end
|
||||
|
||||
def reset!
|
||||
browser.reset
|
||||
@started = false
|
||||
|
|
|
@ -439,5 +439,28 @@ module Capybara::Poltergeist
|
|||
driver.quit
|
||||
end
|
||||
end
|
||||
|
||||
it 'lists the open windows' do
|
||||
@session.visit '/'
|
||||
|
||||
@session.evaluate_script <<-CODE
|
||||
window.open('/poltergeist/simple', 'popup')
|
||||
CODE
|
||||
|
||||
@session.evaluate_script <<-CODE
|
||||
window.open('/poltergeist/simple', 'popup2')
|
||||
CODE
|
||||
|
||||
@session.within_window 'popup2' do
|
||||
@session.html.should include('Test')
|
||||
@session.evaluate_script('window.close()')
|
||||
end
|
||||
|
||||
sleep 0.1;
|
||||
|
||||
@driver.browser.window_handles.should == ["popup"]
|
||||
@driver.window_handles.should == ["popup"]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue