36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import os
|
|
import time
|
|
from selenium.webdriver.firefox.webdriver import WebDriver
|
|
from selenium.webdriver.common.keys import Keys
|
|
from selenium.common.exceptions import WebDriverException
|
|
from selenium.webdriver.common.by import By
|
|
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
|
|
|
|
|
class HomeTests(StaticLiveServerTestCase):
|
|
fixtures = ['accounts.json', 'products.json']
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
cls.browser = WebDriver()
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.browser.quit()
|
|
super().tearDownClass()
|
|
|
|
def test_home_page_has_product_list(self):
|
|
self.login()
|
|
self.assertTrue(
|
|
self.browser.find_element(By.CSS_SELECTOR, '.product__list')
|
|
)
|
|
|
|
def login(self):
|
|
self.browser.get('%s%s' % (self.live_server_url, '/accounts/login/'))
|
|
username_input = self.browser.find_element(By.NAME, "login")
|
|
username_input.send_keys('john@example.com')
|
|
password_input = self.browser.find_element(By.NAME, "password")
|
|
password_input.send_keys('Bf25XBdP4vdt2X9L')
|
|
self.browser.find_element(By.XPATH, '//input[@value="Login"]').click()
|