Skip to content

Commit 5db9c46

Browse files
committed
Expose #execute_cdp method for remote Chrome/Edge instances
1 parent 18c9454 commit 5db9c46

4 files changed

Lines changed: 42 additions & 6 deletions

File tree

rb/lib/selenium/webdriver/chrome/driver.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module Chrome
2727
#
2828

2929
class Driver < WebDriver::Driver
30-
EXTENSIONS = [DriverExtensions::HasNetworkConditions,
30+
EXTENSIONS = [DriverExtensions::HasCDP,
31+
DriverExtensions::HasNetworkConditions,
3132
DriverExtensions::HasNetworkInterception,
3233
DriverExtensions::HasWebStorage,
3334
DriverExtensions::HasLocation,
@@ -42,10 +43,6 @@ def browser
4243
:chrome
4344
end
4445

45-
def execute_cdp(cmd, **params)
46-
@bridge.send_command(cmd: cmd, params: params)
47-
end
48-
4946
private
5047

5148
def devtools_url

rb/lib/selenium/webdriver/common.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
require 'selenium/webdriver/common/driver_extensions/has_authentication'
6868
require 'selenium/webdriver/common/driver_extensions/has_logs'
6969
require 'selenium/webdriver/common/driver_extensions/has_log_events'
70+
require 'selenium/webdriver/common/driver_extensions/has_cdp'
7071
require 'selenium/webdriver/common/keys'
7172
require 'selenium/webdriver/common/profile_helper'
7273
require 'selenium/webdriver/common/options'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module DriverExtensions
23+
module HasCDP
24+
25+
#
26+
# Returns network conditions.
27+
#
28+
# @return [Hash]
29+
#
30+
31+
def execute_cdp(cmd, **params)
32+
@bridge.send_command(cmd: cmd, params: params)
33+
end
34+
35+
end # HasCDP
36+
end # DriverExtensions
37+
end # WebDriver
38+
end # Selenium

rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module Chrome
3939
# at least it doesn't crash
4040
end
4141

42-
it 'can execute CDP commands', only: {driver: :chrome} do
42+
it 'can execute CDP commands' do
4343
res = driver.execute_cdp('Page.addScriptToEvaluateOnNewDocument', source: 'window.was_here="TW";')
4444
expect(res).to have_key('identifier')
4545

0 commit comments

Comments
 (0)