Skip to content

Commit 0d3fbd4

Browse files
author
Matécsa Dániel
committed
Added Selenium tests
1 parent c0d5f32 commit 0d3fbd4

16 files changed

Lines changed: 804 additions & 24 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gradle/
2+
build/
3+
.idea/
4+
bin/

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM ubuntu:24.04
2+
3+
# Install dependencies
4+
RUN apt-get update && apt-get install -y curl unzip wget gnupg2 software-properties-common \
5+
fonts-dejavu fonts-liberation fonts-noto
6+
7+
ENV LANG=C.UTF-8
8+
ENV LC_ALL=C.UTF-8
9+
10+
# Install Java
11+
RUN add-apt-repository ppa:openjdk-r/ppa && \
12+
apt-get update && \
13+
apt-get install -y openjdk-8-jdk
14+
15+
# Install Gradle
16+
ENV GRADLE_VERSION=7.4
17+
RUN wget -q https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip && \
18+
unzip gradle-$GRADLE_VERSION-bin.zip && \
19+
rm gradle-$GRADLE_VERSION-bin.zip && \
20+
mv gradle-$GRADLE_VERSION /opt/gradle && \
21+
ln -s /opt/gradle/bin/gradle /usr/bin/gradle
22+
23+
# Set environment variables
24+
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
25+
ENV GRADLE_HOME=/opt/gradle
26+
27+
# Add Gradle and Java to PATH
28+
ENV PATH=$PATH:$GRADLE_HOME/bin:$JAVA_HOME/bin
29+
30+
RUN apt-get update && apt-get install -y sudo
31+
32+
ARG uid
33+
ARG UNAME=selenium
34+
35+
RUN usermod -l $UNAME ubuntu && \
36+
usermod -d /home/$UNAME -m $UNAME && \
37+
groupmod -n $UNAME ubuntu && \
38+
usermod -aG sudo $UNAME && \
39+
usermod -g $UNAME $UNAME && \
40+
if ! id -u $UID >/dev/null 2>&1; then \
41+
usermod -u $UID $UNAME; \
42+
fi && \
43+
chown -R $UNAME:$UNAME /home/$UNAME
44+
45+
ENV TZ=Europe/Budapest
46+
ENV DEBIAN_FRONTEND=noninteractive
47+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
48+
49+
USER $UNAME
50+
WORKDIR /home/$UNAME
51+
ENV HOME=/home/$UNAME
52+
53+
CMD ["/bin/bash"]

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: "3.8"
2+
3+
services:
4+
selenium:
5+
image: selenium/standalone-chrome:latest
6+
container_name: docker-sandbox-selenium2
7+
shm_size: 2gb
8+
environment:
9+
- LANG=C.UTF-8
10+
- LC_ALL=C.UTF-8
11+
- SE_VNC_NO_PASSWORD=1
12+
- SE_SCREEN_WIDTH=1800
13+
- SE_SCREEN_HEIGHT=960
14+
- SE_NODE_MAX_SESSIONS=5
15+
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
16+
ports:
17+
- "4444:4444"
18+
- "7900:7900"
19+
20+
ubuntu:
21+
build:
22+
context: .
23+
args:
24+
uid: ${USER_ID:-1000}
25+
container_name: docker-sandbox-ubuntu2
26+
stdin_open: true
27+
tty: true
28+
volumes:
29+
- ./tests:/home/selenium/tests
30+
depends_on:
31+
- selenium

points.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# ============================================================
99

1010
student:
11-
website_under_test: ""
11+
website_under_test: "https://sandbox.moodledemo.net"
1212

1313

1414
# ----------------------------------------------------------
@@ -33,47 +33,47 @@ ai_usage:
3333
# ----------------------------------------------------------
3434
quality:
3535
gitignore: # required for grade 2+
36-
done: false
36+
done: true
3737
description: "Unnecessary files are ignored (.gitignore covers build output, IDE files, etc.)"
3838

3939
structured_code: # required for grade 3+
40-
done: false
40+
done: true
4141
description: "Code is organized into classes and functions, not one big file"
4242

4343
readable_code: # required for grade 4+
44-
done: false
44+
done: true
4545
description: "Function and method names describe what they do, test suite reads like a test description"
4646

4747
low_redundancy: # required for grade 5
48-
done: false
48+
done: true
4949
description: "Minimal code duplication, shared logic is extracted into reusable methods"
5050

5151
# ----------------------------------------------------------
5252
# Basic tasks (B)
5353
# ----------------------------------------------------------
5454
basic:
5555
login_form: # 3 pts | once
56-
done: false
56+
done: true
5757
description: "Fill a simple form and submit it (e.g. login with username and password)"
5858

