Passing a string argument in #within_window is deprecated

I am trying to update my code because I am currently triggering the following warning on startup failure:

"DEPRECATION WARNING: Passing a string argument to #within_window is deprecated. Skip window object or lambda."

Here is the code:

new_window=page.driver.browser.window_handles.last page.within_window new_window do expect(current_url).to eq("url") end page.driver.browser.switch_to.window(page.driver.browser.window_handles.last) 

How do I edit above so that I no longer receive an obsolescence warning? Thanks!

+5
source share
1 answer

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 
+9
source

Source: https://habr.com/ru/post/1200892/


All Articles