Skip to content

Commit 158ba8c

Browse files
Assertion and Setup/Teardown examples linked
Assertion and Setup/Teardown examples linked with existing UsingSeleniumTest.java, removed AssertionsTest.java and SetupAndTeardownTest.java
1 parent fd827c0 commit 158ba8c

File tree

5 files changed

+52
-137
lines changed

5 files changed

+52
-137
lines changed

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

Lines changed: 0 additions & 34 deletions
This file was deleted.

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

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,65 @@
11
package dev.selenium.getting_started;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.time.Duration;
6+
7+
import org.junit.jupiter.api.AfterAll;
8+
import org.junit.jupiter.api.AfterEach;
9+
import org.junit.jupiter.api.BeforeAll;
10+
import org.junit.jupiter.api.BeforeEach;
311
import org.junit.jupiter.api.Test;
412
import org.openqa.selenium.By;
513
import org.openqa.selenium.WebDriver;
614
import org.openqa.selenium.WebElement;
715
import org.openqa.selenium.chrome.ChromeDriver;
816

9-
import java.time.Duration;
17+
public class UsingSeleniumTest {
1018

11-
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
WebDriver driver;
1220

13-
public class UsingSeleniumTest {
21+
@BeforeAll
22+
public static void beforeAll() {
23+
System.out.println("This method will be executed only once before all the tests.");
24+
}
25+
26+
@BeforeEach
27+
public void setup() {
28+
System.out.println(
29+
" This method will be executed before each test, so here write the common code that has to be executed.");
30+
driver = new ChromeDriver();
31+
driver.manage().window().maximize();
32+
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
33+
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
34+
}
35+
36+
@Test
37+
public void eightComponents() {
1438

15-
@Test
16-
public void eightComponents() {
17-
WebDriver driver = new ChromeDriver();
18-
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
39+
String title = driver.getTitle();
40+
assertEquals("Web form", title);
1941

20-
String title = driver.getTitle();
21-
assertEquals("Web form", title);
42+
WebElement textBox = driver.findElement(By.name("my-text"));
43+
WebElement submitButton = driver.findElement(By.cssSelector("button"));
2244

23-
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
45+
textBox.sendKeys("Selenium");
46+
submitButton.click();
2447

25-
WebElement textBox = driver.findElement(By.name("my-text"));
26-
WebElement submitButton = driver.findElement(By.cssSelector("button"));
48+
WebElement message = driver.findElement(By.id("message"));
49+
String value = message.getText();
50+
assertEquals("Received!", value);
2751

28-
textBox.sendKeys("Selenium");
29-
submitButton.click();
52+
}
3053

31-
WebElement message = driver.findElement(By.id("message"));
32-
String value = message.getText();
33-
assertEquals("Received!", value);
54+
@AfterEach
55+
public void teardown() {
56+
System.out.println(" This method will be executed after each test, so here write the clean up code.");
57+
driver.quit();
58+
}
3459

35-
driver.quit();
36-
}
60+
@AfterAll
61+
public static void afterAll() {
62+
System.out.println("This method will be executed only once after all the tests.");
63+
}
3764

3865
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ of the application is same what we are expecting or not. If the assertion fails,
143143
then the test case is failed and execution is stopped.
144144
{{< tabpane text=true >}}
145145
{{< tab header="Java" >}}
146-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/AssertionsTest.java#L20-L29" >}}
146+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java#L39-L40" >}}
147147
{{< /tab >}}
148148
{{% tab header="Python" %}}
149149
{{< badge-code >}}
@@ -169,11 +169,11 @@ then the test case is failed and execution is stopped.
169169

170170
### Set Up
171171

172-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/SetupAndTeardownTest.java#L28-L40" >}}
172+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java#L20-L35" >}}
173173

174174
### Tear Down
175175

176-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/SetupAndTeardownTest.java#L67-L76" >}}
176+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java#L53-L64" >}}
177177

178178
{{% /tab %}}
179179
{{% tab header="Python" %}}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ of the application is same what we are expecting or not. If the assertion fails,
139139
then the test case is failed and execution is stopped.
140140
{{< tabpane text=true >}}
141141
{{< tab header="Java" >}}
142-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/AssertionsTest.java#L20-L29" >}}
142+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java#L39-L40" >}}
143143
{{< /tab >}}
144144
{{% tab header="Python" %}}
145145
{{< badge-code >}}
@@ -165,11 +165,11 @@ then the test case is failed and execution is stopped.
165165

166166
### Set Up
167167

168-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/SetupAndTeardownTest.java#L28-L40" >}}
168+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java#L20-L35" >}}
169169

170170
### Tear Down
171171

172-
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/SetupAndTeardownTest.java#L67-L76" >}}
172+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/getting_started/UsingSeleniumTest.java#L53-L64" >}}
173173

174174
{{% /tab %}}
175175
{{% tab header="Python" %}}

0 commit comments

Comments
 (0)