Created
January 28, 2014 16:55
-
-
Save ishuah/8671610 to your computer and use it in GitHub Desktop.
Python/Django - Take screenshots of pages that require authentication with Selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this would be in your view.py | |
from pyvirtualdisplay import Display | |
from selenium import webdriver | |
def take_screenshot(request): | |
HOST = request.get_host() | |
display = Display(visible=0, size=(1920,1440)) | |
display.start() | |
browser = webdriver.Firefox() | |
#before we can add a cookie, we need to access the page first | |
browser.get(HOST) | |
browser.add_cookie({ 'name': 'sessionid', 'value': request.COOKIES['sessionid'], 'path': '/', 'domain': HOST }) | |
#assuming your user is a SuperAdmin | |
browser.get(HOST+'/admin/') | |
browser.save_screenshot(MEDIA_ROOT+'/test.png') | |
browser.quit() | |
display.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment