14
14
# KIND, either express or implied. See the License for the
15
15
# specific language governing permissions and limitations
16
16
# under the License.
17
+ import re
18
+ from random import randint
19
+ from unittest .mock import Mock
17
20
18
21
import pytest
19
22
@@ -45,6 +48,16 @@ def test_should_get_the_size_of_the_current_window(driver):
45
48
assert size .get ("height" ) > 0
46
49
47
50
51
+ @pytest .mark .parametrize ("missing_key" , ["width" , "height" ])
52
+ def test_get_the_size_of_the_current_window_raises (driver , missing_key ):
53
+ driver .get_window_rect = Mock (return_value = {k : randint (1 , 15360 ) for k in ("width" , "height" ) if k != missing_key })
54
+
55
+ with pytest .raises (
56
+ KeyError , match = re .escape (f"No size with key: { missing_key } existed in { driver .get_window_rect .return_value } " )
57
+ ):
58
+ driver .get_window_size ()
59
+
60
+
48
61
def test_should_set_the_size_of_the_current_window (driver ):
49
62
size = driver .get_window_size ()
50
63
@@ -64,6 +77,17 @@ def test_should_get_the_position_of_the_current_window(driver):
64
77
assert position .get ("y" ) >= 0
65
78
66
79
80
+ @pytest .mark .parametrize ("missing_key" , ["x" , "y" ])
81
+ def test_get_the_position_of_the_current_window_raises (driver , missing_key ):
82
+ driver .get_window_rect = Mock (return_value = {k : randint (0 , 15360 ) for k in ("x" , "y" ) if k != missing_key })
83
+
84
+ with pytest .raises (
85
+ KeyError ,
86
+ match = re .escape (f"No position with key: { missing_key } existed in { driver .get_window_rect .return_value } " ),
87
+ ):
88
+ driver .get_window_position ()
89
+
90
+
67
91
def test_should_set_the_position_of_the_current_window (driver ):
68
92
position = driver .get_window_position ()
69
93
0 commit comments