Skip to content

Commit fbd4e31

Browse files
committed
Initial commit
0 parents  commit fbd4e31

File tree

6 files changed

+249
-0
lines changed

6 files changed

+249
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea
2+
/target
3+
/test-output

Diff for: pom.xml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example.kotlin</groupId>
7+
<artifactId>kotlin-selenium-testng-demo</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>com.example.kotlin kotlin-selenium-testng-demo</name>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<kotlin.version>1.3.71</kotlin.version>
16+
<kotlin.code.style>official</kotlin.code.style>
17+
<testng.version>6.8.8</testng.version>
18+
<selenium.version>3.14.0</selenium.version>
19+
<bonigarcia.version>3.7.1</bonigarcia.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.jetbrains.kotlin</groupId>
25+
<artifactId>kotlin-stdlib</artifactId>
26+
<version>${kotlin.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.jetbrains.kotlin</groupId>
30+
<artifactId>kotlin-test-junit</artifactId>
31+
<version>${kotlin.version}</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.seleniumhq.selenium</groupId>
36+
<artifactId>selenium-java</artifactId>
37+
<version>${selenium.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.seleniumhq.selenium</groupId>
41+
<artifactId>selenium-support</artifactId>
42+
<version>${selenium.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>io.github.bonigarcia</groupId>
46+
<artifactId>webdrivermanager</artifactId>
47+
<version>${bonigarcia.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.testng</groupId>
52+
<artifactId>testng</artifactId>
53+
<version>${testng.version}</version>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<sourceDirectory>src/main/kotlin</sourceDirectory>
59+
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
60+
61+
<plugins>
62+
<plugin>
63+
<groupId>org.jetbrains.kotlin</groupId>
64+
<artifactId>kotlin-maven-plugin</artifactId>
65+
<version>${kotlin.version}</version>
66+
<executions>
67+
<execution>
68+
<id>compile</id>
69+
<phase>compile</phase>
70+
<goals>
71+
<goal>compile</goal>
72+
</goals>
73+
</execution>
74+
<execution>
75+
<id>test-compile</id>
76+
<phase>test-compile</phase>
77+
<goals>
78+
<goal>test-compile</goal>
79+
</goals>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
</plugins>
84+
85+
</build>
86+
87+
</project>

Diff for: src/test/kotlin/com/selenium/kotlin/page/HomePage.kt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.selenium.kotlin.page
2+
3+
import org.openqa.selenium.WebDriver
4+
import org.openqa.selenium.WebElement
5+
import org.openqa.selenium.support.FindBy
6+
import org.openqa.selenium.support.PageFactory
7+
8+
/**
9+
* Project Name : kotlin-selenium-testng-demo
10+
* Developer : Osanda Deshan
11+
* Version : 1.0.0
12+
* Date : 4/11/2020
13+
* Time : 9:25 AM
14+
* Description : This is homepage page object class
15+
**/
16+
17+
class HomePage(driver: WebDriver) {
18+
19+
@FindBy(xpath = "//a[@class='login']")
20+
private val signInButton: WebElement? = null
21+
22+
init {
23+
PageFactory.initElements(driver, this)
24+
}
25+
26+
fun clickOnSignInButton() {
27+
signInButton?.click()
28+
}
29+
30+
31+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.selenium.kotlin.page
2+
3+
import org.openqa.selenium.WebDriver
4+
import org.openqa.selenium.WebElement
5+
import org.openqa.selenium.support.FindBy
6+
import org.openqa.selenium.support.PageFactory
7+
8+
/**
9+
* Project Name : kotlin-selenium-testng-demo
10+
* Developer : Osanda Deshan
11+
* Version : 1.0.0
12+
* Date : 4/11/2020
13+
* Time : 9:35 AM
14+
* Description : This is loginpage page object class
15+
**/
16+
17+
class LoginPage(driver: WebDriver) {
18+
19+
@FindBy(id = "email")
20+
private val emailTextBox: WebElement? = null
21+
22+
@FindBy(id = "passwd")
23+
private val passwordTextBox: WebElement? = null
24+
25+
@FindBy(xpath = "//p[@class='submit']//span[1]")
26+
private val signInButton: WebElement? = null
27+
28+
init {
29+
PageFactory.initElements(driver, this)
30+
}
31+
32+
fun login(email: String, password : String){
33+
emailTextBox?.sendKeys(email)
34+
passwordTextBox?.sendKeys(password)
35+
signInButton?.click()
36+
}
37+
38+
39+
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.selenium.kotlin.test
2+
3+
import com.selenium.kotlin.page.HomePage
4+
import com.selenium.kotlin.page.LoginPage
5+
import org.testng.Assert
6+
import org.testng.annotations.Test
7+
8+
/**
9+
* Project Name : kotlin-selenium-testng-demo
10+
* Developer : Osanda Deshan
11+
* Version : 1.0.0
12+
* Date : 4/11/2020
13+
* Time : 10:06 AM
14+
* Description : This is login test class
15+
**/
16+
17+
class LoginTest : TestBase() {
18+
19+
private val validEmail = "[email protected]"
20+
private val validPassword = "1qaz2wsx@"
21+
private val invalidEmail = "[email protected]"
22+
private val invalidPassword = "password1"
23+
24+
private val loginPageTitle = "Login - My Store"
25+
private val myAccountPageTitle = "My account - My Store"
26+
27+
28+
@Test
29+
fun validLogin() {
30+
val homePage = HomePage(driver)
31+
homePage.clickOnSignInButton()
32+
val loginPage = LoginPage(driver)
33+
loginPage.login(validEmail, validPassword)
34+
Assert.assertEquals(getPageTitle(),myAccountPageTitle)
35+
}
36+
37+
@Test
38+
fun invalidLogin() {
39+
val homePage = HomePage(driver)
40+
homePage.clickOnSignInButton()
41+
val loginPage = LoginPage(driver)
42+
loginPage.login(invalidEmail, invalidPassword)
43+
Assert.assertEquals(getPageTitle(),loginPageTitle)
44+
}
45+
46+
47+
}

Diff for: src/test/kotlin/com/selenium/kotlin/test/TestBase.kt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.selenium.kotlin.test
2+
3+
import io.github.bonigarcia.wdm.WebDriverManager
4+
import org.openqa.selenium.WebDriver
5+
import org.openqa.selenium.chrome.ChromeDriver
6+
import org.testng.annotations.AfterMethod
7+
import org.testng.annotations.BeforeMethod
8+
import java.util.concurrent.TimeUnit
9+
10+
/**
11+
* Project Name : kotlin-selenium-testng-demo
12+
* Developer : Osanda Deshan
13+
* Version : 1.0.0
14+
* Date : 4/11/2020
15+
* Time : 9:49 AM
16+
* Description : This is the base class for tests
17+
**/
18+
19+
abstract class TestBase {
20+
21+
lateinit var driver: WebDriver
22+
23+
@BeforeMethod
24+
open fun setup() {
25+
WebDriverManager.chromedriver().setup()
26+
driver = ChromeDriver()
27+
driver.manage()?.timeouts()?.implicitlyWait(10, TimeUnit.SECONDS)
28+
driver.manage()?.window()?.maximize()
29+
driver.get("http://automationpractice.com/")
30+
}
31+
32+
@AfterMethod
33+
open fun tearDown() {
34+
driver.close()
35+
}
36+
37+
fun getPageTitle(): String? {
38+
return driver.title
39+
}
40+
41+
42+
}

0 commit comments

Comments
 (0)