Skip to content

Commit

Permalink
[rb] use rect for firefox with support for previous geckodriver versions
Browse files Browse the repository at this point in the history
add specs for window rect and minimize
  • Loading branch information
lmtierney committed Apr 6, 2017
1 parent 69be61e commit a0f75c2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
23 changes: 13 additions & 10 deletions rb/lib/selenium/webdriver/firefox/w3c_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,33 @@ def quit
@service.stop if @service
end

# Firefox doesn't implement rect yet
# Support for geckodriver < 0.15
def resize_window(width, height, handle = :current)
unless handle == :current
raise Error::WebDriverError, 'Switch to desired window before changing its size'
end
super
rescue Error::UnknownCommandError
execute :set_window_size, {}, {width: width, height: height}
end

def window_size(handle = :current)
unless handle == :current
raise Error::UnsupportedOperationError, 'Switch to desired window before getting its size'
end
data = super
rescue Error::UnknownCommandError
data = execute :get_window_size

Dimension.new data['width'], data['height']
ensure
return Dimension.new data['width'], data['height']
end

def reposition_window(x, y)
super
rescue Error::UnknownCommandError
execute :set_window_position, {}, {x: x, y: y}
end

def window_position
data = super
rescue Error::UnknownCommandError
data = execute :get_window_position
Point.new data['x'], data['y']
ensure
return Point.new data['x'], data['y']
end

private
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/remote/w3c_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ def window_position
Point.new data['x'], data['y']
end

def set_window_rect(width: nil, height: nil, x: nil, y: nil)
execute :set_window_rect, {}, {width: width, height: height, x: x, y: y}
def set_window_rect(x: nil, y: nil, width: nil, height: nil)
execute :set_window_rect, {}, {x: x, y: y, width: width, height: height}
end

def window_rect
Expand Down
48 changes: 46 additions & 2 deletions rb/spec/integration/selenium/webdriver/window_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,42 @@ module WebDriver
end
end

compliant_on browser: :ff_nightly do
it 'gets the rect of the current window' do
rect = driver.manage.window.rect

expect(rect).to be_a(Rectangle)

expect(rect.x).to be >= 0
expect(rect.y).to be >= 0
expect(rect.width).to be >= 0
expect(rect.height).to be >= 0
end

it 'sets the rect of the current window' do
rect = window.rect

target_x = rect.x + 10
target_y = rect.y + 10
target_width = rect.width + 10
target_height = rect.height + 10

window.rect = Rectangle.new(target_x, target_y, target_width, target_height)

wait.until { window.rect.x != rect.x && window.rect.y != rect.y }

new_rect = window.rect
expect(new_rect.x).to eq(target_x)
expect(new_rect.y).to eq(target_y)
expect(new_rect.width).to eq(target_width)
expect(new_rect.height).to eq(target_height)
end
end

# TODO: - Create Window Manager guard
not_compliant_on platform: :linux do
not_compliant_on browser: :safari do
it 'can maximize the current window' do
it 'can maximize the current window' do
window.size = old_size = Dimension.new(200, 200)

window.maximize
Expand All @@ -87,7 +119,7 @@ module WebDriver
new_size = window.size
expect(new_size.width).to be > old_size.width
expect(new_size.height).to be > old_size.height
end
end
end
end

Expand All @@ -106,6 +138,18 @@ module WebDriver
end
end
end

compliant_on browser: [:ff_nightly, :firefox, :edge] do
# Firefox - Not implemented yet, no bug to track
# Edge: Not Yet - https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/
not_compliant_on browser: [:ff_nightly, :firefox, :edge] do
it 'can minimize the window' do
driver.execute_script('window.minimized = false; window.onblur = function(){ window.minimized = true };')
window.minimize
expect(driver.execute_script('return window.minimized;')).to be true
end
end
end
end
end # WebDriver
end # Selenium

0 comments on commit a0f75c2

Please sign in to comment.