-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[py] Bidi py tests expansion #17193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[py] Bidi py tests expansion #17193
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
69c84cc
[py] Add bidi tests for log, errors and a few integration tests
AutomatedTester b150837
Add script tests
AutomatedTester 06747cb
Correct tests
AutomatedTester ed37820
fix lint
AutomatedTester 7f90819
Extend input tests
AutomatedTester 32d6277
Add more storage tests
AutomatedTester 9e848e5
Add more storage tests
AutomatedTester e6f35ba
Extend webextension tests
AutomatedTester 87af189
fixing comments
AutomatedTester 75fe432
fix comments
AutomatedTester 1bcbe17
Merge branch 'trunk' into bidi_py_tests_expandsion
AutomatedTester File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import pytest | ||
|
|
||
| from selenium.common.exceptions import InvalidArgumentException | ||
| from selenium.common.exceptions import WebDriverException | ||
| from selenium.webdriver.common.by import By | ||
|
|
||
|
|
||
| def test_errors_module_initialized(driver): | ||
| """Test that the errors module is accessible.""" | ||
| assert driver.script is not None | ||
|
|
||
|
|
||
| def test_invalid_browsing_context_id(driver): | ||
| """Test that invalid browsing context ID raises an error.""" | ||
| with pytest.raises(WebDriverException): | ||
| driver.browsing_context.close("invalid-context-id") | ||
|
|
||
|
|
||
| def test_invalid_script_evaluate(driver): | ||
| """Test that invalid script evaluation raises an error.""" | ||
| with pytest.raises(WebDriverException): | ||
| driver.script.evaluate("invalid javascript }{", await_promise=False) | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_invalid_navigation_url(driver): | ||
| """Test that invalid URL navigation raises an error.""" | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.browsing_context.navigate(None) | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_invalid_add_preload_script_no_function_declaration(driver): | ||
| """Test that adding preload script without proper format raises an error.""" | ||
| with pytest.raises((WebDriverException, InvalidArgumentException)): | ||
| driver.script.add_preload_script("not a valid script;}") | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_remove_nonexistent_user_context(driver): | ||
| """Test that removing non-existent user context raises an error.""" | ||
| with pytest.raises(WebDriverException): | ||
| driver.browser.remove_user_context("non-existent-context-id") | ||
|
|
||
|
|
||
| def test_invalid_call_function_parameters(driver, pages): | ||
| """Test that call_function with invalid parameters raises an error.""" | ||
| pages.load("blank.html") | ||
|
|
||
| # Try to call with invalid script | ||
| with pytest.raises(WebDriverException): | ||
| driver.script.call_function( | ||
| "invalid function }{", | ||
| [], | ||
| await_promise=False | ||
| ) | ||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def test_invalid_screenshot_clipping(driver, pages): | ||
| """Test that invalid screenshot clipping region raises an error.""" | ||
| pages.load("blank.html") | ||
| context_id = driver.current_context_id | ||
|
|
||
| # Try with invalid clipping region (negative dimensions) | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.browsing_context.capture_screenshot( | ||
| context_id, | ||
| clip={"x": 0, "y": 0, "width": -100, "height": 100} | ||
| ) | ||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def test_invalid_set_viewport_dimensions(driver, pages): | ||
| """Test that setting invalid viewport dimensions raises an error.""" | ||
| pages.load("blank.html") | ||
| context_id = driver.current_context_id | ||
|
|
||
| # Try with negative dimensions | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.browsing_context.set_viewport( | ||
| context_id, | ||
| viewport={"width": -1, "height": -1} | ||
| ) | ||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def test_invalid_set_cookie(driver, pages): | ||
| """Test that setting invalid cookie raises an error.""" | ||
| pages.load("blank.html") | ||
|
|
||
| # Try to set cookie with missing required fields | ||
| with pytest.raises((WebDriverException, TypeError, InvalidArgumentException)): | ||
| driver.storage.set_cookie(None) | ||
|
|
||
|
|
||
| def test_invalid_network_intercept_phase(driver): | ||
| """Test that invalid network intercept phase raises an error.""" | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.network.add_intercept( | ||
| phases=["invalid_phase"], | ||
| url_patterns=[] | ||
| ) | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_invalid_emulation_timezone(driver): | ||
| """Test that invalid timezone string raises an error.""" | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.emulation.set_timezone_override("Invalid/Timezone") | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_invalid_geolocation_coordinates(driver): | ||
| """Test that invalid geolocation coordinates raise an error.""" | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.emulation.set_geolocation_override( | ||
| latitude=999, # Invalid latitude | ||
| longitude=180 | ||
| ) | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_invalid_script_realm_type(driver): | ||
| """Test that invalid realm type raises an error.""" | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.script.get_realms(realm_type="invalid_realm_type") | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_protocol_error_with_invalid_session(driver): | ||
| """Test that operations on invalid session context raise errors.""" | ||
| # Try to use a context that doesn't exist | ||
| with pytest.raises(WebDriverException): | ||
| driver.browsing_context.navigate("https://www.example.com", context_id="nonexistent") | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_error_on_locate_nodes_with_invalid_selector(driver, pages): | ||
| """Test that invalid locator strategy raises an error.""" | ||
| pages.load("blank.html") | ||
| context_id = driver.current_context_id | ||
|
|
||
| # Try with invalid selector strategy | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.browsing_context.locate_nodes( | ||
| locator={"type": "invalid_strategy", "value": "test"}, | ||
| context_id=context_id | ||
| ) | ||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def test_error_on_perform_actions_invalid_action(driver, pages): | ||
| """Test that invalid action sequence raises an error.""" | ||
| pages.load("blank.html") | ||
|
|
||
| with pytest.raises((WebDriverException, InvalidArgumentException)): | ||
| driver.input.perform_actions(actions=None) | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_error_on_multiple_context_operations(driver): | ||
| """Test error handling with rapid context operations.""" | ||
| # Create a context | ||
| context1 = driver.browser.create_user_context() | ||
| assert context1 is not None | ||
|
|
||
| # Try to remove it immediately after (should succeed) | ||
| driver.browser.remove_user_context(context1) | ||
|
|
||
| # Try to remove again (should fail) | ||
| with pytest.raises(WebDriverException): | ||
| driver.browser.remove_user_context(context1) | ||
|
|
||
|
|
||
| class TestBidiErrorHandling: | ||
| """Test class for error handling in BiDi operations.""" | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def setup(self, driver, pages): | ||
| """Setup for each test in this class.""" | ||
| pages.load("blank.html") | ||
|
|
||
| def test_error_on_subscribe_invalid_event(self, driver): | ||
| """Test that subscribing to invalid event type raises error.""" | ||
| with pytest.raises((WebDriverException, ValueError)): | ||
| driver.session.subscribe(events=["invalid.event.type"]) | ||
|
|
||
| def test_error_on_unsubscribe_without_subscription(self, driver): | ||
| """Test that unsubscribing from non-existent subscription raises error.""" | ||
| with pytest.raises(WebDriverException): | ||
| driver.session.unsubscribe(events=["non.subscribed.event"]) | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
| def test_error_recovery_after_failed_navigation(self, driver): | ||
| """Test that driver can recover after failed navigation.""" | ||
| # First, try an invalid navigation | ||
| with pytest.raises(WebDriverException): | ||
| driver.browsing_context.navigate(None) | ||
|
|
||
|
AutomatedTester marked this conversation as resolved.
Outdated
|
||
| # Driver should still be functional | ||
| driver.get("about:blank") | ||
| assert driver.find_element(By.TAG_NAME, "body") is not None | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.