Skip to content

Commit

Permalink
edge test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Apr 2, 2023
1 parent f83431d commit e316906
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/capybara/selenium/driver_specializations/edge_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ def cdp_unsupported_errors
end

def execute_cdp(cmd, params = {})
args = { cmd: cmd, params: params }
result = bridge.http.call(:post, "session/#{bridge.session_id}/goog/cdp/execute", args)
result['value']
if browser.respond_to? :execute_cdp
browser.execute_cdp(cmd, **params)
else
args = { cmd: cmd, params: params }
result = bridge.http.call(:post, "session/#{bridge.session_id}/ms/cdp/execute", args)
result['value']
end
end

def build_node(native_node, initial_cache = {})
Expand All @@ -115,7 +119,7 @@ def build_node(native_node, initial_cache = {})
def edgedriver_version
@edgedriver_version ||= begin
caps = browser.capabilities
caps['chrome']&.fetch('chromedriverVersion', nil).to_f
caps['msedge']&.fetch('msedgedriverVersion', nil).to_f
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions lib/capybara/selenium/nodes/edge_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ def visible?
end
end

def send_keys(*args)
args.chunk { |inp| inp.is_a?(String) && inp.match?(/\p{Emoji Presentation}/) }
.each do |contains_emoji, inputs|
if contains_emoji
inputs.join.grapheme_clusters.chunk { |gc| gc.match?(/\p{Emoji Presentation}/) }
.each do |emoji, clusters|
if emoji
driver.send(:execute_cdp, 'Input.insertText', text: clusters.join)
else
super(clusters.join)
end
end
else
super(*inputs)
end
end
end

private

def file_errors
Expand Down
8 changes: 6 additions & 2 deletions spec/selenium_spec_edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# ::Selenium::WebDriver.logger.level = "debug"
# If we don't create an options object the path set above won't be used
browser_options = Selenium::WebDriver::Edge::Options.new
browser_options.add_argument('--headless') if ENV['HEADLESS']

Capybara::Selenium::Driver.new(app, browser: :edge, options: browser_options).tap do |driver|
driver.browser
driver.download_path = Capybara.save_path
Expand All @@ -35,9 +37,11 @@ module TestSessions
Capybara::SpecHelper.run_specs TestSessions::SeleniumEdge, 'selenium', capybara_skip: skipped_tests do |example|
case example.metadata[:full_description]
when 'Capybara::Session selenium #attach_file with a block can upload by clicking the file input'
pending "EdgeChrome doesn't allow clicking on file inputs"
when /Capybara::Session selenium_chrome node #shadow_root should get visible text/
pending "Edge doesn't allow clicking on file inputs"
when /Capybara::Session selenium node #shadow_root should get visible text/
pending "Selenium doesn't currently support getting visible text for shadow root elements"
when /Capybara::Session selenium Capybara::Window#maximize/
pending "Edge headless doesn't support maximize" if ENV['HEADLESS']
end
end

Expand Down

0 comments on commit e316906

Please sign in to comment.