diff --git a/.skipped-tests b/.skipped-tests index 3262c35fda88a..4ddbb8327e7d9 100644 --- a/.skipped-tests +++ b/.skipped-tests @@ -22,29 +22,4 @@ -//javascript/selenium-webdriver:test-builder-test.js-chrome -//javascript/selenium-webdriver:test-chrome-devtools-test.js-chrome -//javascript/selenium-webdriver:test-firefox-options-test.js-firefox --//rb/spec/integration/selenium/webdriver/chrome:service-chrome --//rb/spec/integration/selenium/webdriver/chrome:service-chrome-bidi --//rb/spec/integration/selenium/webdriver/chrome:service-chrome-remote --//rb/spec/integration/selenium/webdriver/edge:service-edge --//rb/spec/integration/selenium/webdriver/edge:service-edge-bidi --//rb/spec/integration/selenium/webdriver/edge:service-edge-remote --//rb/spec/integration/selenium/webdriver/firefox:driver-firefox-beta-bidi --//rb/spec/integration/selenium/webdriver/firefox:service-firefox --//rb/spec/integration/selenium/webdriver/firefox:service-firefox-beta --//rb/spec/integration/selenium/webdriver/firefox:service-firefox-beta-bidi --//rb/spec/integration/selenium/webdriver/firefox:service-firefox-beta-remote --//rb/spec/integration/selenium/webdriver/firefox:service-firefox-bidi --//rb/spec/integration/selenium/webdriver/firefox:service-firefox-remote --//rb/spec/integration/selenium/webdriver/remote:driver-chrome-remote --//rb/spec/integration/selenium/webdriver/remote:driver-edge-remote --//rb/spec/integration/selenium/webdriver/remote:driver-firefox-beta-remote --//rb/spec/integration/selenium/webdriver/remote:driver-firefox-remote --//rb/spec/integration/selenium/webdriver/remote:element-chrome-remote --//rb/spec/integration/selenium/webdriver/remote:element-edge-remote --//rb/spec/integration/selenium/webdriver/remote:element-firefox-beta-remote --//rb/spec/integration/selenium/webdriver/remote:element-firefox-remote --//rb/spec/integration/selenium/webdriver:element-chrome --//rb/spec/integration/selenium/webdriver:element-chrome-bidi --//rb/spec/integration/selenium/webdriver:element-chrome-remote --//rb/spec/integration/selenium/webdriver:action_builder-firefox-beta-remote -//rb:lint diff --git a/rb/lib/selenium/webdriver/common/websocket_connection.rb b/rb/lib/selenium/webdriver/common/websocket_connection.rb index 26f02ebc9bf1c..69297d0f98728 100644 --- a/rb/lib/selenium/webdriver/common/websocket_connection.rb +++ b/rb/lib/selenium/webdriver/common/websocket_connection.rb @@ -94,21 +94,27 @@ def attach_socket_listener Thread.current.abort_on_exception = true Thread.current.report_on_exception = false - until socket.eof? - incoming_frame << socket.readpartial(1024) - - while (frame = incoming_frame.next) - message = process_frame(frame) - next unless message['method'] - - params = message['params'] - callbacks[message['method']].each do |callback| - @callback_threads.add(callback_thread(params, &callback)) - end - end + read_and_process_frames until socket.eof? + rescue *CONNECTION_ERRORS => e + WebDriver.logger.debug("BiDi socket closed: #{e.class} - #{e.message}", id: :websocket) + Thread.exit + rescue StandardError => e + WebDriver.logger.debug("Unexpected error in BiDi socket thread: #{e.class} - #{e.message}", id: :websocket) + Thread.exit + end + end + + def read_and_process_frames + incoming_frame << socket.readpartial(1024) + + while (frame = incoming_frame.next) + message = process_frame(frame) + next unless message['method'] + + params = message['params'] + callbacks[message['method']].each do |callback| + @callback_threads.add(callback_thread(params, &callback)) end - rescue *CONNECTION_ERRORS - Thread.stop end end @@ -142,7 +148,7 @@ def callback_thread(params) yield params rescue Error::WebDriverError, *CONNECTION_ERRORS - Thread.stop + Thread.exit end end diff --git a/rb/spec/integration/selenium/webdriver/BUILD.bazel b/rb/spec/integration/selenium/webdriver/BUILD.bazel index c420436e6bdbd..69813b7c1e5e2 100644 --- a/rb/spec/integration/selenium/webdriver/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/BUILD.bazel @@ -42,14 +42,31 @@ rb_library( "driver_spec.rb", "devtools_spec.rb", "element_spec.rb", + "network_spec.rb", ], ) ] +rb_integration_test( + name = "network", + srcs = ["network_spec.rb"], + tags = [ + "exclusive-if-local", + "bidi-only", + ], + deps = [ + "//rb/lib/selenium/devtools", + "//rb/lib/selenium/webdriver:bidi", + ], +) + rb_integration_test( name = "bidi", srcs = ["bidi_spec.rb"], - tags = ["exclusive-if-local"], + tags = [ + "exclusive-if-local", + "bidi-only", + ], deps = [ "//rb/lib/selenium/devtools", "//rb/lib/selenium/webdriver:bidi", diff --git a/rb/spec/integration/selenium/webdriver/action_builder_spec.rb b/rb/spec/integration/selenium/webdriver/action_builder_spec.rb index 99ce2fa689e9e..c693d0fa088f3 100644 --- a/rb/spec/integration/selenium/webdriver/action_builder_spec.rb +++ b/rb/spec/integration/selenium/webdriver/action_builder_spec.rb @@ -321,7 +321,7 @@ module WebDriver describe '#scroll_by' do it 'scrolls by given amount', - exclude: {driver: :firefox, reason: 'inconsistent behavior between versions'} do + exclude: {browser: :firefox, reason: 'inconsistent behavior between versions'} do driver.navigate.to url_for('scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html') footer = driver.find_element(tag_name: 'footer') delta_y = footer.rect.y.round diff --git a/rb/spec/integration/selenium/webdriver/bidi/BUILD.bazel b/rb/spec/integration/selenium/webdriver/bidi/BUILD.bazel index 4b317a1a7929a..1f81be877febb 100644 --- a/rb/spec/integration/selenium/webdriver/bidi/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/bidi/BUILD.bazel @@ -4,7 +4,10 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], - tags = ["exclusive-if-local"], + tags = [ + "exclusive-if-local", + "bidi-only", + ], deps = [ "//rb/lib/selenium/devtools", "//rb/lib/selenium/webdriver:bidi", diff --git a/rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel b/rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel index bd2441d4b2e56..751b255e36c15 100644 --- a/rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel @@ -4,7 +4,20 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], - browsers = ["chrome"], # No need to run in other browsers. + browsers = ["chrome"], + ) + for file in glob( + ["*_spec.rb"], + exclude = ["service_spec.rb"], ) - for file in glob(["*_spec.rb"]) ] + +rb_integration_test( + name = "service", + srcs = ["service_spec.rb"], + browsers = ["chrome"], + tags = [ + "no-grid", + "skip-rbe", # RBE needs internet + ], +) diff --git a/rb/spec/integration/selenium/webdriver/devtools_spec.rb b/rb/spec/integration/selenium/webdriver/devtools_spec.rb index 4506ecbbed5a1..0129d79d9befb 100644 --- a/rb/spec/integration/selenium/webdriver/devtools_spec.rb +++ b/rb/spec/integration/selenium/webdriver/devtools_spec.rb @@ -21,8 +21,7 @@ module Selenium module WebDriver - describe DevTools, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, - {browser: %i[chrome edge]}] do + describe DevTools, exclusive: {browser: %i[chrome edge]} do after { |example| reset_driver!(example: example) } it 'sends commands' do diff --git a/rb/spec/integration/selenium/webdriver/edge/BUILD.bazel b/rb/spec/integration/selenium/webdriver/edge/BUILD.bazel index 73f983fef259a..d15613f5fb625 100644 --- a/rb/spec/integration/selenium/webdriver/edge/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/edge/BUILD.bazel @@ -4,7 +4,20 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], - browsers = ["edge"], # No need to run in other browsers. + browsers = ["edge"], + ) + for file in glob( + ["*_spec.rb"], + exclude = ["service_spec.rb"], ) - for file in glob(["*_spec.rb"]) ] + +rb_integration_test( + name = "service", + srcs = ["service_spec.rb"], + browsers = ["edge"], + tags = [ + "no-grid", + "skip-rbe", # RBE needs internet + ], +) diff --git a/rb/spec/integration/selenium/webdriver/edge/sample.crx b/rb/spec/integration/selenium/webdriver/edge/sample.crx deleted file mode 100644 index 15147dd01f3d8..0000000000000 Binary files a/rb/spec/integration/selenium/webdriver/edge/sample.crx and /dev/null differ diff --git a/rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel b/rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel index 6cb37b594a5fb..d455f24f60f1b 100644 --- a/rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel @@ -11,5 +11,21 @@ load("//rb/spec:tests.bzl", "rb_integration_test") ], data = ["//common/extensions"], ) - for file in glob(["*_spec.rb"]) + for file in glob( + ["*_spec.rb"], + exclude = ["service_spec.rb"], + ) ] + +rb_integration_test( + name = "service", + srcs = ["service_spec.rb"], + browsers = [ + "firefox", + "firefox-beta", + ], + tags = [ + "no-grid", + "skip-rbe", # RBE needs internet + ], +) diff --git a/rb/spec/integration/selenium/webdriver/ie/BUILD.bazel b/rb/spec/integration/selenium/webdriver/ie/BUILD.bazel new file mode 100644 index 0000000000000..2fc5c4e6e3deb --- /dev/null +++ b/rb/spec/integration/selenium/webdriver/ie/BUILD.bazel @@ -0,0 +1,8 @@ +load("//rb/spec:tests.bzl", "rb_integration_test") + +rb_integration_test( + name = "service", + srcs = ["service_spec.rb"], + browsers = ["ie"], + tags = ["no-grid"], +) diff --git a/rb/spec/integration/selenium/webdriver/remote/BUILD.bazel b/rb/spec/integration/selenium/webdriver/remote/BUILD.bazel index 7c4b21bda53c0..a45e4beb0d2ab 100644 --- a/rb/spec/integration/selenium/webdriver/remote/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/remote/BUILD.bazel @@ -4,6 +4,7 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], + tags = ["grid-only"], ) for file in glob(["*_spec.rb"]) ] diff --git a/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb b/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb index bd6a5a200fa82..38d8ec706f40f 100644 --- a/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb +++ b/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb @@ -42,7 +42,9 @@ module Remote wait.until { driver.find_element(id: 'upload_label').displayed? } driver.switch_to.frame('upload_target') - wait.until { driver.find_element(xpath: '//body') } + wait(ignore: [Error::NoSuchElementError, Error::StaleElementReferenceError]).until do + !driver.find_element(xpath: '//body').text.empty? + end body = driver.find_element(xpath: '//body') expect(body.text.scan('This is a dummy test file').count).to eq(1) @@ -83,8 +85,7 @@ module Remote end end - it 'errors when not set', {except: {browser: :firefox, reason: 'grid always sets true and firefox returns it'}, - exclude: {browser: :safari, reason: 'grid hangs'}} do + it 'errors when not set', {exclude: {browser: :safari, reason: 'grid hangs'}} do reset_driver!(enable_downloads: false) do |driver| expect { driver.downloadable_files diff --git a/rb/spec/integration/selenium/webdriver/safari/BUILD.bazel b/rb/spec/integration/selenium/webdriver/safari/BUILD.bazel index 54d03e20334c8..4848dbefa3ad2 100644 --- a/rb/spec/integration/selenium/webdriver/safari/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/safari/BUILD.bazel @@ -10,5 +10,18 @@ load("//rb/spec:tests.bzl", "rb_integration_test") "safari-preview", ], ) - for file in glob(["*_spec.rb"]) + for file in glob( + ["*_spec.rb"], + exclude = ["service_spec.rb"], + ) ] + +rb_integration_test( + name = "service", + srcs = ["service_spec.rb"], + browsers = [ + "safari", + "safari-preview", + ], + tags = ["no-grid"], +) diff --git a/rb/spec/integration/selenium/webdriver/spec_support/helpers.rb b/rb/spec/integration/selenium/webdriver/spec_support/helpers.rb index c0894380926c6..f3a90e82e7a09 100644 --- a/rb/spec/integration/selenium/webdriver/spec_support/helpers.rb +++ b/rb/spec/integration/selenium/webdriver/spec_support/helpers.rb @@ -97,8 +97,8 @@ def wait_for_new_url(old_url) end end - def wait(timeout = 10) - Wait.new(timeout: timeout) + def wait(timeout = 10, **opts) + Wait.new(timeout: timeout, **opts) end def png_size(path) diff --git a/rb/spec/integration/selenium/webdriver/spec_support/rack_server.rb b/rb/spec/integration/selenium/webdriver/spec_support/rack_server.rb index d141d536b9c37..7a7499e93f207 100644 --- a/rb/spec/integration/selenium/webdriver/spec_support/rack_server.rb +++ b/rb/spec/integration/selenium/webdriver/spec_support/rack_server.rb @@ -107,7 +107,7 @@ def call(env) case env['PATH_INFO'] when '/upload' req = Rack::Request.new(env) - body = case req['upload'] + body = case req.params['upload'] when Array req.params['upload'].map { |upload| upload[:tempfile].read }.join("\n") when Hash diff --git a/rb/spec/tests.bzl b/rb/spec/tests.bzl index 7004d184b2494..bf5c03f5ef54f 100644 --- a/rb/spec/tests.bzl +++ b/rb/spec/tests.bzl @@ -14,6 +14,8 @@ BROWSERS = { "deps": ["//rb/lib/selenium/webdriver:chrome"], "tags": [], "target_compatible_with": [], + "bidi_supported": True, + "devtools_supported": True, "env": { "WD_REMOTE_BROWSER": "chrome", "WD_SPEC_DRIVER": "chrome", @@ -37,6 +39,8 @@ BROWSERS = { "deps": ["//rb/lib/selenium/webdriver:edge"], "tags": [], "target_compatible_with": [], + "bidi_supported": True, + "devtools_supported": True, "env": { "WD_REMOTE_BROWSER": "edge", "WD_SPEC_DRIVER": "edge", @@ -60,6 +64,7 @@ BROWSERS = { "deps": ["//rb/lib/selenium/webdriver:firefox"], "tags": [], "target_compatible_with": [], + "bidi_supported": True, "env": { "WD_REMOTE_BROWSER": "firefox", "WD_SPEC_DRIVER": "firefox", @@ -83,6 +88,7 @@ BROWSERS = { "deps": ["//rb/lib/selenium/webdriver:firefox"], "tags": [], "target_compatible_with": [], + "bidi_supported": True, "env": { "WD_REMOTE_BROWSER": "firefox", "WD_SPEC_DRIVER": "firefox", @@ -149,63 +155,69 @@ def rb_integration_test(name, srcs, deps = [], data = [], browsers = BROWSERS.ke visibility = ["//rb:__subpackages__"], ) + VARIANTS = [ + {"suffix": "", "remote": False, "bidi": False}, + {"suffix": "-remote", "remote": True, "bidi": False}, + {"suffix": "-bidi", "remote": False, "bidi": True}, + {"suffix": "-bidi-remote", "remote": True, "bidi": True}, + ] + for browser in browsers: - # Generate a test target for local browser execution. - rb_test( - name = "{}-{}".format(name, browser), - size = "large", - srcs = srcs, - args = ["rb/spec/"], - data = BROWSERS[browser]["data"] + data + ["//common/src/web"], - env = BROWSERS[browser]["env"], - main = "@bundle//bin:rspec", - tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + [browser], - deps = ["//rb/spec/integration/selenium/webdriver:spec_helper"] + BROWSERS[browser]["deps"] + deps, - visibility = ["//rb:__subpackages__"], - target_compatible_with = BROWSERS[browser]["target_compatible_with"], - ) + config = BROWSERS[browser] + for variant in VARIANTS: + bidi_not_supported = variant["bidi"] and not config.get("bidi_supported", False) + devtools_not_supported = "needs-devtools" in tags and not config.get("devtools_supported", False) + excluded_by_bidi = "bidi-only" in tags and not variant["bidi"] + excluded_by_grid = "remote-only" in tags and not variant["remote"] + excluded_by_local = "no-grid" in tags and variant["remote"] - # Generate a test target for remote browser execution (Grid). - rb_test( - name = "{}-{}-remote".format(name, browser), - size = "large", - srcs = srcs, - args = ["rb/spec/"], - data = BROWSERS[browser]["data"] + data + [ - "//common/src/web", - "//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar", - "//rb/spec:java-location", - "@bazel_tools//tools/jdk:current_java_runtime", - ], - env = BROWSERS[browser]["env"] | { - "WD_BAZEL_JAVA_LOCATION": "$(rootpath //rb/spec:java-location)", - "WD_SPEC_DRIVER": "remote", - }, - main = "@bundle//bin:rspec", - tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + ["{}-remote".format(browser)], - deps = ["//rb/spec/integration/selenium/webdriver:spec_helper"] + BROWSERS[browser]["deps"] + deps, - visibility = ["//rb:__subpackages__"], - target_compatible_with = BROWSERS[browser]["target_compatible_with"], - ) + if bidi_not_supported or devtools_not_supported or excluded_by_bidi or excluded_by_grid or excluded_by_local: + continue + + target_name = "{}-{}{}".format(name, browser, variant["suffix"]) + + env = config["env"] + if variant["remote"]: + env = env | { + "WD_SPEC_DRIVER": "remote", + "WD_BAZEL_JAVA_LOCATION": "$(rootpath //rb/spec:java-location)", + } + if variant["bidi"]: + env = env | { + "WEBDRIVER_BIDI": "true" + } + + test_data = config["data"] + data + ["//common/src/web"] + if variant["remote"]: + test_data += [ + "//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar", + "//rb/spec:java-location", + "@bazel_tools//tools/jdk:current_java_runtime", + ] + + test_deps = [ + "//rb/spec/integration/selenium/webdriver:spec_helper" + ] + config["deps"] + deps + if variant["bidi"]: + test_deps.append("//rb/lib/selenium/webdriver:bidi") + + test_tags = COMMON_TAGS + config["tags"] + tags + [browser] + if variant["bidi"]: + test_tags.append("bidi") - # Generate a test target for bidi browser execution. - rb_test( - name = "{}-{}-bidi".format(name, browser), - size = "large", - srcs = srcs, - args = ["rb/spec/"], - data = BROWSERS[browser]["data"] + data + ["//common/src/web"], - env = BROWSERS[browser]["env"] | {"WEBDRIVER_BIDI": "true"}, - main = "@bundle//bin:rspec", - tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + ["{}-bidi".format(browser)], - deps = depset( - ["//rb/spec/integration/selenium/webdriver:spec_helper", "//rb/lib/selenium/webdriver:bidi"] + - BROWSERS[browser]["deps"] + - deps, - ), - visibility = ["//rb:__subpackages__"], - target_compatible_with = BROWSERS[browser]["target_compatible_with"], - ) + rb_test( + name = target_name, + size = "large", + srcs = srcs, + args = ["rb/spec/integration"], + data = test_data, + env = env, + main = "@bundle//bin:rspec", + tags = test_tags, + deps = depset(test_deps), + visibility = ["//rb:__subpackages__"], + target_compatible_with = config["target_compatible_with"], + ) def rb_unit_test(name, srcs, deps, data = []): rb_test(