Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
968caaac
Commit
968caaac
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add selenium test for PDF generation
parent
827b235c
No related branches found
No related tags found
1 merge request
!464
Resolve "Support PDF generation via a headless Chromium running in the background using celery"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/core/tests/browser/test_selenium.py
+35
-13
35 additions, 13 deletions
aleksis/core/tests/browser/test_selenium.py
conftest.py
+1
-0
1 addition, 0 deletions
conftest.py
with
36 additions
and
13 deletions
aleksis/core/tests/browser/test_selenium.py
+
35
−
13
View file @
968caaac
import
os
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.test
import
override_settings
from
django.test.selenium
import
SeleniumTestCase
,
SeleniumTestCaseBase
from
django.urls
import
reverse
import
pytest
from
selenium.webdriver.support.wait
import
WebDriverWait
from
aleksis.core.models
import
Person
pytestmark
=
pytest
.
mark
.
django_db
...
...
@@ -14,7 +19,8 @@ SeleniumTestCaseBase.browsers = list(
)
SeleniumTestCaseBase
.
selenium_hub
=
os
.
environ
.
get
(
"
TEST_SELENIUM_HUB
"
,
""
)
or
None
@pytest.mark.usefixtures
(
"
celery_worker
"
)
@override_settings
(
CELERY_BROKER_URL
=
"
memory://localhost//
"
)
class
SeleniumTests
(
SeleniumTestCase
):
serialized_rollback
=
True
...
...
@@ -29,18 +35,11 @@ class SeleniumTests(SeleniumTestCase):
else
:
return
False
def
test_index
(
self
):
self
.
selenium
.
get
(
self
.
live_server_url
+
"
/
"
)
assert
"
AlekSIS
"
in
self
.
selenium
.
title
self
.
_screenshot
(
"
index.png
"
)
def
test_login_default_superuser
(
self
):
username
=
"
admin
"
password
=
"
admin
"
def
_login
(
self
,
username
=
"
admin
"
,
password
=
"
admin
"
,
with_screenshots
=
False
):
# Navigate to configured login page
self
.
selenium
.
get
(
self
.
live_server_url
+
reverse
(
settings
.
LOGIN_URL
))
self
.
_screenshot
(
"
login_default_superuser_blank.png
"
)
if
with_screenshots
:
self
.
_screenshot
(
"
login_default_superuser_blank.png
"
)
# Find login form input fields and enter defined credentials
self
.
selenium
.
find_element_by_xpath
(
...
...
@@ -49,11 +48,34 @@ class SeleniumTests(SeleniumTestCase):
self
.
selenium
.
find_element_by_xpath
(
'
//label[contains(text(),
"
Password
"
)]/../input
'
).
send_keys
(
password
)
self
.
_screenshot
(
"
login_default_superuser_filled.png
"
)
if
with_screenshots
:
self
.
_screenshot
(
"
login_default_superuser_filled.png
"
)
# Submit form by clicking django-two-factor-auth's Next button
self
.
selenium
.
find_element_by_xpath
(
'
//button[contains(text(),
"
Login
"
)]
'
).
click
()
self
.
_screenshot
(
"
login_default_superuser_submitted.png
"
)
if
with_screenshots
:
self
.
_screenshot
(
"
login_default_superuser_submitted.png
"
)
def
_create_person
(
self
,
username
=
"
admin
"
):
user
=
User
.
objects
.
get
(
username
=
username
)
person
=
Person
.
objects
.
create
(
user
=
user
,
first_name
=
"
Jane
"
,
last_name
=
"
Doe
"
)
return
person
def
test_index
(
self
):
self
.
selenium
.
get
(
self
.
live_server_url
+
"
/
"
)
assert
"
AlekSIS
"
in
self
.
selenium
.
title
self
.
_screenshot
(
"
index.png
"
)
def
test_login_default_superuser
(
self
):
self
.
_login
(
"
admin
"
,
"
admin
"
,
with_screenshots
=
True
)
# Should redirect away from login page and not put up an alert about wrong credentials
assert
"
Please enter a correct username and password.
"
not
in
self
.
selenium
.
page_source
def
test_pdf_generation
(
self
):
self
.
_login
()
self
.
_create_person
()
self
.
selenium
.
get
(
self
.
live_server_url
+
reverse
(
"
test_pdf
"
))
el
=
WebDriverWait
(
self
.
selenium
,
10
).
until
(
lambda
d
:
"
.pdf
"
in
self
.
selenium
.
current_url
)
self
.
_screenshot
(
"
pdf.png
"
)
This diff is collapsed.
Click to expand it.
conftest.py
0 → 100644
+
1
−
0
View file @
968caaac
pytest_plugins
=
(
"
celery.contrib.pytest
"
,
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment