Skip to content

Commit 60e6173

Browse files
authored
Fix first Java script example and doc (SeleniumHQ#1108)
[deploy site]
1 parent f74f2e4 commit 60e6173

File tree

9 files changed

+68
-51
lines changed

9 files changed

+68
-51
lines changed

examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package dev.selenium.getting_started;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import java.time.Duration;
47

58
import org.junit.jupiter.api.AfterEach;
69
import org.junit.jupiter.api.BeforeAll;
710
import org.junit.jupiter.api.BeforeEach;
811
import org.junit.jupiter.api.Test;
12+
import org.openqa.selenium.By;
913
import org.openqa.selenium.WebDriver;
14+
import org.openqa.selenium.WebElement;
1015
import org.openqa.selenium.chrome.ChromeDriver;
1116

1217
import io.github.bonigarcia.wdm.WebDriverManager;
@@ -31,11 +36,23 @@ public void quit() {
3136
}
3237

3338
@Test
34-
public void test() {
35-
driver.get("https://google.com");
39+
public void eightComponents() {
40+
driver.get("https://duckduckgo.com/");
3641

3742
String title = driver.getTitle();
38-
assertEquals("Google", title);
43+
assertTrue(title.contains("DuckDuckGo"));
44+
45+
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
46+
47+
WebElement searchBox = driver.findElement(By.name("q"));
48+
WebElement searchButton = driver.findElement(By.id("search_button_homepage"));
49+
50+
searchBox.sendKeys("Selenium");
51+
searchButton.click();
52+
53+
searchBox = driver.findElement(By.name("q"));
54+
String value = searchBox.getAttribute("value");
55+
assertEquals("Selenium", value);
3956
}
4057

4158
}

website_and_docs/content/documentation/about/style.en.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ shortcode. This is an example of the `gh-codeblock` shortcode usage:
166166

167167
{{</* tabpane */>}}
168168
{{</* tab header="Link" disableCodeBlock=true */>}}
169-
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L15-L37" */>}}
169+
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" */>}}
170170
{{</* /tab */>}}
171171
{{</* tab header="No Link" */>}}
172172
This content should not get linked to GitHub
@@ -177,7 +177,7 @@ Which looks like this:
177177

178178
{{< tabpane >}}
179179
{{< tab header="Link" disableCodeBlock=true >}}
180-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L15-L37" >}}
180+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" >}}
181181
{{< /tab >}}
182182
{{< tab header="No Link" >}}
183183
This content should not get linked to GitHub
@@ -239,12 +239,12 @@ All code examples should be present and linked to in our example
239239
With the `gh-codeblock` shortcode, it is possible to render code hosted in a GitHub
240240
repository. This is an example of the `gh-codeblock` shortcode usage:
241241

242-
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L15-L37" */>}}
242+
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" */>}}
243243

244244
Which looks like this:
245245

246246
<span class="tab-pane">
247-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L15-L37" >}}
247+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" >}}
248248
</span>
249249

250250
### Consistent Heights

website_and_docs/content/documentation/about/style.ja.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ shortcode. This is an example of the `gh-codeblock` shortcode usage:
167167

168168
{{</* tabpane */>}}
169169
{{</* tab header="Link" disableCodeBlock=true */>}}
170-
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" */>}}
170+
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" */>}}
171171
{{</* /tab */>}}
172172
{{</* tab header="No Link" */>}}
173173
This content should not get linked to GitHub
@@ -178,7 +178,7 @@ Which looks like this:
178178

179179
{{< tabpane >}}
180180
{{< tab header="Link" disableCodeBlock=true >}}
181-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" >}}
181+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" >}}
182182
{{< /tab >}}
183183
{{< tab header="No Link" >}}
184184
This content should not get linked to GitHub
@@ -239,12 +239,12 @@ All code examples should be present and linked to in our example
239239
With the `gh-codeblock` shortcode, it is possible to render code hosted in a GitHub
240240
repository. This is an example of the `gh-codeblock` shortcode usage:
241241

242-
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" */>}}
242+
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" */>}}
243243

244244
Which looks like this:
245245

246246
<span class="tab-pane">
247-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" >}}
247+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" >}}
248248
</span>
249249

250250
### Code Comments

website_and_docs/content/documentation/about/style.pt-br.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ shortcode. This is an example of the `gh-codeblock` shortcode usage:
167167

168168
{{</* tabpane */>}}
169169
{{</* tab header="Link" disableCodeBlock=true */>}}
170-
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" */>}}
170+
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" */>}}
171171
{{</* /tab */>}}
172172
{{</* tab header="No Link" */>}}
173173
This content should not get linked to GitHub
@@ -178,7 +178,7 @@ Which looks like this:
178178

179179
{{< tabpane >}}
180180
{{< tab header="Link" disableCodeBlock=true >}}
181-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" >}}
181+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" >}}
182182
{{< /tab >}}
183183
{{< tab header="No Link" >}}
184184
This content should not get linked to GitHub
@@ -239,12 +239,12 @@ All code examples should be present and linked to in our example
239239
With the `gh-codeblock` shortcode, it is possible to render code hosted in a GitHub
240240
repository. This is an example of the `gh-codeblock` shortcode usage:
241241

242-
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" */>}}
242+
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" */>}}
243243

244244
Which looks like this:
245245

246246
<span class="tab-pane">
247-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" >}}
247+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" >}}
248248
</span>
249249

250250
### Code Comments

website_and_docs/content/documentation/about/style.zh-cn.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ shortcode. This is an example of the `gh-codeblock` shortcode usage:
167167

168168
{{</* tabpane */>}}
169169
{{</* tab header="Link" disableCodeBlock=true */>}}
170-
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" */>}}
170+
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" */>}}
171171
{{</* /tab */>}}
172172
{{</* tab header="No Link" */>}}
173173
This content should not get linked to GitHub
@@ -178,7 +178,7 @@ Which looks like this:
178178

179179
{{< tabpane >}}
180180
{{< tab header="Link" disableCodeBlock=true >}}
181-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" >}}
181+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" >}}
182182
{{< /tab >}}
183183
{{< tab header="No Link" >}}
184184
This content should not get linked to GitHub
@@ -239,12 +239,12 @@ All code examples should be present and linked to in our example
239239
With the `gh-codeblock` shortcode, it is possible to render code hosted in a GitHub
240240
repository. This is an example of the `gh-codeblock` shortcode usage:
241241

242-
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" */>}}
242+
{{</* gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" */>}}
243243

244244
Which looks like this:
245245

246246
<span class="tab-pane">
247-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17-L37" >}}
247+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L38-L56" >}}
248248
</span>
249249

250250
### Code Comments

website_and_docs/content/documentation/webdriver/getting_started/first_script.en.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For more details on starting a session read our documentation on [opening and cl
2020

2121
{{< tabpane disableCodeBlock=true >}}
2222
{{< tab header="Java" >}}
23-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}}
23+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L30" >}}
2424
{{< /tab >}}
2525
{{< tab header="Python" >}}
2626
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L6" >}}
@@ -44,7 +44,7 @@ In this example we are [navigating]({{< ref "/documentation/webdriver/browser/na
4444

4545
{{< tabpane disableCodeBlock=true >}}
4646
{{< tab header="Java" >}}
47-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L19" >}}
47+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L40" >}}
4848
{{< /tab >}}
4949
{{< tab header="Python" >}}
5050
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L8" >}}
@@ -70,7 +70,7 @@ can request, including window handles, browser size / position, cookies, alerts,
7070

7171
{{< tabpane disableCodeBlock=true >}}
7272
{{< tab header="Java" >}}
73-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L21" >}}
73+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L42" >}}
7474
{{< /tab >}}
7575
{{< tab header="Python" >}}
7676
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L10" >}}
@@ -104,7 +104,7 @@ Read more about [Waiting strategies]({{< ref "/documentation/webdriver/waits.md"
104104

105105
{{< tabpane disableCodeBlock=true >}}
106106
{{< tab header="Java" >}}
107-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L24" >}}
107+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L45" >}}
108108
{{< /tab >}}
109109
{{< tab header="Python" >}}
110110
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L13" >}}
@@ -129,7 +129,7 @@ with one without first [finding an element]({{< ref "/documentation/webdriver/el
129129

130130
{{< tabpane disableCodeBlock=true >}}
131131
{{< tab header="Java" >}}
132-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L26-L27" >}}
132+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L47-L48" >}}
133133
{{< /tab >}}
134134
{{< tab header="Python" >}}
135135
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L15-L16" >}}
@@ -154,7 +154,7 @@ but you will use them frequently.
154154

155155
{{< tabpane disableCodeBlock=true >}}
156156
{{< tab header="Java" >}}
157-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L29-L30" >}}
157+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L50-L51" >}}
158158
{{< /tab >}}
159159
{{< tab header="Python" >}}
160160
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L18-L19" >}}
@@ -179,7 +179,7 @@ Notice that we need to relocate the search box because the DOM has changed since
179179

180180
{{< tabpane disableCodeBlock=true >}}
181181
{{< tab header="Java" >}}
182-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L33" >}}
182+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L54" >}}
183183
{{< /tab >}}
184184
{{< tab header="Python" >}}
185185
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L22" >}}
@@ -205,7 +205,7 @@ No more commands can be sent to this driver instance.
205205

206206
{{< tabpane disableCodeBlock=true >}}
207207
{{< tab header="Java" >}}
208-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L36" >}}
208+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}}
209209
{{< /tab >}}
210210
{{< tab header="Python" >}}
211211
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L25" >}}

website_and_docs/content/documentation/webdriver/getting_started/first_script.ja.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ For more details on starting a session read our documentation on [opening and cl
2121

2222
{{< tabpane disableCodeBlock=true >}}
2323
{{< tab header="Java" >}}
24-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L17" >}}
24+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L30" >}}
2525
{{< /tab >}}
2626
{{< tab header="Python" >}}
2727
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L6" >}}
@@ -45,7 +45,7 @@ In this example we are ブラウザが[ナビゲート]({{< ref "/documentation/
4545

4646
{{< tabpane disableCodeBlock=true >}}
4747
{{< tab header="Java" >}}
48-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L19" >}}
48+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L40" >}}
4949
{{< /tab >}}
5050
{{< tab header="Python" >}}
5151
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L8" >}}
@@ -71,7 +71,7 @@ can request, including window handles, browser size / position, cookies, alerts,
7171

7272
{{< tabpane disableCodeBlock=true >}}
7373
{{< tab header="Java" >}}
74-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L21" >}}
74+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L42" >}}
7575
{{< /tab >}}
7676
{{< tab header="Python" >}}
7777
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L10" >}}
@@ -105,7 +105,7 @@ Read more about [Waiting strategies]({{< ref "/documentation/webdriver/waits.md"
105105

106106
{{< tabpane disableCodeBlock=true >}}
107107
{{< tab header="Java" >}}
108-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L24" >}}
108+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L45" >}}
109109
{{< /tab >}}
110110
{{< tab header="Python" >}}
111111
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L13" >}}
@@ -130,7 +130,7 @@ with one without first [finding an element]({{< ref "/documentation/webdriver/el
130130

131131
{{< tabpane disableCodeBlock=true >}}
132132
{{< tab header="Java" >}}
133-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L26-L27" >}}
133+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L47-L48" >}}
134134
{{< /tab >}}
135135
{{< tab header="Python" >}}
136136
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L15-L16" >}}
@@ -155,7 +155,7 @@ but you will use them frequently.
155155

156156
{{< tabpane disableCodeBlock=true >}}
157157
{{< tab header="Java" >}}
158-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L29-L30" >}}
158+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L50-L51" >}}
159159
{{< /tab >}}
160160
{{< tab header="Python" >}}
161161
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L18-L19" >}}
@@ -180,7 +180,7 @@ Notice that we need to relocate the search box because the DOM has changed since
180180

181181
{{< tabpane disableCodeBlock=true >}}
182182
{{< tab header="Java" >}}
183-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L33" >}}
183+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L54" >}}
184184
{{< /tab >}}
185185
{{< tab header="Python" >}}
186186
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L22" >}}
@@ -206,7 +206,7 @@ No more commands can be sent to this driver instance.
206206

207207
{{< tabpane disableCodeBlock=true >}}
208208
{{< tab header="Java" >}}
209-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L36" >}}
209+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/FirstScriptTest.java#L35" >}}
210210
{{< /tab >}}
211211
{{< tab header="Python" >}}
212212
{{< gh-codeblock path="examples/python/tests/getting_started/test_first_script.py#L25" >}}

0 commit comments

Comments
 (0)