Path: blob/trunk/rb/lib/selenium/webdriver/common/window.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21class Window22#23# @api private24#2526def initialize(bridge)27@bridge = bridge28end2930#31# Resize the current window to the given dimension.32#33# @param [Selenium::WebDriver::Dimension, #width and #height] dimension The new size.34#3536def size=(dimension)37unless dimension.respond_to?(:width) && dimension.respond_to?(:height)38raise ArgumentError, "expected #{dimension.inspect}:#{dimension.class} " \39'to respond to #width and #height'40end4142@bridge.resize_window dimension.width, dimension.height43end4445#46# Get the size of the current window.47#48# @return [Selenium::WebDriver::Dimension] The size.49#5051def size52@bridge.window_size53end5455#56# Move the current window to the given position.57#58# @param [Selenium::WebDriver::Point, #x and #y] point The new position.59#6061def position=(point)62unless point.respond_to?(:x) && point.respond_to?(:y)63raise ArgumentError, "expected #{point.inspect}:#{point.class} " \64'to respond to #x and #y'65end6667@bridge.reposition_window point.x, point.y68end6970#71# Get the position of the current window.72#73# @return [Selenium::WebDriver::Point] The position.74#7576def position77@bridge.window_position78end7980#81# Sets the current window rect to the given point and position.82#83# @param [Selenium::WebDriver::Rectangle, #x, #y, #width, #height] rectangle The new rect.84#8586def rect=(rectangle)87unless %w[x y width height].all? { |val| rectangle.respond_to? val }88raise ArgumentError, "expected #{rectangle.inspect}:#{rectangle.class} " \89'to respond to #x, #y, #width, and #height'90end9192@bridge.set_window_rect(x: rectangle.x,93y: rectangle.y,94width: rectangle.width,95height: rectangle.height)96end9798#99# Get the rect of the current window.100#101# @return [Selenium::WebDriver::Rectangle] The rectangle.102#103104def rect105@bridge.window_rect106end107108#109# Equivalent to #size=, but accepts width and height arguments.110#111# @example Maximize the window.112#113# max_width, max_height = driver.execute_script("return [window.screen.availWidth, window.screen.availHeight];")114# driver.manage.window.resize_to(max_width, max_height)115#116117def resize_to(width, height)118@bridge.resize_window Integer(width), Integer(height)119end120121#122# Equivalent to #position=, but accepts x and y arguments.123#124# @example125#126# driver.manage.window.move_to(300, 400)127#128129def move_to(x, y)130@bridge.reposition_window Integer(x), Integer(y)131end132133#134# Maximize the current window135#136137def maximize138@bridge.maximize_window139end140141#142# Minimize the current window143#144145def minimize146@bridge.minimize_window147end148149#150# Make current window full screen151#152153def full_screen154@bridge.full_screen_window155end156end # Window157end # WebDriver158end # Selenium159160161