Skip to content

Commit 022f9db

Browse files
krmahadevandiemol
andauthored
Adding Kotlin sample project (SeleniumHQ#925)
Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent 87db007 commit 022f9db

File tree

5 files changed

+241
-0
lines changed

5 files changed

+241
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules
55
resources/
66
website_and_docs/.hugo_build.lock
77

8+
**/target/*

examples/kotlin/pom.xml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>dev.selenium</groupId>
7+
<artifactId>selenium-examples</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<properties>
10+
<kotlin.version>1.6.10</kotlin.version>
11+
<jdk.version>1.8</jdk.version>
12+
<maven.compiler.source>${jdk.version}</maven.compiler.source>
13+
<maven.compiler.target>${jdk.version}</maven.compiler.target>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.seleniumhq.selenium</groupId>
18+
<artifactId>selenium-java</artifactId>
19+
<version>4.1.1</version>
20+
<scope>test</scope>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.junit.jupiter</groupId>
24+
<artifactId>junit-jupiter-engine</artifactId>
25+
<version>5.8.2</version>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>io.github.bonigarcia</groupId>
30+
<artifactId>webdrivermanager</artifactId>
31+
<version>5.0.3</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.jetbrains.kotlin</groupId>
36+
<artifactId>kotlin-stdlib-jdk8</artifactId>
37+
<version>${kotlin.version}</version>
38+
<scope>test</scope>
39+
</dependency>
40+
</dependencies>
41+
<build>
42+
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-surefire-plugin</artifactId>
47+
<version>3.0.0-M5</version>
48+
</plugin>
49+
<plugin>
50+
<groupId>org.jetbrains.kotlin</groupId>
51+
<artifactId>kotlin-maven-plugin</artifactId>
52+
<version>${kotlin.version}</version>
53+
<executions>
54+
<execution>
55+
<id>compile</id>
56+
<phase>compile</phase>
57+
<goals>
58+
<goal>compile</goal>
59+
</goals>
60+
</execution>
61+
<execution>
62+
<id>test-compile</id>
63+
<phase>test-compile</phase>
64+
<goals>
65+
<goal>test-compile</goal>
66+
</goals>
67+
</execution>
68+
</executions>
69+
<configuration>
70+
<jvmTarget>${jdk.version}</jvmTarget>
71+
</configuration>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package dev.selenium.getting_started
2+
3+
import io.github.bonigarcia.wdm.WebDriverManager
4+
import org.junit.jupiter.api.*
5+
import org.junit.jupiter.api.Assertions.assertEquals
6+
import org.openqa.selenium.By
7+
import org.openqa.selenium.WebDriver
8+
import org.openqa.selenium.chrome.ChromeDriver
9+
import java.time.Duration
10+
11+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
12+
class FirstScriptTest {
13+
private lateinit var driver: WebDriver
14+
15+
@BeforeAll
16+
fun setupDriverBinary() {
17+
WebDriverManager.chromedriver().setup()
18+
}
19+
20+
@BeforeEach
21+
fun setupBrowser() {
22+
driver = ChromeDriver()
23+
}
24+
25+
@Test
26+
fun eightComponents() {
27+
driver.get("https://google.com")
28+
29+
assertEquals("Google", driver.title)
30+
31+
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500))
32+
33+
var searchBox = driver.findElement(By.name("q"))
34+
val searchButton = driver.findElement(By.name("btnK"))
35+
36+
searchBox.sendKeys("Selenium")
37+
searchButton.click()
38+
39+
searchBox = driver.findElement(By.name("q"))
40+
assertEquals("Selenium", searchBox.getAttribute("value"))
41+
}
42+
43+
@AfterEach
44+
fun cleanupBrowser() {
45+
driver.quit()
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package dev.selenium.getting_started
2+
3+
import io.github.bonigarcia.wdm.WebDriverManager
4+
import org.junit.jupiter.api.Disabled
5+
import org.junit.jupiter.api.Test
6+
import org.openqa.selenium.WebDriver
7+
import org.openqa.selenium.chrome.ChromeDriver
8+
import org.openqa.selenium.edge.EdgeDriver
9+
import org.openqa.selenium.firefox.FirefoxDriver
10+
import org.openqa.selenium.ie.InternetExplorerDriver
11+
12+
13+
class InstallDriversTest {
14+
@Test
15+
fun chromeSession() {
16+
WebDriverManager.chromedriver().setup()
17+
val driver: WebDriver = ChromeDriver()
18+
driver.quit()
19+
}
20+
21+
@Test
22+
fun edgeSession() {
23+
WebDriverManager.edgedriver().setup()
24+
val driver: WebDriver = EdgeDriver()
25+
driver.quit()
26+
}
27+
28+
@Test
29+
fun firefoxSession() {
30+
WebDriverManager.firefoxdriver().setup()
31+
val driver: WebDriver = FirefoxDriver()
32+
driver.quit()
33+
}
34+
35+
@Disabled("Only runs on Windows")
36+
@Test
37+
fun ieSession() {
38+
WebDriverManager.iedriver().setup()
39+
val driver: WebDriver = InternetExplorerDriver()
40+
driver.quit()
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package dev.selenium.getting_started
2+
3+
import org.junit.jupiter.api.Disabled
4+
import org.junit.jupiter.api.Test
5+
import org.openqa.selenium.WebDriver
6+
import org.openqa.selenium.chrome.ChromeDriver
7+
import org.openqa.selenium.chrome.ChromeOptions
8+
import org.openqa.selenium.edge.EdgeDriver
9+
import org.openqa.selenium.edge.EdgeOptions
10+
import org.openqa.selenium.firefox.FirefoxDriver
11+
import org.openqa.selenium.firefox.FirefoxOptions
12+
import org.openqa.selenium.ie.InternetExplorerDriver
13+
import org.openqa.selenium.ie.InternetExplorerOptions
14+
import org.openqa.selenium.safari.SafariDriver
15+
import org.openqa.selenium.safari.SafariOptions
16+
17+
18+
class OpenBrowserTest {
19+
private lateinit var driver: WebDriver
20+
21+
@Test
22+
fun chromeSession() {
23+
val options = ChromeOptions()
24+
driver = ChromeDriver(options)
25+
driver.quit()
26+
}
27+
28+
@Test
29+
fun edgeSession() {
30+
val options = EdgeOptions()
31+
driver = EdgeDriver(options)
32+
driver.quit()
33+
}
34+
35+
@Test
36+
fun firefoxSession() {
37+
val options = FirefoxOptions()
38+
driver = FirefoxDriver(options)
39+
driver.quit()
40+
}
41+
42+
@Disabled("Only runs on Windows")
43+
@Test
44+
fun internetExplorerSession() {
45+
val options = InternetExplorerOptions()
46+
driver = InternetExplorerDriver(options)
47+
driver.quit()
48+
}
49+
50+
@Disabled("Only runs on Windows")
51+
@Test
52+
fun internetExplorerCompatibilitySession() {
53+
val options = InternetExplorerOptions()
54+
options.attachToEdgeChrome()
55+
options.withEdgeExecutablePath("/path/to/edge/browser")
56+
driver = InternetExplorerDriver(options)
57+
driver.quit()
58+
}
59+
60+
@Disabled("Requires non-standard browser")
61+
@Test
62+
fun operaSession() {
63+
val options = ChromeOptions()
64+
options.setBinary("/path/to/opera/browser")
65+
driver = ChromeDriver(options)
66+
driver.quit()
67+
}
68+
69+
@Disabled("Only runs on Mac")
70+
@Test
71+
fun safariSession() {
72+
val options = SafariOptions()
73+
driver = SafariDriver(options)
74+
driver.quit()
75+
}
76+
}

0 commit comments

Comments
 (0)