Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Automatic Screenshots of your Django web applic...
Search
Raphael Michel
October 25, 2017
Programming
260
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Automatic Screenshots of your Django web application with py.test and Selenium
Raphael Michel
October 25, 2017
More Decks by Raphael Michel
See All by Raphael Michel
Plug-in architectures for Python web applications
raphaelm
0
78
Data Internationalization in Django
raphaelm
2
550
Other Decks in Programming
See All in Programming
1B+ /day規模のログを管理する技術
broadleaf
0
120
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
270
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
430
Creating Composable Callables in Contemporary C++
rollbear
0
180
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
260
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
450
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
230
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
150
Performance Engineering for Everyone
elenatanasoiu
0
250
Lessons from Spec-Driven Development
simas
PRO
0
230
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.8k
Featured
See All Featured
How to Ace a Technical Interview
jacobian
281
24k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
170
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
880
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Deep Space Network (abreviated)
tonyrice
0
220
Between Models and Reality
mayunak
4
360
Abbi's Birthday
coloredviolet
3
8.4k
Speed Design
sergeychernyshev
33
1.9k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Transcript
AUTOMATIC SCREENSHOTTING with Python, Django, py.test, and Selenium RAPHAEL MICHEL
MOTIVATION
INGREDIENTS
SELENIUM a remote control for your browser
CHROME HEADLESS $ chrome --headless
PY.TEST # content of test_sample.py def inc(x): return x +
1 def test_answer(): assert inc(3) == 5 $ py.test ======= test session starts ======== collected 1 item test_sample.py F ======= FAILURES ======== _______ test_answer ________ ... test_sample.py:5: AssertionError ======= 1 failed in 0.12 seconds ========
PY.TEST FIXTURES import pytest @pytest.fixture def smtp(): import smtplib return
smtplib.SMTP("smtp.gmail.com", 587, timeout=5) def test_ehlo(smtp): response, msg = smtp.ehlo() assert response == 250 assert 0 # for demo purposes
DJANGO pytest-django LiveServerTestCase
LET'S SET IT UP!
PYTEST.INI [pytest] DJANGO_SETTINGS_MODULE=pretix.testutils.settings python_functions = shot_* python_files = scene_* python_classess
= *Scene addopts =--driver Chrome
SCENES/CONFTEST.PY @pytest.fixture def user(): return User.objects.create_user( '
[email protected]
', 'john', fullname='John Doe'
)
SCENES/CONFTEST.PY @pytest.fixture def logged_in_client(live_server, selenium, user): selenium.get(live_server.url + '/control/login') selenium.implicitly_wait(10)
# Fill out name and password # Click button return selenium
SCENES/CONFTEST.PY @pytest.fixture def chrome_options(chrome_options): chrome_options.add_argument('headless') chrome_options.add_argument('window-size=1024x768')
AAAND… ACTION!
SCENES/SCENE_ORGA.PY @pytest.mark.django_db def shot_organizer_list(live_server, organizer, logged_in_client): logged_in_client.get( live_server.url + '/control/organizers/'
) screenshot(logged_in_client, 'organizer/list.png')
RUN IT $ py.test scenes … Results (45.80s): 9 passed
TADA!
pretix/pretix-screenshots
CONTACT ME! Raphael Michel
[email protected]
@_rami_ raphaelm pretix.eu
[email protected]
@pretixeu
pretix
MAY 23-27TH, 2018 HEIDELBERG, GERMANY 2018.DJANGOCON.EU