Path: blob/trunk/rb/spec/integration/selenium/webdriver/window_spec.rb
1864 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.1819require_relative 'spec_helper'2021module Selenium22module WebDriver23describe Window, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do24after(:all) { reset_driver! }2526let(:window) { driver.manage.window }2728it 'gets the size of the current window' do29size = window.size3031expect(size).to be_a(Dimension)3233expect(size.width).to be_positive34expect(size.height).to be_positive35end3637it 'sets the size of the current window' do38size = window.size3940target_width = size.width - 2041target_height = size.height - 204243window.size = Dimension.new(target_width, target_height)4445new_size = window.size46expect(new_size.width).to eq(target_width)47expect(new_size.height).to eq(target_height)48end4950it 'gets the position of the current window' do51pos = window.position5253expect(pos).to be_a(Point)5455expect(pos.x).to be >= 056expect(pos.y).to be >= 057end5859it 'sets the position of the current window' do60pos = window.position6162target_x = pos.x + 1063target_y = pos.y + 106465window.position = Point.new(target_x, target_y)6667wait.until { window.position.x != pos.x && window.position.y != pos.y }6869new_pos = window.position70expect(new_pos.x).to eq(target_x)71expect(new_pos.y).to eq(target_y)72end7374it 'gets the rect of the current window' do75rect = window.rect7677expect(rect).to be_a(Rectangle)7879expect(rect.x).to be >= 080expect(rect.y).to be >= 081expect(rect.width).to be >= 082expect(rect.height).to be >= 083end8485it 'sets the rect of the current window' do86rect = window.rect8788target_x = rect.x + 1089target_y = rect.y + 1090target_width = rect.width + 1091target_height = rect.height + 109293window.rect = Rectangle.new(target_x, target_y, target_width, target_height)9495wait.until { window.rect.x != rect.x && window.rect.y != rect.y }9697new_rect = window.rect98expect(new_rect.x).to eq(target_x)99expect(new_rect.y).to eq(target_y)100expect(new_rect.width).to eq(target_width)101expect(new_rect.height).to eq(target_height)102end103104it 'can maximize the current window' do105window.size = old_size = Dimension.new(700, 700)106107window.maximize108wait.until { window.size != old_size }109110new_size = window.size111expect(new_size.width).to be > old_size.width112expect(new_size.height).to be > old_size.height113end114115it 'can make window full screen', except: {browser: %i[chrome edge], headless: true} do116window.size = old_size = Dimension.new(700, 700)117118window.full_screen119wait.until { window.size != old_size }120121new_size = window.size122expect(new_size.width).to be > old_size.width123expect(new_size.height).to be > old_size.height124end125126it 'can minimize the window', except: [{browser: %i[chrome edge], headless: true}],127flaky: {browser: :chrome, platform: %i[macosx linux], ci: :github} do128window.minimize129expect {130wait.until { driver.execute_script('return document.hidden;') }131}.not_to raise_error132end133end134end # WebDriver135end # Selenium136137138