Description
Leadium - implementation library for web UI / rest api / jdbc test automation in Kotlin.
...
LoginPage() - {
setLogin(login)
setPassword(password)
signIn()
}
MainPage() - {
checkTitle()
next()
Dialog() - {
checkTitle()
accept()
}
Database() - {
...
}
...
}
...
How to start
Intellij IDEA
-
Install Intellij IDEA
-
Download project leadium-examples.
-
Open the project in Intellij IDEA.
Project structure
Example:
.
├── build.gradle
├── dependencies.gradle
├── libs
│ ├── directorywalker.jar
│ ├── leadium-core.jar
│ ├── leadium-core-sources.jar
│ ├── leadium-junit5.jar
│ ├── leadium-junit5-sources.jar
│ ├── leadium-report-allure.jar
│ ├── leadium-report-allure-sources.jar
│ ├── leadium-report.jar
│ ├── leadium-report-sources.jar
│ ├── leadium-ui.jar
│ └── leadium-ui-sources.jar
├── README.md
├── res
│ ├── allure.properties
│ ├── auth.property
│ └── categories.json
├── settings.gradle
└── src
└── apps
└── example
├── res
│ ├── allure.properties
│ ├── dev
│ │ └── example.property
│ └── video.property
├── settings.gradle
└── src
├── allure
│ └── ReportAdapter.kt
└── example
├── alias.kt
├── AOP.kt
├── cases
│ ├── ExampleTest.kt
│ └── syntax
│ └── TestDataSyntax.kt
├── Properties.kt
├── steps
│ └── pages
│ ├── DuckDuckGo.kt
│ └── Wikipedia.kt
└── suite
├── ExampleSuite.kt
└── TestSuite.kt
Basic concepts
An HTML element is a type of HTML document component, one of several types of HTML nodes. HTML document is composed of a tree of simple HTML nodes, such as text nodes, and HTML elements, which add semantics and formatting to parts of document. Each element can have HTML attributes specified. Elements can also have content, including other elements and text.
Test Steps
package steps.pages
import com.codeborne.selenide.Condition.*
import org.leadium.core.*
import org.leadium.data.*
import org.openqa.selenium.*
class DuckDuckGo : AbstractStep, XpathPresetSyntax { (1)
@Step (2)
fun setSearchBox(searchRequest: String) {
element(By.xpath("//input[@id='search_form_input_homepage']"))
.setValue(searchRequest)
}
@Step
fun enter() {
element(By.xpath("//input[@id='search_form_input_homepage']"))
.sendKeys(Keys.ENTER)
}
@Step
fun checkResult(expectedResult: String) {
element(By.xpath(xpathByText(expectedResult, withText = true)))
.should(be(visible))
}
@Step
fun clickResult() {
element(By.xpath("//*[text()='More at Wikipedia ']"))
.click()
}
}
-
Class DuckDuckGo extends AbstractStep (and XpathPresetSyntax optional)
-
Step Annotation for AOP StepProvider
Test case
import com.codeborne.selenide.Condition.*
import example.TestDataMap
import example.cases.syntax.TestDataSyntax
import example.steps.pages.DuckDuckGo
import example.steps.pages.Wikipedia
import org.leadium.core.TestCase
import org.leadium.core.minus
import org.leadium.report.allure.description.Description
@Description("""
Example Test Description
""")
class ExampleTest(override val testData: TestDataMap) : TestCase, TestDataSyntax { (1)
override fun begin() { (2)
DuckDuckGo() - { (3)
setSearchBox(searchRequest())
enter()
checkResult(expectedResult())
clickResult()
}
Wikipedia() - {
checkResult(expectedResult())
checkLogoTitle()
checkSearchInput()
mathematics()
mainPage()
checkLogoCondition(be(not(focused)))
}
}
}
-
Specify the name of the class and implement the TestCase interface.
-
Override the begin method
-
The operator - is required to call class methods (i.e. DuckDuckGo or Wikipedia) and display their title in the report.
Test Suite
...
@Epic("EXAMPLE EPIC") (1)
@DisplayName("Example Suite | positive") (2)
@DisplayNameGeneration(DisplayNameGenerator::class) (3)
class ExampleSuite : TestSuite() { (4)
@Test (5)
@Feature("POSITIVE") (6)
@Story("EXAMPLE STORY")
@TestCaseDisplayName(ExampleTest::class) (7)
@TestDataResolver.Settings(TestDataType.PROPERTY, resourcesPath, ["dev/example.property"])
fun wikiTest(@Inject testData: PropertyTestData) {
ExampleTest(testData.map).begin() (8)
}
...
}
-
Specify the @Epic annotation to indicate the epic group in the report.
-
Specify the @DisplayName annotation to display the test suite name in the report.
-
Specify the @DisplayNameGeneration annotation for auto-formatting of names in the report tests.
-
The ExampleSuite class extends the class TestSuite.
-
Specify the annotation @Test, which means that this method is a test.
-
Specify the annotations @Feature and @Story, defining subgroups for the report.
-
Pass the test case class to the @TestCaseDisplayName annotation to display the name in the report. It is also possible to use the annotation @DisplayName instead of the annotation @TestCaseDisplayName.
-
Call the test-case begin method.
Test running
To run the test, click run in Idea on the left of the test declaration.

