The within_window method within_window been modified to expect Capybara :: Window or proc / lamda. Finding a window using a string that returns window_handles.last is deprecated.
To get the last Capybara :: Window, use the windows method. It works similarly to what was done using window_handles :
new_window = windows.last page.within_window new_window do expect(current_url).to eq("url") end
Please note that the documentation states that "the order of the windows in the returned array is not defined. The driver can sort the windows by the time they were created, but this is not required." I think the same thing was true when using window_handles , so you can probably safely assume that the last window is a new window.
However, if possible, it would probably be better to find the window using something specific, such as a title:
within_window(->{ page.title == 'New window title' }) do expect(current_url).to eq("url") end
source share