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
270
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
83
Data Internationalization in Django
raphaelm
2
560
Other Decks in Programming
See All in Programming
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
260
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
410
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
260
プロポーザルを書いてもらう
pvcresin
0
580
My Marp Sample
sinoue0108
0
120
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
240
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
730
Press start. Python's next generation.
willingc
PRO
3
190
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
500
Flow は今どうなっているか
mizdra
PRO
0
720
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
510
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
400
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
790
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Designing Powerful Visuals for Engaging Learning
tmiket
1
510
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
550
Code Reviewing Like a Champion
maltzj
528
40k
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