Test running by console
To start the test suite, execute the command from the project directory:
./gradlew :example:test --tests example.suite.ExampleSuite -i
Parallel tests execution by console
Docker installation
Docker need for Selenoid execution.
Selenoid Installation
Selenoid is Selenium Hub successor running browsers within Docker containers. Scalable, immutable, self hosted Selenium-Grid is on every platform with single binary.
It is required to download binary of Selenoid and Selenoid-ui.
For working Selenoid, we need to download docker-images for browsers and for video-recorder:
docker pull selenoid/video-recorder
docker pull selenoid/vnc:chrome_65.0
Create docker network:
docker network create \
--driver=bridge \
--subnet=172.29.0.0/16 \
--ip-range=172.29.5.0/24 \
--gateway=172.29.5.254 \
bridge1
Before running the tests, we need to execute selenoid and selenoid-ui:
./selenoid -container-network bridge1 -timeout 3m0s -limit 4
./selenoid-ui -listen :8090
Selenoid system properties initialization in build.gradle:
tasks.withType(Test) {
useJUnitPlatform()
def defaultHost = "dev"
systemProperty "host", System.getProperty("host", defaultHost) (1)
systemProperty "envTestDataDir", System.getProperty("envTestDataDir", defaultHost)
systemProperty "parallel", System.getProperty("parallel", "false") (2)
systemProperty "leadium.selenoid.browserName", "chrome" (3)
systemProperty "leadium.selenoid.enableVNC", true (4)
systemProperty "leadium.selenoid.enableVideo", true (5)
systemProperty "leadium.selenoid.host", "http://jenkins-01.example.com:4444" (6)
systemProperty "leadium.selenoid.localhost", "http://localhost:4444" (7)
systemProperty "leadium.selenoid.dimensionWidth", 1280 (8)
systemProperty "leadium.selenoid.dimensionHeight", 1024 (9)
}
-
Add the -Dhost flag to gradle tasks of type Test. In this flag we specify the host where testing will be performed.
-
Add the -Dparallel flag to enable parallel mode when =true.
-
Browser name.
-
Enable VNC.
-
Enable video recording in containers.
-
The host where published the video files list with the record of passing tests from containers.
-
The local host where published the video files list with recording tests from the containers.
-
Video resolution, width.
-
Video resolution, height.
Parallel running
For parallel running execute the command in terminal (one or more):
./gradlew -Dparallel=true :example:test --tests example.suite.ExampleSuite1 -i
-
The -Dparallel flag is used to start each process in a separate container.
-
The --tests flag is used to specify the current test suite reference (--tests example.suite.ExampleSuite).
Generating Allure Report
-
Download the latest version of Allure
Execute this command:
./allure serve /path/to/project_dir/test/apps/module_name/build/allure-results
You can see the report example below:
