diff --git a/examples/ruby/Gemfile b/examples/ruby/Gemfile index 676ed770491c..4faeb52b6fa4 100644 --- a/examples/ruby/Gemfile +++ b/examples/ruby/Gemfile @@ -8,4 +8,4 @@ gem 'rspec', '~> 3.0' gem 'rubocop', '~> 1.35' gem 'rubocop-rspec', '~> 3.0' gem 'selenium-devtools', '= 0.127.0' -gem 'selenium-webdriver', '= 4.23.0' \ No newline at end of file +gem 'selenium-webdriver', '= 4.23.0' diff --git a/examples/ruby/Gemfile.lock b/examples/ruby/Gemfile.lock index e3d89fcfb2bb..4cab4baaa26d 100644 --- a/examples/ruby/Gemfile.lock +++ b/examples/ruby/Gemfile.lock @@ -62,6 +62,7 @@ GEM PLATFORMS arm64-darwin-21 arm64-darwin-22 + arm64-darwin-23 x86_64-darwin-19 x86_64-darwin-20 x86_64-darwin-22 diff --git a/examples/ruby/spec/interactions/alerts_spec.rb b/examples/ruby/spec/interactions/alerts_spec.rb index b2dd8ca218e0..b8337db2fcdc 100644 --- a/examples/ruby/spec/interactions/alerts_spec.rb +++ b/examples/ruby/spec/interactions/alerts_spec.rb @@ -4,4 +4,47 @@ RSpec.describe 'Alerts' do let(:driver) { start_session } + + before do + driver.navigate.to 'https://selenium.dev' + end + + it 'interacts with an alert' do + driver.execute_script 'alert("Hello, World!")' + + # Store the alert reference in a variable + alert = driver.switch_to.alert + + # Get the text of the alert + alert.text + + # Press on Cancel button + alert.dismiss + end + + it 'interacts with a confirm' do + driver.execute_script 'confirm("Are you sure?")' + + # Store the alert reference in a variable + alert = driver.switch_to.alert + + # Get the text of the alert + alert.text + + # Press on Cancel button + alert.dismiss + end + + it 'interacts with a prompt' do + driver.execute_script 'prompt("What is your name?")' + + # Store the alert reference in a variable + alert = driver.switch_to.alert + + # Type a message + alert.send_keys('selenium') + + # Press on Ok button + alert.accept + end end diff --git a/examples/ruby/spec/spec_helper.rb b/examples/ruby/spec/spec_helper.rb index 20273e7019c5..a79f81232d01 100644 --- a/examples/ruby/spec/spec_helper.rb +++ b/examples/ruby/spec/spec_helper.rb @@ -28,7 +28,9 @@ config.after { @driver&.quit } def start_session - @driver = Selenium::WebDriver.for :chrome + options = Selenium::WebDriver::Chrome::Options.new + options.add_argument('disable-search-engine-choice-screen') + @driver = Selenium::WebDriver.for(:chrome, options: options) end def start_bidi_session diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md index 8480fe78b79f..e25e08f9e721 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md @@ -57,18 +57,8 @@ string text = alert.Text; //Press the OK button alert.Accept(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See an example alert').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Store the alert text in a variable -alert_text = alert.text - -# Press on OK button -alert.accept + {{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L15-L22" >}} {{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L19-L21" >}} @@ -135,19 +125,9 @@ string text = alert.Text; //Press the Cancel button alert.Dismiss(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See a sample confirm').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Store the alert text in a variable -alert_text = alert.text - -# Press on Cancel button -alert.dismiss - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L28-L35" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L30-L32" >}} {{< /tab >}} @@ -212,19 +192,9 @@ alert.SendKeys("Selenium"); //Press the OK button alert.Accept(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See a sample prompt').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Type a message -alert.send_keys("selenium") - -# Press on Ok button -alert.accept - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L41-L48" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L42-L45" >}} {{< /tab >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md index 956fe747ad97..b1401ca2ffb3 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md @@ -52,19 +52,9 @@ string text = alert.Text; //Press the OK button alert.Accept(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See an example alert').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Store the alert text in a variable -alert_text = alert.text - -# Press on OK button -alert.accept - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L15-L22" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L19-L21" >}} {{< /tab >}} @@ -128,19 +118,9 @@ string text = alert.Text; //Press the Cancel button alert.Dismiss(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See a sample confirm').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Store the alert text in a variable -alert_text = alert.text - -# Press on Cancel button -alert.dismiss - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L28-L35" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L30-L32" >}} {{< /tab >}} @@ -202,19 +182,9 @@ alert.SendKeys("Selenium"); //Press the OK button alert.Accept(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See a sample prompt').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Type a message -alert.send_keys("selenium") - -# Press on Ok button -alert.accept - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L41-L48" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L42-L45" >}} {{< /tab >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md index 447964e861c6..9c30bda412d0 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md @@ -43,19 +43,9 @@ alert.accept(); {{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L12-L18" >}} {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See an example alert').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Store the alert text in a variable -alert_text = alert.text - -# Press on OK button -alert.accept - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L15-L22" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L19-L21" >}} {{< /tab >}} @@ -120,19 +110,9 @@ string text = alert.Text; //Press the Cancel button alert.Dismiss(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See a sample confirm').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Store the alert text in a variable -alert_text = alert.text - -# Press on Cancel button -alert.dismiss - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L28-L35" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L30-L32" >}} {{< /tab >}} @@ -196,19 +176,9 @@ alert.SendKeys("Selenium"); //Press the OK button alert.Accept(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See a sample prompt').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Type a message -alert.send_keys("selenium") - -# Press on Ok button -alert.accept - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L41-L48" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L42-L45" >}} {{< /tab >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md index cc21dfbef9bd..3aeafede61d0 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md @@ -49,19 +49,9 @@ string text = alert.Text; //Press the OK button alert.Accept(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See an example alert').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Store the alert text in a variable -alert_text = alert.text - -# Press on OK button -alert.accept - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L15-L22" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L19-L21" >}} {{< /tab >}} @@ -124,19 +114,9 @@ string text = alert.Text; //Press the Cancel button alert.Dismiss(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See a sample confirm').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Store the alert text in a variable -alert_text = alert.text - -# Press on Cancel button -alert.dismiss - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L28-L35" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L30-L32" >}} {{< /tab >}} @@ -197,19 +177,9 @@ alert.SendKeys("Selenium"); //Press the OK button alert.Accept(); {{< /tab >}} - {{< tab header="Ruby" >}} -# Click the link to activate the alert -driver.find_element(:link_text, 'See a sample prompt').click - -# Store the alert reference in a variable -alert = driver.switch_to.alert - -# Type a message -alert.send_keys("selenium") - -# Press on Ok button -alert.accept - {{< /tab >}} +{{< tab header="Ruby" text=true >}} +{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L41-L48" >}} +{{< /tab >}} {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L42-L45" >}} {{< /tab >}}