5959
form_with_user: # 3 pts | once
60-
done: false
60+
done: true
6161
description: "Submit a form that requires a registered/logged-in user"
6262

6363
logout: # 2 pts | once
64-
done: false
64+
done: true
6565
description: "Log out from the application and verify it"
6666

6767
fill_input: # 1 pt each | repeatable | max 10
68-
count: 0
68+
count: 2
6969
description: "Fill an input field (text, radio, checkbox, date, etc.) — each different type counts as one"
7070

7171
send_form: # 1 pt each | repeatable | max 10
72-
count: 0
72+
count: 1
7373
description: "Submit a form (each distinct form counts as one)"
7474

7575
static_page_test: # 2 pts | once
76-
done: false
76+
done: true
7777
description: "Test a static page (verify text content, element presence, etc.)"
7878

7979
multiple_page_test: # 3 pts | once
@@ -98,50 +98,50 @@ basic:
9898
description: "Select or verify a radio button"
9999

100100
at_least_4_classes: # 3 pts | once
101-
done: false
101+
done: true
102102
description: "Project has at least 4 Java classes"
103103

104104
at_least_6_classes: # 3 pts | once
105-
done: false
105+
done: true
106106
description: "Project has at least 6 Java classes (cumulative with above)"
107107

108108
at_least_8_classes: # 3 pts | once
109-
done: false
109+
done: true
110110
description: "Project has at least 8 Java classes (cumulative with above)"
111111

112112
explicit_wait: # 3 pts | once
113-
done: false
113+
done: true
114114
description: "Use explicit wait (WebDriverWait with ExpectedConditions)"
115115
link: "https://www.selenium.dev/documentation/webdriver/waits/"
116116

117117
page_title: # 1 pt | once
118-
done: false
118+
done: true
119119
description: "Read and verify the page title using getTitle()"
120120

121121
page_object_pattern: # 3 pts | once
122-
done: false
122+
done: true
123123
description: "Use Page Object pattern with at least 2 page classes"
124124
link: "https://www.selenium.dev/documentation/test_practices/encouraged/page_object_models/"
125125

126126
base_page_class: # 1 pt | once
127-
done: false
127+
done: true
128128
description: "Create a BasePage class that other page classes extend"
129129

130130
readable_tests: # 3 pts | once
131-
done: false
131+
done: true
132132
description: "Test methods have descriptive names so the suite reads like a test specification"
133133

134134
# ----------------------------------------------------------
135135
# Advanced tasks (A)
136136
# ----------------------------------------------------------
137137
advanced:
138138
webdriver_config: # 4 pts | once
139-
done: false
139+
done: true
140140
description: "Configure WebDriver with custom options (e.g. ChromeOptions, window size, user agent)"
141141
link: "https://www.selenium.dev/documentation/webdriver/drivers/options/"
142142

143143
cookie_manipulation: # 6 pts | once
144-
done: false
144+
done: true
145145
description: "Manipulate cookies meaningfully (e.g. add/delete/read cookies, skip consent popup)"
146146
link: "https://www.selenium.dev/documentation/webdriver/interactions/cookies/"
147147

@@ -166,7 +166,7 @@ advanced:
166166
link: "https://www.selenium.dev/documentation/webdriver/interactions/navigation/"
167167

168168
test_dependencies: # 4 pts | once
169-
done: false
169+
done: true
170170
description: "Make a test method depend on another using dependsOnMethods or dependsOnGroups — e.g. a logout test that only runs if login passed"
171171
link: "https://testng.org/#_test_methods_classes_and_groups"
172172

@@ -175,15 +175,15 @@ advanced:
175175
description: "Verify an e-mail was sent (e.g. registration activation link, password reset)"
176176

177177
random_data: # 8 pts | once
178-
done: false
178+
done: true
179179
description: "Generate random test data (e.g. random username, email) and use it in a test"
180180

181181
download_files: # 12 pts | once
182182
done: false
183183
description: "Download one or more files to a folder and verify they were saved"
184184

185185
config_file: # 6 pts | once
186-
done: false
186+
done: true
187187
description: "Store test settings in an external file (e.g. .properties, .yml, or .env) and read them at runtime — things like base URL, username, password, browser type. No hardcoded values in your test code"
188188

189189
javascript_executor: # 4 pts | once

