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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1k
テーブルをDELETEした
yuzneri
0
110
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
140
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
120
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
0
320
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
3.1k
yield再入門 #phpcon
o0h
PRO
0
790
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
400
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
670
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
420
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
120
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
410
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
230
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
330
Thoughts on Productivity
jonyablonski
76
5.3k
Navigating Weather and Climate Data
rabernat
0
410
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
190
A designer walks into a library…
pauljervisheath
211
24k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
200
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
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