In Capybara, is it possible to open a link in a new window, rather than the current one?
If this element is a link you can just get its href and open it in a new window:
url = find('.some_link')[:href]
within_window open_new_window do
# do something
end
open_new_window has been added in Capybara 2.3
Related
I want to add an hyperlink or a button in my FitNesse page.
On click of this link or button a popup window with some HTML content should open.
Please let me know if this is possible in FitNesse? If yes, how to achieve this?
I tried to search on FitNesse website but could not get information.
Adding a link to a wiki page is easy: just type the link, or use [[word or phrase][url]]. But this will not open a pop-up. I don't know how to achieve that by just using the wiki.
In a Slim fixture's result you can return any HTML (sometimes you will have to surround it with <div></div>), so you can return ... and in the test result there will be a hyperlink that will open in a new tab...
I am using Activeadmin with Rich Editor.
When I add a link to my text within the window of the editor i cannot set how the link is being opened - wether it is in a new tab or a new window ..
I understand that the Rich editor derives from CKEditor with certain features being disabled and that these features can be reenabled.
Also I know, that this particular feature is set in the config by the line
config.linkShowTargetTab = true
I am just not sure on where to put it exactly so that it is enabled globally.
Thanks for any advice on this.
In the gem source (lib/rich.rb) you can see the default buttons defined in ##editor[:toolbar]:
##editor = {
...
:removeDialogTabs => 'link:advanced;link:target',
...
}
If I delete ";link:target" the Tab is shown in my app.
I'm in my applications controller and I have a url string. How do I tell the app to open the url in the browser in a new window. Is there a way to set the target to blank?
For example
def link
#url = 'www.google.com'
****??? Open #url ?? *** with target blank?
end
This is not possible to do directly from the controller. Using redirect_to #url has the effect of opening an URL in the same "window", as it simply sends a HTTP redirect instruction back to the browser. redirect_to is not capable of opening new windows. The controller resides on the server side, and opening a new window belongs to the client side.
Some options:
a) render a link with <%= link_to 'Google', 'google.com', :target => '_blank' %> or Google which the user can click on in a new view
b) use JavaScript to open the link automatically, but beware that browsers may treat this as a popup and block it
By combining these options you can open links in new window for browsers/users who allow it, and fall back to a regular URL in case that didn't work.
As the others point out, you can't (and shouldn't) do this in the controller. In the view you can use
<%= link_to #url, :target => "_blank" %>
Well, it's not that you CAN'T do it, it's just kind of a convoluted process. I did this in a project I'm working on. Basically, it's a mixture of Rails goodness and Javascript. I simply passed a flash notice on creation of an instance, and then used a script to set that flash notice equal to a js variable, and a redirect_url. If that particular flash notice pops up on that page, it redirects in the js script. Like I said, it's hack hack hack, but it works for my purposes.
You can't do that in rails, because your script is being executed on a server.
Use Javascript to work with browser on the client side.
I have the following link in my view that opens a changelog in a new page:
<%= link_to("Changelog", changelog_path, :target => "_blank") %>
In this changelog page I would like to create a link to close this changelog page.
What is the most appropriate way to do this ?
Is that possible to achieve this without Javascript ?
You will need to use JavaScript for this. You can call window.close(), but this will prompt the user before closing the window, unless the window was opened from JavaScript with window.open(), so you will also need to use JavaScript for opening the window instead of a link with target="_blank".
I have a link that opens in a new window, and I need to test the part of my app that is within that new window.
Any suggestions will be much appreciated.
Define a step that contains this code:
page.driver.browser.switch_to.window (page.driver.browser.window_handles.last)
switch_to is a selenium command that allows you to change over to a new window
window_handles returns a list of currently open windows
I realize this is a very old post, but here's a Cucumber step definition using Capybara and the Poltergeist driver:
And /^I follow "([^"]*)" to the new window$/ do |link|
new_window = window_opened_by { click_link link }
switch_to_window new_window
end
Could you just validate that the link has it's target set to _blank?