Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/integration/selenium/webdriver/window_spec.rb
1864 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require_relative 'spec_helper'
21
22
module Selenium
23
module WebDriver
24
describe Window, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do
25
after(:all) { reset_driver! }
26
27
let(:window) { driver.manage.window }
28
29
it 'gets the size of the current window' do
30
size = window.size
31
32
expect(size).to be_a(Dimension)
33
34
expect(size.width).to be_positive
35
expect(size.height).to be_positive
36
end
37
38
it 'sets the size of the current window' do
39
size = window.size
40
41
target_width = size.width - 20
42
target_height = size.height - 20
43
44
window.size = Dimension.new(target_width, target_height)
45
46
new_size = window.size
47
expect(new_size.width).to eq(target_width)
48
expect(new_size.height).to eq(target_height)
49
end
50
51
it 'gets the position of the current window' do
52
pos = window.position
53
54
expect(pos).to be_a(Point)
55
56
expect(pos.x).to be >= 0
57
expect(pos.y).to be >= 0
58
end
59
60
it 'sets the position of the current window' do
61
pos = window.position
62
63
target_x = pos.x + 10
64
target_y = pos.y + 10
65
66
window.position = Point.new(target_x, target_y)
67
68
wait.until { window.position.x != pos.x && window.position.y != pos.y }
69
70
new_pos = window.position
71
expect(new_pos.x).to eq(target_x)
72
expect(new_pos.y).to eq(target_y)
73
end
74
75
it 'gets the rect of the current window' do
76
rect = window.rect
77
78
expect(rect).to be_a(Rectangle)
79
80
expect(rect.x).to be >= 0
81
expect(rect.y).to be >= 0
82
expect(rect.width).to be >= 0
83
expect(rect.height).to be >= 0
84
end
85
86
it 'sets the rect of the current window' do
87
rect = window.rect
88
89
target_x = rect.x + 10
90
target_y = rect.y + 10
91
target_width = rect.width + 10
92
target_height = rect.height + 10
93
94
window.rect = Rectangle.new(target_x, target_y, target_width, target_height)
95
96
wait.until { window.rect.x != rect.x && window.rect.y != rect.y }
97
98
new_rect = window.rect
99
expect(new_rect.x).to eq(target_x)
100
expect(new_rect.y).to eq(target_y)
101
expect(new_rect.width).to eq(target_width)
102
expect(new_rect.height).to eq(target_height)
103
end
104
105
it 'can maximize the current window' do
106
window.size = old_size = Dimension.new(700, 700)
107
108
window.maximize
109
wait.until { window.size != old_size }
110
111
new_size = window.size
112
expect(new_size.width).to be > old_size.width
113
expect(new_size.height).to be > old_size.height
114
end
115
116
it 'can make window full screen', except: {browser: %i[chrome edge], headless: true} do
117
window.size = old_size = Dimension.new(700, 700)
118
119
window.full_screen
120
wait.until { window.size != old_size }
121
122
new_size = window.size
123
expect(new_size.width).to be > old_size.width
124
expect(new_size.height).to be > old_size.height
125
end
126
127
it 'can minimize the window', except: [{browser: %i[chrome edge], headless: true}],
128
flaky: {browser: :chrome, platform: %i[macosx linux], ci: :github} do
129
window.minimize
130
expect {
131
wait.until { driver.execute_script('return document.hidden;') }
132
}.not_to raise_error
133
end
134
end
135
end # WebDriver
136
end # Selenium
137
138