17
17
18
18
import pytest
19
19
20
+ from selenium .common .exceptions import WebDriverException
20
21
from selenium .webdriver .support .wait import WebDriverWait
21
22
22
23
@@ -38,3 +39,83 @@ def testShouldMaximizeTheWindow(driver):
38
39
new_size = driver .get_window_size ()
39
40
assert new_size ["width" ] > size ["width" ]
40
41
assert new_size ["height" ] > size ["height" ]
42
+
43
+
44
+ def test_should_get_the_size_of_the_current_window (driver ):
45
+ size = driver .get_window_size ()
46
+ assert size .get ('width' ) > 0
47
+ assert size .get ('height' ) > 0
48
+
49
+
50
+ def test_should_set_the_size_of_the_current_window (driver ):
51
+ size = driver .get_window_size ()
52
+
53
+ target_width = size .get ('width' ) - 20
54
+ target_height = size .get ('height' ) - 20
55
+ driver .set_window_size (width = target_width , height = target_height )
56
+
57
+ new_size = driver .get_window_size ()
58
+ assert new_size .get ('width' ) == target_width
59
+ assert new_size .get ('height' ) == target_height
60
+
61
+
62
+ def test_should_get_the_position_of_the_current_window (driver ):
63
+ position = driver .get_window_position ()
64
+ assert position .get ('x' ) >= 0
65
+ assert position .get ('y' ) >= 0
66
+
67
+
68
+ def test_should_set_the_position_of_the_current_window (driver ):
69
+ position = driver .get_window_position ()
70
+
71
+ target_x = position .get ('x' ) + 10
72
+ target_y = position .get ('y' ) + 10
73
+ driver .set_window_position (x = target_x , y = target_y )
74
+
75
+ WebDriverWait (driver , 2 ).until (lambda d : d .get_window_position ()['x' ] != position ['x' ] and
76
+ d .get_window_position ()['y' ] != position ['y' ])
77
+
78
+ new_position = driver .get_window_position ()
79
+ assert new_position .get ('x' ) == target_x
80
+ assert new_position .get ('y' ) == target_y
81
+
82
+
83
+ @pytest .mark .xfail_chrome (raises = WebDriverException ,
84
+ reason = 'Get Window Rect command not implemented' )
85
+ @pytest .mark .xfail_phantomjs (raises = WebDriverException ,
86
+ reason = 'Get Window Rect command not implemented' )
87
+ @pytest .mark .xfail_safari (raises = WebDriverException ,
88
+ reason = 'Get Window Rect command not implemented' )
89
+ def test_should_get_the_rect_of_the_current_window (driver ):
90
+ rect = driver .get_window_rect ()
91
+ assert rect .get ('x' ) >= 0
92
+ assert rect .get ('y' ) >= 0
93
+ assert rect .get ('width' ) >= 0
94
+ assert rect .get ('height' ) >= 0
95
+
96
+
97
+ @pytest .mark .xfail_chrome (raises = WebDriverException ,
98
+ reason = 'Get Window Rect command not implemented' )
99
+ @pytest .mark .xfail_phantomjs (raises = WebDriverException ,
100
+ reason = 'Get Window Rect command not implemented' )
101
+ @pytest .mark .xfail_safari (raises = WebDriverException ,
102
+ reason = 'Get Window Rect command not implemented' )
103
+ def test_should_set_the_rect_of_the_current_window (driver ):
104
+ rect = driver .get_window_rect ()
105
+
106
+ target_x = rect .get ('x' ) + 10
107
+ target_y = rect .get ('y' ) + 10
108
+ target_width = rect .get ('width' ) + 10
109
+ target_height = rect .get ('height' ) + 10
110
+
111
+ driver .set_window_rect (x = target_x , y = target_y , width = target_width , height = target_height )
112
+
113
+ WebDriverWait (driver , 2 ).until (lambda d : d .get_window_position ()['x' ] != rect ['x' ] and
114
+ d .get_window_position ()['y' ] != rect ['y' ])
115
+
116
+ new_rect = driver .get_window_rect ()
117
+
118
+ assert new_rect .get ('x' ) == target_x
119
+ assert new_rect .get ('y' ) == target_y
120
+ assert new_rect .get ('width' ) == target_width
121
+ assert new_rect .get ('height' ) == target_height
0 commit comments