From 5eaa6e48a02860eb4a239b9da1ff616f19dc15bc Mon Sep 17 00:00:00 2001 From: titusfortner Date: Fri, 24 Sep 2021 11:09:31 -0500 Subject: [PATCH] [rb] implement endpoint for deleting network conditions --- rb/lib/selenium/webdriver/chrome/features.rb | 5 +++++ .../driver_extensions/has_network_conditions.rb | 8 ++++++++ .../selenium/webdriver/chrome/driver_spec.rb | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/rb/lib/selenium/webdriver/chrome/features.rb b/rb/lib/selenium/webdriver/chrome/features.rb index 149d1c3ecd544..05161a42d8115 100644 --- a/rb/lib/selenium/webdriver/chrome/features.rb +++ b/rb/lib/selenium/webdriver/chrome/features.rb @@ -31,6 +31,7 @@ module Features stop_casting: [:post, 'session/:session_id/goog/cast/stop_casting'], get_network_conditions: [:get, 'session/:session_id/chromium/network_conditions'], set_network_conditions: [:post, 'session/:session_id/chromium/network_conditions'], + delete_network_conditions: [:delete, 'session/:session_id/chromium/network_conditions'], send_command: [:post, 'session/:session_id/goog/cdp/execute'], get_available_log_types: [:get, 'session/:session_id/se/log/types'], get_log: [:post, 'session/:session_id/se/log'] @@ -72,6 +73,10 @@ def network_conditions=(conditions) execute :set_network_conditions, {}, {network_conditions: conditions} end + def delete_network_conditions + execute :delete_network_conditions + end + def send_command(command_params) execute :send_command, {}, command_params end diff --git a/rb/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb b/rb/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb index bbc4de1ce6ab0..72e2df0d541eb 100644 --- a/rb/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +++ b/rb/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb @@ -45,6 +45,14 @@ def network_conditions=(conditions) @bridge.network_conditions = conditions end + # + # Resets Chromium network emulation settings. + # + + def delete_network_conditions + @bridge.delete_network_conditions + end + end # HasNetworkConditions end # DriverExtensions end # WebDriver diff --git a/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb b/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb index 31d5e1034add9..3d351e3a16297 100644 --- a/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb +++ b/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb @@ -126,6 +126,19 @@ module Chrome end end + it 'manages network features' do + driver.network_conditions = {offline: false, latency: 56, download_throughput: 789, upload_throughput: 600} + conditions = driver.network_conditions + expect(conditions['offline']).to eq false + expect(conditions['latency']).to eq 56 + expect(conditions['download_throughput']).to eq 789 + expect(conditions['upload_throughput']).to eq 600 + driver.delete_network_conditions + + error = /network conditions must be set before it can be retrieved/ + expect { driver.network_conditions }.to raise_error(Error::UnknownError, error) + end + # This requires cast sinks to run it 'casts' do # Does not get list correctly the first time for some reason