Running test automation with Selenide on GitLab

Pradap Pandiyan
4 min readJan 14

--

Selenide is a robust test automation framework powered by Selenium. We can start building the test in minutes with a very minimal configuration. Here is the quick start guide.

WebDriver brings the following advantages

  • Concise fluent API for tests
  • Stable tests
  • Powerful selectors
  • Simple configuration

I have created a project with Selenide — Gradle structure.

I have used the selenide library on the project for Gradle import. Below is the build.gradle.kts file for the configuration.

plugins {
id("java")
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
}

dependencies {
implementation("junit:junit:4.13.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
testImplementation("junit:junit:4.13.2")
implementation("com.codeborne:selenide:6.11.0")

}


tasks.getByName<Test>("test") {
useJUnitPlatform()
testLogging.showStandardStreams = true
}

In this project, I haven’t used any reports. I’m using the default Gradle-generated report to view the tests. I have added test logging and it helps in viewing the logs whenever the Gradle test runs.

stages:
- test

test:
image: rvancea/gradle-chrome-jdk8
stage: test
script:
- gradle test
when: manual
artifacts:
when: always
paths:
- build/reports
- out
expire_in: 1 day

I’ve created one stage on the gitlab-ci.yml file under the project. I kept the yml file to run manually on the project in order to reduce the usage of the CI minutes. I have used this gentlemen docker image rvancea/gradle- chrome-jdk8 to run the test on the CI. I’ve created an artifact path so that in case of failure, we can look into the reports and added 1-day validity. We can directly view the generated reports on Gitlab.

I’ve added some code block to run the test on headless, When I tried running on UI mode it crashes on the docker image.

ChromeOptions options = new ChromeOptions()
.setHeadless(true)
.addArguments("--lang=en_US");
Configuration.browserCapabilities = options;

Below are the Logs from the test and we have artifacts added for the report.

Running with gitlab-runner 15.6.0~beta.186.ga889181a (a889181a)
on blue-2.shared.runners-manager.gitlab.com/default XxUrkriX
Preparing the "docker+machine" executor
00:41
Using Docker executor with image rvancea/gradle-chrome-jdk8 ...
Pulling docker image rvancea/gradle-chrome-jdk8 ...
Using docker image sha256:49569bf0059894035cfc4b6139e837340f4235a2ed10094ad41c136cf7ccf257 for rvancea/gradle-chrome-jdk8 with digest rvancea/gradle-chrome-jdk8@sha256:3b195103c7bbe984815e1a3dc6953fea610c1af1856316a06f7aacf4a8acc314 ...
Preparing environment
00:02
Running on runner-xxurkrix-project-42519157-concurrent-0 via runner-xxurkrix-shared-1673518336-8301ff99...
Getting source from Git repository
00:01
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/pradapjackie/selenide-web/.git/
Created fresh repository.
Checking out 0230f1bc as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
01:57
Using docker image sha256:49569bf0059894035cfc4b6139e837340f4235a2ed10094ad41c136cf7ccf257 for rvancea/gradle-chrome-jdk8 with digest rvancea/gradle-chrome-jdk8@sha256:3b195103c7bbe984815e1a3dc6953fea610c1af1856316a06f7aacf4a8acc314 ...
$ gradle test
Welcome to Gradle 7.0!
Here are the highlights of this release:
- File system watching enabled by default
- Support for running with and building Java 16 projects
- Native support for Apple Silicon processors
- Dependency catalog feature preview
For more details see https://docs.gradle.org/7.0/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test
MainTest STANDARD_ERROR
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
MainTest > valid_Login_with_TC_1() STANDARD_ERROR
Starting ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429}) on port 14318
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jan 12, 2023 10:15:24 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find CDP implementation matching 90
Jan 12, 2023 10:15:24 AM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.7.2` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
BUILD SUCCESSFUL in 1m 54s
3 actionable tasks: 3 executed
Uploading artifacts for successful job
00:02
Uploading artifacts...
build/reports: found 13 matching files and directories
WARNING: out: no matching files. Ensure that the artifact path is relative to the working directory
Uploading artifacts as "archive" to coordinator... 201 Created id=3592709940 responseStatus=201 Created token=64_1XBTm
Cleaning up project directory and file based variables
00:01
Job succeeded
test

Duration: 2 minutes 45 seconds
Finished: 51 minutes ago
Queued: 0 seconds
Timeout: 1h (from project)

Runner: #12270831 (XxUrkriX) 2-blue.shared.runners-manager.gitlab.com/default
Job artifacts
These artifacts are the latest. They will not be deleted (even if expired) until newer artifacts are available.

Commit 0230f1bc
added code to run headless

Pipeline #745293679 for master
test
result

This is the link for the deployed report on GitLab for the Gradle test.

Conclusion

Selenide is a very simple framework to use with minimal configuration. I have all the actions customized and easier way to run the tests. It doesn't have great documentation to work with, but I believe it will get sorted out.

I have created a project on Gitlab and added the code here.

Feel free to hit clap if you like the content. Happy Automation Testing :) Cheers. 👏

--

--

Pradap Pandiyan

I’m a passionate QA Engineer. I’m a motovlogger, content creator, off-roader and freelancer. Buy me a coffee here https://www.buymeacoffee.com/pradappandiyan