Skip to content

Commit 7accf10

Browse files
Augustin GottliebAugustin Gottlieb
authored andcommitted
set_window_state implemented
1 parent f8be682 commit 7accf10

File tree

5 files changed

+89
-30
lines changed

5 files changed

+89
-30
lines changed

rb/lib/selenium/webdriver/bidi/browser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def windows
5858
end
5959

6060
def window
61-
@window ||= windows.find(&:active?)
61+
@window ||= windows.find(&:active?) || windows.first
6262
end
6363
end # Browser
6464
end # BiDi

rb/lib/selenium/webdriver/bidi/browser/window.rb

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ def active?
4040
@active
4141
end
4242

43-
# Set the client window state
44-
# @param state [String, Symbol] One of: "fullscreen", "maximized", "minimized", "normal"
45-
# @param width [Integer, nil] Width in pixels (only for "normal" state)
46-
# @param height [Integer, nil] Height in pixels (only for "normal" state)
47-
# @param x [Integer, nil] X position (only for "normal" state)
48-
# @param y [Integer, nil] Y position (only for "normal" state)
4943
def set_state(state:, width: nil, height: nil, x: nil, y: nil)
5044
params = {clientWindow: @handle, state: state.to_s, width: width, height: height, x: x, y: y}.compact
5145

@@ -54,19 +48,6 @@ def set_state(state:, width: nil, height: nil, x: nil, y: nil)
5448
response
5549
end
5650

57-
private
58-
59-
def update_attributes(state:, width:, height:, x:, y:)
60-
@state = state.to_sym
61-
@width = width.to_i if width
62-
@height = height.to_i if height
63-
@x = x.to_i if x
64-
@y = y.to_i if y
65-
end
66-
67-
public
68-
69-
# Convenience methods for common state changes
7051
def maximize
7152
set_state(state: 'maximized')
7253
end
@@ -82,6 +63,16 @@ def fullscreen
8263
def resize(width:, height:, x: nil, y: nil)
8364
set_state(state: 'normal', width: width, height: height, x: x, y: y)
8465
end
66+
67+
private
68+
69+
def update_attributes(state:, width:, height:, x:, y:)
70+
@state = state.to_sym
71+
@width = width.to_i if width
72+
@height = height.to_i if height
73+
@x = x.to_i if x
74+
@y = y.to_i if y
75+
end
8576
end # Window
8677
end # Browser
8778
end # BiDi

rb/sig/lib/selenium/webdriver/bidi/browser.rbs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ module Selenium
22
module WebDriver
33
class BiDi
44
class Browser
5-
Window: Selenium::WebDriver::BiDi::Browser::Window
6-
75
@bidi: BiDi
6+
@window: Window?
87

98
def initialize: (BiDi bidi) -> void
109

1110
def create_user_context: () -> Hash[String, String]
1211

13-
def user_contexts: () -> Array[Hash[String, String]]
12+
def user_contexts: () -> Hash[String, Array[Hash[String, String]]]
13+
14+
def remove_user_context: (String user_context) -> Hash[untyped, untyped]
15+
16+
def windows: () -> Array[Window]
1417

15-
def remove_user_context: (String user_context) -> Hash[nil, nil]
18+
def window: () -> Window?
1619
end
1720
end
1821
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module Selenium
2+
module WebDriver
3+
class BiDi
4+
class Browser
5+
class Window
6+
attr_reader handle: String
7+
attr_reader active: bool
8+
attr_reader state: Symbol
9+
10+
attr_accessor height: Integer
11+
attr_accessor width: Integer
12+
attr_accessor x: Integer
13+
attr_accessor y: Integer
14+
15+
@bidi: BiDi
16+
@handle: String
17+
@active: bool
18+
@state: Symbol
19+
@height: Integer
20+
@width: Integer
21+
@x: Integer
22+
@y: Integer
23+
24+
def initialize: (BiDi bidi, handle: String, active: bool, height: Integer, width: Integer, x: Integer, y: Integer, state: String) -> void
25+
26+
def active?: () -> bool
27+
28+
def set_state: (state: String | Symbol, ?width: Integer?, ?height: Integer?, ?x: Integer?, ?y: Integer?) -> Hash[untyped, untyped]
29+
30+
def maximize: () -> Hash[untyped, untyped]
31+
32+
def minimize: () -> Hash[untyped, untyped]
33+
34+
def fullscreen: () -> Hash[untyped, untyped]
35+
36+
def resize: (width: Integer, height: Integer, ?x: Integer?, ?y: Integer?) -> Hash[untyped, untyped]
37+
38+
private
39+
40+
def update_attributes: (state: String | Symbol, width: Integer?, height: Integer?, x: Integer?, y: Integer?) -> void
41+
end
42+
end
43+
end
44+
end
45+
end

rb/spec/integration/selenium/webdriver/bidi/browser_spec.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,49 @@ class BiDi
7474
expect(active_window).to be_a(Selenium::WebDriver::BiDi::Browser::Window)
7575
end
7676

77-
it 'set window state' do
77+
# Skip all browsers until browser.setClientWindowState is implemented
78+
it 'maximizes window', except: {browser: %i[chrome edge firefox]} do
7879
browser = described_class.new(bidi)
7980
window = browser.window
8081

81-
# Test maximize
8282
window.maximize
8383
expect(window.state).to eq(:maximized)
84+
end
85+
86+
# Skip all browsers until browser.setClientWindowState is implemented
87+
it 'minimizes window', except: {browser: %i[chrome edge firefox]} do
88+
browser = described_class.new(bidi)
89+
window = browser.window
8490

85-
# Test minimize
8691
window.minimize
8792
expect(window.state).to eq(:minimized)
93+
end
94+
95+
# Skip all browsers until browser.setClientWindowState is implemented
96+
it 'sets window to fullscreen', except: {browser: %i[chrome edge firefox]} do
97+
browser = described_class.new(bidi)
98+
window = browser.window
8899

89-
# Test fullscreen
90100
window.fullscreen
91101
expect(window.state).to eq(:fullscreen)
102+
end
103+
104+
# Skip all browsers until browser.setClientWindowState is implemented
105+
it 'resizes window', except: {browser: %i[chrome edge firefox]} do
106+
browser = described_class.new(bidi)
107+
window = browser.window
92108

93-
# Test resize with normal state
94109
window.resize(width: 800, height: 600)
95110
expect(window.state).to eq(:normal)
96111
expect(window.width).to eq(800)
97112
expect(window.height).to eq(600)
113+
end
114+
115+
# Skip all browsers until browser.setClientWindowState is implemented
116+
it 'sets window state with position', except: {browser: %i[chrome edge firefox]} do
117+
browser = described_class.new(bidi)
118+
window = browser.window
98119

99-
# Test set_state with position
100120
window.set_state(state: 'normal', width: 1024, height: 768, x: 100, y: 50)
101121
expect(window.state).to eq(:normal)
102122
expect(window.width).to eq(1024)

0 commit comments

Comments
 (0)