watir
watir copied to clipboard
Feature request: add an #undomaximize method
Watir today has a method #maximize that wraps the maximize method for Selenium itself.
Say that you call @browser.window.maximize in a script. At the time you call #maximize on the window, have watir store the existing window size. Then enable the user to call a method something like #unmaximize or #undomaximize to return the window to it's previous size.
If a user calls #undomaximize without having called #maximize first, this should be a noop, possibly with a warning similar to other watir warnings, something like that the stored previous window size is 0,0 and did you mean to call #undomaximize without having called #maximize first?
This is a feature that I myself have wanted from time to time over the years, but every time I need it I find it doesn't exist yet. We discussed the idea on the watir slack channel and people thought it would be valuable and "matches user behavior".
I looked at this, and I'm not sure about always adding another command to store the original size automatically.
This can be done right now:
original_size = @browser.window.size
@browser.window.maximize
@browser.window.resize_to(*original_size)
I looked at storing original size/position in the window and providing a method to restore that value.
The problem is that we don't tend to reuse the same window. Every time we call @browser.window
we create a new instance, so this wouldn't work:
@browser.window.maximize
@browser.window.restore
This could be made to work:
window = @browser.window
window.maximize
window.restore
But at that point, why not just use the first method....
Now, we could also cache the Window
instance we get from @browser.window
, but I'm not sure I have a good mental picture right now for when we would need to reset the cache, so I'm not going to do it before 7.0 release.
Much better would be for the driver itself to be able to direct this behavior, so I'll raise a feature request in webdriver spec.