Skip to content

Commit

Permalink
update all the places where code needs to be moved into examples
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 14, 2023
1 parent f8319f9 commit b82db1d
Show file tree
Hide file tree
Showing 27 changed files with 1,024 additions and 58 deletions.
43 changes: 42 additions & 1 deletion website_and_docs/content/documentation/about/contributing.en.md
Expand Up @@ -44,7 +44,48 @@ If you are not sure about what you have found is an issue or not,
please ask through the communication channels described at
https://selenium.dev/support.

## Contributions
## What to Help With

### Moving Examples

Examples that need to be moved are marked with: {{% badge-examples %}}

We want to be able to run all of our code examples in the CI to ensure that people can copy and paste and
execute everything on the site. So we put the code where it belongs in the
[examples directory](https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/).
Each page in the documentation correlates to a test file in each of the languages, and should follow naming conventions.
For instance examples for this page https://www.selenium.dev/documentation/webdriver/browsers/chrome/ get added in these
files:
* `"/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java"`
* `"/examples/python/tests/browsers/test_chrome.py"`
* `"/examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs"`
* `"/examples/ruby/spec/browsers/chrome_spec.rb"`
* `"/examples/javascript/test/browser/chromeSpecificCaps.spec.js"`

Each example should get its own test. Ideally each test has an assertion that verifies the code works as intended.
Once the code is copied to its own test in the proper file, it needs to be referenced in the markdown file.

For example, the tab in Ruby would look like this:

{{</* tab header="Ruby" text=true */>}}
{{</* gh-codeblock path="/examples/ruby/spec/browsers/chrome_spec.rb#L8-L9" */>}}
{{</* /tab */>}}

The line numbers at the end represent only the line or lines of code that actually represent the item being displayed.
If a user wants more context, they can click the link to the github page that will show the full context.

Make sure the tab header includes `text=true`. By default, the tabs get formatted
for code, so to use markdown or other shortcode statements (like `gh-codeblock`) it needs to be declared as text.
For most examples, the `tabpane` declares the `text=true`, but if some of the tabs have code examples, the `tabpane`
cannot specify it, and it must be specified in the tabs that do not need automatic code formatting.

Make sure that if you add a test to the page that all the other line numbers in the markdown file are still
correct. Adding a test at the top of a page means updating every single reference in the documentation that has a line
number for that file.

Finally, make sure that the code is compatible with the latest version of Selenium, and the tests pass.

## Contribution Mechanics

The Selenium project welcomes new contributors. Individuals making
significant and valuable contributions over time are made _Committers_
Expand Down
1 change: 1 addition & 0 deletions website_and_docs/content/documentation/about/style.en.md
Expand Up @@ -106,6 +106,7 @@ and the code itself should be placed inside code tabs.
The Docsy code tabs look like this:

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
WebDriver driver = new ChromeDriver();
{{< /tab >}}
Expand Down
Expand Up @@ -15,6 +15,7 @@ Some applications make use of browser authentication to secure pages.
With Selenium, you can automate the input of basic auth credentials whenever they arise.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
Predicate<URI> uriPredicate = uri -> uri.getHost().contains("your-domain.com");

Expand Down Expand Up @@ -82,6 +83,7 @@ WebDriver BiDi when there are DOM mutations on a specific
element in the DOM.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
ChromeDriver driver = new ChromeDriver();

Expand Down Expand Up @@ -202,6 +204,7 @@ const assert = require("assert");
Listen to the `console.log` events and register callbacks to process the event.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
ChromeDriver driver = new ChromeDriver();
DevTools devTools = driver.getDevTools();
Expand Down Expand Up @@ -311,6 +314,7 @@ Listen to the JS Exceptions
and register callbacks to process the exception details.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
Expand Down Expand Up @@ -444,6 +448,7 @@ If you want to capture network events coming into the browser and you want manip
it with the following examples.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.devtools.HasDevTools;
Expand Down
Expand Up @@ -33,6 +33,7 @@ the geo-locations in the browser using Selenium. But with the help of Devtools,
we can easily emulate them. Below code snippet demonstrates that.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
ChromeDriver driver = new ChromeDriver();
DevTools devTools = driver.getDevTools();
Expand Down Expand Up @@ -127,6 +128,7 @@ fun main() {
## Emulate Geo Location with the Remote WebDriver:

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
ChromeOptions chromeOptions = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL("<grid-url>"), chromeOptions);
Expand Down Expand Up @@ -288,6 +290,7 @@ are required parameters. Optional parameters include scale, screenWidth,
screenHeight, positionX, positionY, dontSetVisible, screenOrientation, viewport, and displayFeature.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
ChromeDriver driver = new ChromeDriver();
DevTools devTools = driver.getDevTools();
Expand Down Expand Up @@ -432,6 +435,7 @@ fun kotlinOverridDeviceMode() {
Collect various performance metrics while navigating the application.

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
Expand Down
Expand Up @@ -100,9 +100,9 @@ Add a browser location to options:

There are several ways to work with Firefox profiles.

<div>
{{< badge-examples >}}
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
FirefoxProfile profile = new FirefoxProfile();
FirefoxOptions options = new FirefoxOptions();
Expand Down Expand Up @@ -147,7 +147,6 @@ options.profile = FirefoxProfile()
driver = FirefoxDriver(options)
{{< /tab >}}
{{< /tabpane >}}
</div>


## Service
Expand Down
Expand Up @@ -57,6 +57,7 @@ IE Driver will automatically locate Edge on your system.
So, if IE is not on the system, you only need:

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/InternetExplorerTest.java#46-L47" >}}
{{< /tab >}}
Expand All @@ -76,7 +77,6 @@ let driver = await new Builder()
.build();
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-examples >}}
val options = InternetExplorerOptions()
val driver = InternetExplorerDriver(options)
{{< /tab >}}
Expand All @@ -90,9 +90,8 @@ In some environments, Internet Explorer may timeout when opening the
File Upload dialog. IEDriver has a default timeout of 1000ms, but you
can increase the timeout using the fileUploadDialogTimeout capability.

