From 73d6bea82e522c957905a75aab7ef7b465384b85 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Fri, 24 Sep 2021 00:10:01 -0500 Subject: [PATCH] [py] implement chromium specific endpoint for deleting network conditions --- py/selenium/webdriver/chromium/remote_connection.py | 1 + py/selenium/webdriver/chromium/webdriver.py | 6 ++++++ .../webdriver/chrome/chrome_network_emulation_tests.py | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/py/selenium/webdriver/chromium/remote_connection.py b/py/selenium/webdriver/chromium/remote_connection.py index a1c89a94964c0..cf143e43785fa 100644 --- a/py/selenium/webdriver/chromium/remote_connection.py +++ b/py/selenium/webdriver/chromium/remote_connection.py @@ -25,6 +25,7 @@ def __init__(self, remote_server_addr, vendor_prefix, browser_name, keep_alive=T self._commands["launchApp"] = ('POST', '/session/$sessionId/chromium/launch_app') self._commands["setNetworkConditions"] = ('POST', '/session/$sessionId/chromium/network_conditions') self._commands["getNetworkConditions"] = ('GET', '/session/$sessionId/chromium/network_conditions') + self._commands["deleteNetworkConditions"] = ('DELETE', '/session/$sessionId/chromium/network_conditions') self._commands['executeCdpCommand'] = ('POST', '/session/$sessionId/{}/cdp/execute'.format(vendor_prefix)) self._commands['getSinks'] = ('GET', '/session/$sessionId/{}/cast/get_sinks'.format(vendor_prefix)) self._commands['getIssueMessage'] = ('GET', '/session/$sessionId/{}/cast/get_issue_message'.format(vendor_prefix)) diff --git a/py/selenium/webdriver/chromium/webdriver.py b/py/selenium/webdriver/chromium/webdriver.py index 9414acfe54bbe..6d36d4a63d0a9 100644 --- a/py/selenium/webdriver/chromium/webdriver.py +++ b/py/selenium/webdriver/chromium/webdriver.py @@ -139,6 +139,12 @@ def set_network_conditions(self, **network_conditions) -> NoReturn: 'network_conditions': network_conditions }) + def delete_network_conditions(self) -> NoReturn: + """ + Resets Chromium network emulation settings. + """ + self.execute("deleteNetworkConditions") + def execute_cdp_cmd(self, cmd: str, cmd_args: dict): """ Execute Chrome Devtools Protocol command and get returned result diff --git a/py/test/selenium/webdriver/chrome/chrome_network_emulation_tests.py b/py/test/selenium/webdriver/chrome/chrome_network_emulation_tests.py index 342bc76b32dac..d85298b1ca772 100755 --- a/py/test/selenium/webdriver/chrome/chrome_network_emulation_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_network_emulation_tests.py @@ -14,7 +14,9 @@ # 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 WebDriverException from selenium.webdriver import Chrome @@ -29,3 +31,6 @@ def test_network_conditions_emulation(): assert conditions['latency'] == 56 assert conditions['download_throughput'] == 789 assert conditions['upload_throughput'] == 789 + driver.delete_network_conditions() + with pytest.raises(WebDriverException): + driver.get_network_conditions()