Skip to content

Commit ef89c3a

Browse files
committed
[rb] split out tests into separate files and let the shortcode display the whole file
1 parent 3069735 commit ef89c3a

File tree

8 files changed

+105
-9
lines changed

8 files changed

+105
-9
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe 'Chrome Options' do
6+
it 'add arguments' do
7+
options = default_chrome_options
8+
9+
options.args << '--start-maximized'
10+
11+
@driver = Selenium::WebDriver.for :chrome, options: options
12+
end
13+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe 'Chrome Options' do
6+
it 'start session with basic options' do
7+
options = Selenium::WebDriver::Chrome::Options.new
8+
@driver = Selenium::WebDriver.for :chrome, options: options
9+
end
10+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe 'Chrome Options' do
6+
it 'sets location of binary' do
7+
options = default_chrome_options
8+
9+
options.binary = chrome_location
10+
11+
@driver = Selenium::WebDriver.for :chrome, options: options
12+
end
13+
14+
private
15+
16+
def chrome_location
17+
options = default_chrome_options
18+
service = Selenium::WebDriver::Service.chrome
19+
finder = Selenium::WebDriver::DriverFinder.new(options, service)
20+
ENV['CHROMEDRIVER_BIN'] = finder.driver_path
21+
ENV['CHROME_BIN'] = finder.browser_path
22+
end
23+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe 'Chrome Options' do
6+
it 'keeps browser open' do
7+
options = default_chrome_options
8+
9+
options.detach = true
10+
11+
@driver = Selenium::WebDriver.for :chrome, options: options
12+
end
13+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe 'Chrome Options' do
6+
it 'excludes switches' do
7+
options = default_chrome_options
8+
9+
options.exclude_switches << 'disable-popup-blocking'
10+
11+
@driver = Selenium::WebDriver.for :chrome, options: options
12+
end
13+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe 'Chrome Options' do
6+
it 'add extensions' do
7+
options = default_chrome_options
8+
9+
extension_file_path = File.expand_path('../../../spec_support/extensions/webextensions-selenium-example.crx',
10+
__dir__)
11+
options.add_extension(extension_file_path)
12+
13+
@driver = Selenium::WebDriver.for :chrome, options: options
14+
@driver.get('https://www.selenium.dev/selenium/web/blank.html')
15+
injected = @driver.find_element(:id, 'webextensions-selenium-example')
16+
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
17+
end
18+
end

website_and_docs/content/documentation/webdriver/browsers/chrome.en.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Starting a Chrome session with basic defined options looks like this:
3232
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L30-L31" >}}
3333
{{< /tab >}}
3434
{{< tab header="Ruby" >}}
35-
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L10-L11" >}}
35+
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/basic_spec.rb#L7-L8" >}}
3636
{{< /tab >}}
3737
{{< tab header="JavaScript" >}}
3838
{{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L51-L55">}}
@@ -64,7 +64,7 @@ Add an argument to options:
6464
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L39" >}}
6565
{{< /tab >}}
6666
{{< tab header="Ruby" >}}
67-
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L17" >}}
67+
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/arguments_spec.rb#L9" >}}
6868
{{< /tab >}}
6969
{{< tab header="JavaScript" >}}
7070
{{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L9-L12">}}
@@ -92,7 +92,7 @@ Add a browser location to options:
9292
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L49" >}}
9393
{{< /tab >}}
9494
{{< tab header="Ruby" >}}
95-
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L25" >}}
95+
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/binary_spec.rb#L9" >}}
9696
{{< /tab >}}
9797
{{< tab header="JavaScript" >}}
9898
{{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L41-L44">}}
@@ -121,7 +121,7 @@ Add an extension to options:
121121
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L61" >}}
122122
{{< /tab >}}
123123
{{< tab header="Ruby" >}}
124-
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L34" >}}
124+
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/extensions_spec.rb#L10" >}}
125125
{{< /tab >}}
126126
{{< tab header="JavaScript" >}}
127127
{{< 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.
147147
**Note**: This is already the default behavior in .NET.
148148
{{% /tab %}}
149149
{{< tab header="Ruby" >}}
150-
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L45" >}}
150+
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/detach_spec.rb#L9" >}}
151151
{{< /tab >}}
152152
{{< tab header="JavaScript" >}}
153153
{{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L29-L32">}}
@@ -178,7 +178,7 @@ Set excluded arguments on options:
178178
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs#L76" >}}
179179
{{< /tab >}}
180180
{{< tab header="Ruby" >}}
181-
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L53" >}}
181+
{{< gh-codeblock path="/examples/ruby/spec/browsers/chrome/options/exclude_switches_spec.rb#L9" >}}
182182
{{< /tab >}}
183183
{{< tab header="JavaScript" >}}
184184
{{< gh-codeblock path="/examples/javascript/test/browser/chromeSpecificCaps.spec.js#L19-L22">}}

website_and_docs/layouts/shortcodes/gh-codeblock.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
{{ $fullPath := .Get "path" }}
2323
{{ $path := index (split $fullPath "#") 0 }}
24+
{{ $hasFragment := in $fullPath "#" }}
2425

2526
{{ $apiUrl := printf "%s/%s/%s/contents%s?ref=%s" $apiBaseUrl $org $repo $path $branch }}
2627
{{ $webUrl := printf "%s/%s/%s/blob/%s/%s" $webBaseUrl $org $repo $branch $fullPath }}
@@ -50,6 +51,13 @@
5051

5152
{{ highlight $codeSnippet $language }}
5253

54+
{{ if $hasFragment }}
55+
<details class="mt-2">
56+
<summary>Show full example</summary>
57+
<div class="pt-2">{{ highlight $content $language }}</div>
58+
</details>
59+
{{ end }}
60+
5361
<div class="text-end pb-2">
5462
<a href="{{- $webUrl -}}" target="_blank">
5563
<i class="fas fa-external-link-alt pl-2"></i>
@@ -58,6 +66,4 @@
5866
</div>
5967
{{ else }}
6068
{{ partial "github-content.html" }}
61-
{{ end }}
62-
63-
69+
{{ end }}

0 commit comments

Comments
 (0)