<div>
{{< badge-examples >}}
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
InternetExplorerOptions options = new InternetExplorerOptions();
options.waitForUploadDialogUpTo(Duration.ofSeconds(2));
Expand Down Expand Up @@ -132,7 +131,6 @@ options.waitForUploadDialogUpTo(Duration.ofSeconds(2))
val driver = RemoteWebDriver(options)
{{< /tab >}}
{{< /tabpane >}}
</div>

### ensureCleanSession

Expand All @@ -147,9 +145,8 @@ gets cleared before launching the IE browser.

This capability accepts a Boolean value as parameter.

<div>
{{< badge-examples >}}
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
InternetExplorerOptions options = new InternetExplorerOptions();
options.destructivelyEnsureCleanSession();
Expand Down Expand Up @@ -189,7 +186,6 @@ options.destructivelyEnsureCleanSession()
val driver = RemoteWebDriver(options)
{{< /tab >}}
{{< /tabpane >}}
</div>

### ignoreZoomSetting

Expand All @@ -199,9 +195,8 @@ can be disabled by setting the _ignoreZoomSetting_ to _true_.

This capability accepts a Boolean value as parameter.

<div>
{{< badge-examples >}}
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
InternetExplorerOptions options = new InternetExplorerOptions();
options.ignoreZoomSettings();
Expand Down Expand Up @@ -241,7 +236,6 @@ options.ignoreZoomSettings()
val driver = RemoteWebDriver(options)
{{< /tab >}}
{{< /tabpane >}}
</div>

### ignoreProtectedModeSettings

Expand All @@ -261,9 +255,8 @@ only a "best effort" at support will be given.

This capability accepts a Boolean value as parameter.

<div>
{{< badge-examples >}}
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
InternetExplorerOptions options = new InternetExplorerOptions();
options.introduceFlakinessByIgnoringSecurityDomains();
Expand Down Expand Up @@ -303,7 +296,6 @@ options.introduceFlakinessByIgnoringSecurityDomains()
val driver = RemoteWebDriver(options)
{{< /tab >}}
{{< /tabpane >}}
</div>

### silent

Expand All @@ -312,9 +304,8 @@ diagnostic output of the IEDriverServer.

This capability accepts a Boolean value as parameter.

<div>
{{< badge-examples >}}
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
InternetExplorerOptions options = new InternetExplorerOptions();
options.setCapability("silent", true);
Expand Down Expand Up @@ -376,7 +367,6 @@ fun main() {
}
{{< /tab >}}
{{< /tabpane >}}
</div>

### Command-Line Options

Expand All @@ -395,9 +385,8 @@ This option specifically used to troubleshoot problems with browser add-ons. Wor

Note: __forceCreateProcessApi__ should to enabled in-order for command line arguments to work.

<div>
{{< badge-examples >}}
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ie.InternetExplorerDriver;
Expand Down Expand Up @@ -494,7 +483,6 @@ fun main() {
}
{{< /tab >}}
{{< /tabpane >}}
</div>

### forceCreateProcessApi

Expand All @@ -504,9 +492,8 @@ using the CreateProcess API. The default value is false.
For IE 8 and above, this option requires the
"TabProcGrowth" registry value to be set to 0.

<div>
{{< badge-examples >}}
{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" >}}
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ie.InternetExplorerDriver;
Expand Down Expand Up @@ -595,8 +582,6 @@ fun main() {
}
{{< /tab >}}
{{< /tabpane >}}
</div>


## Service

Expand Down
Expand Up @@ -25,6 +25,8 @@ Capabilities unique to Safari can be found at Apple's page [About WebDriver for
Starting a Safari session with basic defined options looks like this:

{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< badge-examples >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/browsers/SafariTest.java#24-L25" >}}
{{< /tab >}}
Expand Down

0 comments on commit b82db1d

Please sign in to comment.