Skip to content

Commit 23ae0ca

Browse files
committed
add test browser tests
1 parent 14a154c commit 23ae0ca

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import pytest
19+
20+
from selenium.webdriver.common.bidi.browser import ClientWindowInfo, ClientWindowState
21+
22+
23+
@pytest.mark.xfail_safari
24+
def test_browser_initialized(driver):
25+
"""Test that the browser module is initialized properly."""
26+
assert driver.browser is not None
27+
28+
29+
@pytest.mark.xfail_safari
30+
def test_create_user_context(driver):
31+
"""Test creating a user context."""
32+
user_context = driver.browser.create_user_context()
33+
assert user_context is not None
34+
35+
# Clean up
36+
driver.browser.remove_user_context(user_context)
37+
38+
39+
@pytest.mark.xfail_safari
40+
def test_get_user_contexts(driver):
41+
"""Test getting user contexts."""
42+
user_context1 = driver.browser.create_user_context()
43+
user_context2 = driver.browser.create_user_context()
44+
45+
user_contexts = driver.browser.get_user_contexts()
46+
# it should be 3 since there is a default user context present, therefore >= 2
47+
assert len(user_contexts) >= 2
48+
49+
# Clean up
50+
driver.browser.remove_user_context(user_context1)
51+
driver.browser.remove_user_context(user_context2)
52+
53+
54+
@pytest.mark.xfail_safari
55+
def test_remove_user_context(driver):
56+
"""Test removing a user context."""
57+
user_context1 = driver.browser.create_user_context()
58+
user_context2 = driver.browser.create_user_context()
59+
60+
user_contexts = driver.browser.get_user_contexts()
61+
assert len(user_contexts) >= 2
62+
63+
driver.browser.remove_user_context(user_context2)
64+
65+
updated_user_contexts = driver.browser.get_user_contexts()
66+
assert user_context1 in updated_user_contexts
67+
assert user_context2 not in updated_user_contexts
68+
69+
# Clean up
70+
driver.browser.remove_user_context(user_context1)
71+
72+
73+
@pytest.mark.xfail_safari
74+
def test_get_client_windows(driver):
75+
"""Test getting client windows."""
76+
client_windows = driver.browser.get_client_windows()
77+
78+
assert client_windows is not None
79+
assert len(client_windows) > 0
80+
81+
window_info = client_windows[0]
82+
assert isinstance(window_info, ClientWindowInfo)
83+
assert window_info.get_client_window() is not None
84+
assert window_info.get_state() is not None
85+
assert isinstance(window_info.get_state(), str)
86+
assert window_info.get_width() > 0
87+
assert window_info.get_height() > 0
88+
assert isinstance(window_info.is_active(), bool)
89+
assert window_info.get_x() > 0
90+
assert window_info.get_y() > 0
91+
92+
93+
@pytest.mark.xfail_safari
94+
def test_client_window_state_constants(driver):
95+
assert ClientWindowState.FULLSCREEN == "fullscreen"
96+
assert ClientWindowState.MAXIMIZED == "maximized"
97+
assert ClientWindowState.MINIMIZED == "minimized"
98+
assert ClientWindowState.NORMAL == "normal"

0 commit comments

Comments
 (0)