Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.staticfiles.testing import StaticLiveServerTestCase
- from django.contrib.auth.models import User
- from selenium import webdriver
- class TestName(StaticLiveServerTestCase):
- @classmethod
- def setUpClass(cls):
- super().setUpClass()
- cls.browser = webdriver.Firefox()
- @classmethod
- def tearDownClass(cls):
- cls.browser.quit()
- super().tearDownClass()
- def setUp(self):
- super(TestName, self).setUp()
- test_user = User.objects.create(username='Testuser')
- test_user.set_password('senha8dg')
- test_user.save()
- # Login the user
- self.assertTrue(self.client.login(username='Testuser', password='senha8dg'))
- # Add cookie to log in the browser
- cookie = self.client.cookies['sessionid']
- self.browser.get(self.live_server_url) # visit page in the site domain so the page accepts the cookie
- self.browser.add_cookie({'name': 'sessionid', 'value': cookie.value, 'secure': False, 'path': '/'})
Add Comment
Please, Sign In to add comment