-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
59 lines (44 loc) · 1.78 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from django.contrib.auth.models import User
import time
import django
# class Hosttest(LiveServerTestCase):
# def testhomepage(self):
# options = Options()
# options.headless = True
# driver = webdriver.Chrome(options=options)
# driver.get(self.live_server_url)
# # try driver.get(self.live_server_url) if driver.get('http://127.0.0.1:8000/') does not work
# assert "Hello, world!" in driver.title
class LoginFormTest(LiveServerTestCase):
port = 8000
host = '127.0.0.1'
# def setUp(self):
# self.selenium = webdriver.Chrome(executable_path="/Users/mueezkhan/django-test/chromedriver")
# super(LoginFormTest, self).setUp()
# def tearDown(self):
# self.selenium.quit()
# super(LoginFormTest, self).tearDown()
def testform(self):
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
# driver = self.selenium
# super(LoginFormTest, self).setUp()
driver.get(f"http://127.0.0.1:8000/accounts/login")
# user = User.objects.create_user('kamil', '[email protected]', 'kamil')
# print(user)
# time.sleep(1)
user_name = driver.find_element_by_name('username')
user_password = driver.find_element_by_name('password')
time.sleep(3)
submit = driver.find_element_by_id('submit')
user_name.send_keys('kamil')
user_password.send_keys('kamil')
submit.send_keys(Keys.RETURN)
time.sleep(3)
print(driver.page_source)
assert 'User: kamil' in driver.page_source