From 0404d8bdcb706ad5f0488e0ba2f5062fe65f5119 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 17 Apr 2025 22:09:25 -0700 Subject: [PATCH 1/7] [rb] do not reference spec_helper in documentation --- .../getting_started/using_selenium_spec.rb | 21 +++++++++---------- .../getting_started/using_selenium.en.md | 6 +++--- .../getting_started/using_selenium.ja.md | 6 +++--- .../getting_started/using_selenium.pt-br.md | 6 +++--- .../getting_started/using_selenium.zh-cn.md | 6 +++--- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/examples/ruby/spec/getting_started/using_selenium_spec.rb b/examples/ruby/spec/getting_started/using_selenium_spec.rb index f972389fca0b..0019c64bc210 100644 --- a/examples/ruby/spec/getting_started/using_selenium_spec.rb +++ b/examples/ruby/spec/getting_started/using_selenium_spec.rb @@ -1,29 +1,28 @@ # frozen_string_literal: true -require 'spec_helper' require 'selenium-webdriver' RSpec.describe 'Using Selenium' do - before do - @driver = Selenium::WebDriver.for :chrome - end - it 'uses eight components' do - @driver.get('https://www.selenium.dev/selenium/web/web-form.html') + driver = Selenium::WebDriver.for :chrome - title = @driver.title + driver.get('https://www.selenium.dev/selenium/web/web-form.html') + + title = driver.title expect(title).to eq('Web form') - @driver.manage.timeouts.implicit_wait = 500 + driver.manage.timeouts.implicit_wait = 500 - text_box = @driver.find_element(name: 'my-text') - submit_button = @driver.find_element(tag_name: 'button') + text_box = driver.find_element(name: 'my-text') + submit_button = driver.find_element(tag_name: 'button') text_box.send_keys('Selenium') submit_button.click - message = @driver.find_element(id: 'message') + message = driver.find_element(id: 'message') value = message.text expect(value).to eq('Received!') + + driver.quit end end diff --git a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.en.md b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.en.md index f2641c0136b7..c9024642d85e 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.en.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.en.md @@ -152,7 +152,7 @@ In your project's `package.json`, add requirement to `dependencies`: {{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs#L19-L20" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L14-L15" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L11-L12" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/runningTests.spec.js#L14-L15" >}} @@ -194,11 +194,11 @@ In your project's `package.json`, add requirement to `dependencies`: ### Set Up -{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L7-L9" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L7" >}} ### Tear Down -{{< gh-codeblock path="examples/ruby/spec/spec_helper.rb#L30" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L26" >}} {{% /tab %}} {{< tab header="JavaScript" >}} diff --git a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.ja.md b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.ja.md index e69f82b69732..01eeedf03c1d 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.ja.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.ja.md @@ -141,7 +141,7 @@ Seleniumコードの使用方法に関係なく、優れた統合開発環境が {{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs#L19-L20" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L14-L15" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L11-L12" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/runningTests.spec.js#L14-L15" >}} @@ -184,11 +184,11 @@ Seleniumコードの使用方法に関係なく、優れた統合開発環境が ### 並べる -{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L7-L9" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L7" >}} ### 取り壊す -{{< gh-codeblock path="examples/ruby/spec/spec_helper.rb#L30" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L26" >}} {{% /tab %}} {{< tab header="JavaScript" >}} diff --git a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.pt-br.md b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.pt-br.md index 8281f5211e32..362e63cfac58 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.pt-br.md @@ -146,7 +146,7 @@ In your project's `package.json`, adicionar requisito às `dependências`: {{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs#L19-L20" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L14-L15" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L11-L12" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/runningTests.spec.js#L14-L15" >}} @@ -188,11 +188,11 @@ In your project's `package.json`, adicionar requisito às `dependências`: ### Set Up -{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L7-L9" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L7" >}} ### Tear Down -{{< gh-codeblock path="examples/ruby/spec/spec_helper.rb#L30" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L26" >}} {{% /tab %}} {{< tab header="JavaScript" >}} diff --git a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.zh-cn.md b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.zh-cn.md index eb0e813823d4..977c7e9c8fa8 100644 --- a/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/getting_started/using_selenium.zh-cn.md @@ -130,7 +130,7 @@ In your project's `package.json`, add requirement to `dependencies`: {{< gh-codeblock path="examples/dotnet/SeleniumDocs/GettingStarted/UsingSeleniumTest.cs#L19-L20" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L14-L15" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L11-L12" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="examples/javascript/test/getting_started/runningTests.spec.js#L14-L15" >}} @@ -172,11 +172,11 @@ In your project's `package.json`, add requirement to `dependencies`: ### Set Up -{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L7-L9" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L7" >}} ### Tear Down -{{< gh-codeblock path="examples/ruby/spec/spec_helper.rb#L30" >}} +{{< gh-codeblock path="examples/ruby/spec/getting_started/using_selenium_spec.rb#L26" >}} {{% /tab %}} {{< tab header="JavaScript" >}} From 2bbd06c732034585af93d8b23f26c5e3eee196c5 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 17 Apr 2025 22:46:41 -0700 Subject: [PATCH 2/7] [rb] create default options to use when the implementation does not matter --- examples/ruby/spec/spec_helper.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/ruby/spec/spec_helper.rb b/examples/ruby/spec/spec_helper.rb index a68a4526f0be..80cc91c61522 100644 --- a/examples/ruby/spec/spec_helper.rb +++ b/examples/ruby/spec/spec_helper.rb @@ -30,19 +30,28 @@ config.after { @driver&.quit } def start_session - options = Selenium::WebDriver::Chrome::Options.new - options.add_argument('disable-search-engine-choice-screen') - options.add_argument('--no-sandbox') - @driver = Selenium::WebDriver.for(:chrome, options: options) + @service = Selenium::WebDriver::Service.chrome + @driver = Selenium::WebDriver.for :chrome, options: default_chrome_options end def start_bidi_session - options = Selenium::WebDriver::Chrome::Options.new(web_socket_url: true) + options = default_chrome_options + options.web_socket_url = true @driver = Selenium::WebDriver.for :chrome, options: options end + def default_chrome_options + options = Selenium::WebDriver::Chrome::Options.new + options.browser_version = 'stable' + options.timeouts = {implicit: 500} + options.add_argument('disable-search-engine-choice-screen') + options.add_argument('--no-sandbox') if Selenium::WebDriver::Platform.os == :linux + options + end + def start_firefox options = Selenium::WebDriver::Options.firefox(timeouts: {implicit: 1500}) + options.browser_version = 'stable' @driver = Selenium::WebDriver.for :firefox, options: options end end From 306973518037bbb9e005291219b7ca56121f8428 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 17 Apr 2025 16:41:12 -0700 Subject: [PATCH 3/7] [rb] fix logging spec linter issue --- examples/ruby/spec/bidi/logging_spec.rb | 2 ++ .../content/documentation/webdriver/bidi/logging.en.md | 8 ++++---- .../content/documentation/webdriver/bidi/logging.ja.md | 8 ++++---- .../content/documentation/webdriver/bidi/logging.pt-br.md | 8 ++++---- .../content/documentation/webdriver/bidi/logging.zh-cn.md | 8 ++++---- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/examples/ruby/spec/bidi/logging_spec.rb b/examples/ruby/spec/bidi/logging_spec.rb index b07b93342628..df010daae8e3 100644 --- a/examples/ruby/spec/bidi/logging_spec.rb +++ b/examples/ruby/spec/bidi/logging_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Logging' do diff --git a/website_and_docs/content/documentation/webdriver/bidi/logging.en.md b/website_and_docs/content/documentation/webdriver/bidi/logging.en.md index 312123ec9737..8817ed9ff209 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/logging.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/logging.en.md @@ -31,7 +31,7 @@ Record or take actions on `console.log` events. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L11" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L13" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -56,7 +56,7 @@ You need to store the ID returned when adding the handler to delete it. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L22-L23" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L24-L25" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -83,7 +83,7 @@ Record or take actions on JavaScript exception events. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L33" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L35" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -108,7 +108,7 @@ You need to store the ID returned when adding the handler to delete it. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L44-L45" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L46-L47" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/logging.ja.md b/website_and_docs/content/documentation/webdriver/bidi/logging.ja.md index ae23c7a6412b..77d1995aa327 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/logging.ja.md +++ b/website_and_docs/content/documentation/webdriver/bidi/logging.ja.md @@ -31,7 +31,7 @@ Record or take actions on `console.log` events. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L11" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L13" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -56,7 +56,7 @@ You need to store the ID returned when adding the handler to delete it. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L22-L23" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L24-L25" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -83,7 +83,7 @@ Record or take actions on JavaScript exception events. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L33" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L35" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -108,7 +108,7 @@ You need to store the ID returned when adding the handler to delete it. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L44-L45" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L46-L47" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/logging.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/logging.pt-br.md index 8109898135fd..402ea5f5e214 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/logging.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/bidi/logging.pt-br.md @@ -31,7 +31,7 @@ Record or take actions on `console.log` events. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L11" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L13" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -56,7 +56,7 @@ You need to store the ID returned when adding the handler to delete it. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L22-L23" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L24-L25" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -83,7 +83,7 @@ Record or take actions on JavaScript exception events. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L33" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L35" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -108,7 +108,7 @@ You need to store the ID returned when adding the handler to delete it. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L44-L45" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L46-L47" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/logging.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/logging.zh-cn.md index 8109898135fd..402ea5f5e214 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/logging.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/bidi/logging.zh-cn.md @@ -31,7 +31,7 @@ Record or take actions on `console.log` events. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L11" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L13" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -56,7 +56,7 @@ You need to store the ID returned when adding the handler to delete it. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L22-L23" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L24-L25" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -83,7 +83,7 @@ Record or take actions on JavaScript exception events. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L33" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L35" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} @@ -108,7 +108,7 @@ You need to store the ID returned when adding the handler to delete it. {{< badge-implementation >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L44-L45" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L46-L47" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< badge-implementation >}} From ef89c3a88dbf57b712921834a1fe742c3243a908 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 17 Apr 2025 22:24:19 -0700 Subject: [PATCH 4/7] [rb] split out tests into separate files and let the shortcode display the whole file --- .../browsers/chrome/options/arguments_spec.rb | 13 +++++++++++ .../browsers/chrome/options/basic_spec.rb | 10 ++++++++ .../browsers/chrome/options/binary_spec.rb | 23 +++++++++++++++++++ .../browsers/chrome/options/detach_spec.rb | 13 +++++++++++ .../chrome/options/exclude_switches_spec.rb | 13 +++++++++++ .../chrome/options/extensions_spec.rb | 18 +++++++++++++++ .../webdriver/browsers/chrome.en.md | 12 +++++----- .../layouts/shortcodes/gh-codeblock.html | 12 +++++++--- 8 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 examples/ruby/spec/browsers/chrome/options/arguments_spec.rb create mode 100644 examples/ruby/spec/browsers/chrome/options/basic_spec.rb create mode 100644 examples/ruby/spec/browsers/chrome/options/binary_spec.rb create mode 100644 examples/ruby/spec/browsers/chrome/options/detach_spec.rb create mode 100644 examples/ruby/spec/browsers/chrome/options/exclude_switches_spec.rb create mode 100644 examples/ruby/spec/browsers/chrome/options/extensions_spec.rb diff --git a/examples/ruby/spec/browsers/chrome/options/arguments_spec.rb b/examples/ruby/spec/browsers/chrome/options/arguments_spec.rb new file mode 100644 index 000000000000..a9ed66dbdcb4 --- /dev/null +++ b/examples/ruby/spec/browsers/chrome/options/arguments_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Chrome Options' do + it 'add arguments' do + options = default_chrome_options + + options.args << '--start-maximized' + + @driver = Selenium::WebDriver.for :chrome, options: options + end +end diff --git a/examples/ruby/spec/browsers/chrome/options/basic_spec.rb b/examples/ruby/spec/browsers/chrome/options/basic_spec.rb new file mode 100644 index 000000000000..db19fb819317 --- /dev/null +++ b/examples/ruby/spec/browsers/chrome/options/basic_spec.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Chrome Options' do + it 'start session with basic options' do + options = Selenium::WebDriver::Chrome::Options.new + @driver = Selenium::WebDriver.for :chrome, options: options + end +end diff --git a/examples/ruby/spec/browsers/chrome/options/binary_spec.rb b/examples/ruby/spec/browsers/chrome/options/binary_spec.rb new file mode 100644 index 000000000000..870f0e7cf801 --- /dev/null +++ b/examples/ruby/spec/browsers/chrome/options/binary_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Chrome Options' do + it 'sets location of binary' do + options = default_chrome_options + + options.binary = chrome_location + + @driver = Selenium::WebDriver.for :chrome, options: options + end + + private + + def chrome_location + options = default_chrome_options + service = Selenium::WebDriver::Service.chrome + finder = Selenium::WebDriver::DriverFinder.new(options, service) + ENV['CHROMEDRIVER_BIN'] = finder.driver_path + ENV['CHROME_BIN'] = finder.browser_path + end +end diff --git a/examples/ruby/spec/browsers/chrome/options/detach_spec.rb b/examples/ruby/spec/browsers/chrome/options/detach_spec.rb new file mode 100644 index 000000000000..d3d3c2779625 --- /dev/null +++ b/examples/ruby/spec/browsers/chrome/options/detach_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Chrome Options' do + it 'keeps browser open' do + options = default_chrome_options + + options.detach = true + + @driver = Selenium::WebDriver.for :chrome, options: options + end +end diff --git a/examples/ruby/spec/browsers/chrome/options/exclude_switches_spec.rb b/examples/ruby/spec/browsers/chrome/options/exclude_switches_spec.rb new file mode 100644 index 000000000000..c6f85a83618f --- /dev/null +++ b/examples/ruby/spec/browsers/chrome/options/exclude_switches_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Chrome Options' do + it 'excludes switches' do + options = default_chrome_options + + options.exclude_switches << 'disable-popup-blocking' + + @driver = Selenium::WebDriver.for :chrome, options: options + end +end diff --git a/examples/ruby/spec/browsers/chrome/options/extensions_spec.rb b/examples/ruby/spec/browsers/chrome/options/extensions_spec.rb new file mode 100644 index 000000000000..fa21474c8fa6 --- /dev/null +++ b/examples/ruby/spec/browsers/chrome/options/extensions_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Chrome Options' do + it 'add extensions' do + options = default_chrome_options + + extension_file_path = File.expand_path('../../../spec_support/extensions/webextensions-selenium-example.crx', + __dir__) + options.add_extension(extension_file_path) + + @driver = Selenium::WebDriver.for :chrome, options: options + @driver.get('https://www.selenium.dev/selenium/web/blank.html') + injected = @driver.find_element(:id, 'webextensions-selenium-example') + expect(injected.text).to eq 'Content injected by webextensions-selenium-example' + end +end diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md index 224c8bcbd3b5..65dc3081aaea 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md @@ -32,7 +32,7 @@ Starting a Chrome session with basic defined options looks like this: {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L30-L31" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L10-L11" >}} +{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/basic_spec.rb#L7-L8" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L51-L55">}} @@ -64,7 +64,7 @@ Add an argument to options: {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L39" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L17" >}} +{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/arguments_spec.rb#L9" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L9-L12">}} @@ -92,7 +92,7 @@ Add a browser location to options: {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L49" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L25" >}} +{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/binary_spec.rb#L9" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L41-L44">}} @@ -121,7 +121,7 @@ Add an extension to options: {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L61" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L34" >}} +{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/extensions_spec.rb#L10" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L62-L66">}} @@ -147,7 +147,7 @@ so long as the quit command is not sent to the driver. **Note**: This is already the default behavior in .NET. {{% /tab %}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L45" >}} +{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/detach_spec.rb#L9" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L29-L32">}} @@ -178,7 +178,7 @@ Set excluded arguments on options: {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L76" >}} {{< /tab >}} {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L53" >}} +{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/exclude_switches_spec.rb#L9" >}} {{< /tab >}} {{< tab header="JavaScript" >}} {{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L19-L22">}} diff --git a/website_and_docs/layouts/shortcodes/gh-codeblock.html b/website_and_docs/layouts/shortcodes/gh-codeblock.html index ca3073301620..ff7ce8e2ce88 100644 --- a/website_and_docs/layouts/shortcodes/gh-codeblock.html +++ b/website_and_docs/layouts/shortcodes/gh-codeblock.html @@ -21,6 +21,7 @@ {{ $fullPath := .Get "path" }} {{ $path := index (split $fullPath "#") 0 }} +{{ $hasFragment := in $fullPath "#" }} {{ $apiUrl := printf "%s/%s/%s/contents%s?ref=%s" $apiBaseUrl $org $repo $path $branch }} {{ $webUrl := printf "%s/%s/%s/blob/%s/%s" $webBaseUrl $org $repo $branch $fullPath }} @@ -50,6 +51,13 @@ {{ highlight $codeSnippet $language }} +{{ if $hasFragment }} +
+ Show full example +
{{ highlight $content $language }}
+
+{{ end }} + {{ else }} {{ partial "github-content.html" }} -{{ end }} - - +{{ end }} \ No newline at end of file From a8d6ffe7ee0e9bd79989a0cc6dfd93152a4247c0 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 17 Apr 2025 22:42:21 -0700 Subject: [PATCH 5/7] try to keep it all inside the tab --- .../layouts/shortcodes/gh-codeblock.html | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/website_and_docs/layouts/shortcodes/gh-codeblock.html b/website_and_docs/layouts/shortcodes/gh-codeblock.html index ff7ce8e2ce88..acd9785f8a26 100644 --- a/website_and_docs/layouts/shortcodes/gh-codeblock.html +++ b/website_and_docs/layouts/shortcodes/gh-codeblock.html @@ -49,20 +49,26 @@ {{ $codeSnippet = delimit (first $numOfLines (after $fromLine $splitContent)) "\n" }} {{ end }} - {{ highlight $codeSnippet $language }} +
+
+ {{ highlight $codeSnippet $language }} +
-{{ if $hasFragment }} -
- Show full example -
{{ highlight $content $language }}
-
-{{ end }} + {{ if $hasFragment }} +
+ Show full example +
+ {{ highlight $content $language }} +
+
+ {{ end }} -
{{ else }} {{ partial "github-content.html" }} From 2080bee675b809bac81de243ff05ba557c821cb2 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 17 Apr 2025 22:50:26 -0700 Subject: [PATCH 6/7] remove the div wrappers --- website_and_docs/layouts/shortcodes/gh-codeblock.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/website_and_docs/layouts/shortcodes/gh-codeblock.html b/website_and_docs/layouts/shortcodes/gh-codeblock.html index acd9785f8a26..ba77794c36dd 100644 --- a/website_and_docs/layouts/shortcodes/gh-codeblock.html +++ b/website_and_docs/layouts/shortcodes/gh-codeblock.html @@ -50,9 +50,7 @@ {{ end }}
-
- {{ highlight $codeSnippet $language }} -
+ {{ highlight $codeSnippet $language }} {{ if $hasFragment }}
From 1cd4dacad6d3615173da7e9914d1b31ef7528371 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 17 Apr 2025 23:11:25 -0700 Subject: [PATCH 7/7] try again --- .../layouts/shortcodes/gh-codeblock.html | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/website_and_docs/layouts/shortcodes/gh-codeblock.html b/website_and_docs/layouts/shortcodes/gh-codeblock.html index ba77794c36dd..ad4209ced0d5 100644 --- a/website_and_docs/layouts/shortcodes/gh-codeblock.html +++ b/website_and_docs/layouts/shortcodes/gh-codeblock.html @@ -39,15 +39,14 @@ {{ $content := base64Decode $apiResults.content }} {{ $codeSnippet := $content }} - {{ $parsedApiUrl := urls.Parse $webUrl }} - {{ with $parsedApiUrl.Fragment }} - {{ $codeLines := split $parsedApiUrl.Fragment "-" }} - {{ $fromLine := sub (int (replace (index $codeLines 0) "L" "")) 1 }} - {{ $toLine := int (cond (eq (len $codeLines) 1) (replace (index $codeLines 0) "L" "") (replace (index $codeLines 1) "L" "")) }} - {{ $numOfLines := cond (eq (sub $toLine $fromLine) 0) 1 (sub $toLine $fromLine) }} - {{ $splitContent := split $content "\n" }} - {{ $codeSnippet = delimit (first $numOfLines (after $fromLine $splitContent)) "\n" }} - {{ end }} +{{ if $hasFragment }} +{{ $fragment := index (split $fullPath "#") 1 }} +{{ $codeLines := split $fragment "-" }} +{{ $fromLine := sub (int (replace (index $codeLines 0) "L" "")) 1 }} +{{ $toLine := int (cond (eq (len $codeLines) 1) (replace (index $codeLines 0) "L" "") (replace (index $codeLines 1) "L" "")) }} +{{ $splitContent := split $content "\n" }} +{{ $codeSnippet = delimit (slice $splitContent $fromLine (add $toLine 1)) "\n" }} +{{ end }}
{{ highlight $codeSnippet $language }} @@ -55,7 +54,7 @@ {{ if $hasFragment }}
Show full example -
+
{{ highlight $content $language }}