tests/mytests/README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Video
2+
3+
https://www.youtube.com/watch?v=yrF7CgMraSs
4+
5+
# Gitlab Wiki page
6+
7+
https://docs.gitlab.com/ee/user/markdown.html
8+
9+
# Extend our code
10+
11+
```
12+
public int add(int aLeft, int aRight) {
13+
return aLeft + aRight;
14+
}
15+
```
16+
17+
If we have a more complex code and plenty test cases, we want to know what parts of the original code tested weakly.
18+
19+
# Code coverage
20+
21+
The code coverage shows us which lines of the code run by our tests.
22+
With this information we can find code that isn't used any tests, so if there is a bug in it, it does not reveals.
23+
24+
25+
# Jacoco
26+
27+
https://docs.gradle.org/current/userguide/jacoco_plugin.html
28+
29+
For JAVA we can use Jacoco to measure code coverage, we have to extend our gradle file only.
30+
31+
First we have to import, so we change plugins to the following:
32+
```
33+
plugins {
34+
id 'application'
35+
id 'java'
36+
id 'jacoco'
37+
}
38+
```
39+
40+
When we activates Jacoco plugin it automatically creates a `jacocoTestReport` task in our gradle project.
41+
We want to ask the gradle to run the code coverage report after every test, so we add
42+
```
43+
test {
44+
finalizedBy jacocoTestReport
45+
}
46+
```
47+
that activates the `jacocoTestReport` right after the `test` task finished.
48+
Therefore if we run `gradle test` it will create the code coverage as well.
49+
50+
If we want to make sure the test results are exists we can say for the gradle if we want to run directly the `jacocoTestReport` by the `gradle jacocoTestReport` command, then please run the `test` before by
51+
```
52+
jacocoTestReport {
53+
dependsOn test
54+
}
55+
```
56+
57+
So our new shiny *build.gradle* file:
58+
```
59+
plugins {
60+
id 'application'
61+
id 'java'
62+
id 'jacoco'
63+
}
64+
65+
repositories {
66+
mavenCentral()
67+
}
68+
69+
test {
70+
finalizedBy jacocoTestReport
71+
}
72+
jacocoTestReport {
73+
dependsOn test
74+
}
75+
76+
dependencies {
77+
implementation 'com.google.guava:guava:31.1-jre'
78+
}
79+
80+
testing {
81+
suites {
82+
test {
83+
useJUnit('4.13.2')
84+
}
85+
}
86+
}
87+
88+
application {
89+
mainClass = 'MultiplyTest.App'
90+
}
91+
```
92+
93+
By default it will create the report in `build/reports/jacoco/test/html` folder.
94+
95+
For more configuration: https://docs.gradle.org/current/userguide/jacoco_plugin.html
96+
97+
## If jacoco skipeed
98+
99+
Run `gradle clean` to clean the gradle build directory, that helps in many cases.
100+
101+
# Extend with function with branches
102+
103+
```
104+
public int max(int aLeft, int aRight) {
105+
if(aLeft > aRight){
106+
return aLeft;
107+
}else{
108+
return aRight;
109+
}
110+
}
111+
```
112+
113+
We can check in the report what lines tested exactly.
114+
115+
# How can get this on the server?
116+
117+
We have to define to the GitLab we want to save some information from the specific stage by extending with artifacts part the job descriptor.
118+
119+
```
120+
test_with_coverage:
121+
stage: test
122+
image: gradle:8.0.2
123+
script:
124+
- gradle test
125+
artifacts:
126+
paths:
127+
- build/reports/jacoco/test/html
128+
expire_in: 1 week
129+
```
130+
131+
More info: https://docs.gitlab.com/ci/jobs/job_artifacts/
132+
133+
From this point we can download from the job view directly our code coverage report or publish to somewhere in a next stage.
134+
135+
# Merge request closes issue
136+
137+
https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically
138+
139+
# Task
140+
141+
- Create a milestone titled "I learn how to use GitLab ([your name])".
142+
- Create a wiki page. Set the title to your name. As content:
143+
- Add a clickable link to google.
144+
- Add a code snippet into the page
145+
- Add link to your milestone
146+
- Add a link to one of your issue (created in the last session)
147+
- Copy the source files from this repository (Rectangle classes) and commit to the sandbox project onto a new branch.
148+
- Write test for the Rectangle classes (Functionality of Rectangle classes, exception as well, but Main class not needed to be tested).
149+
- Achieve 100% testing coverage of the source code with the tests.
150+
- Create a Merge request about your branch to the master, put a link to your wiki page and your milestone into the merge request and assign it to me @hudi89.

0 commit comments

Comments
 (0)