import unittest
from time import sleep
from selenium import webdriver
class TestFunctions(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome()
url_login = 'http://172.16.121.105/'
cls.driver.get(url_login)
cls.driver.maximize_window()
sleep(1)
def test_login(self):
self.driver.find_element_by_id("username").send_keys('admin')
self.driver.find_element_by_xpath("//input[@id='password']").send_keys("kedacom#123")
result = self.driver.find_element_by_xpath("//input[@type='button']").click()
now_url = self.driver.current_url
sleep(1)
self.driver.switch_to.window(self.driver.window_handles[-1])
sleep(3)
print('URL地址:' + now_url[0:22])
url_login = 'http://172.16.121.105/'
if url_login == now_url[0:22]:
print('URL校验通过')
else:
raise Exception('URL校验失败')
sleep(1)
@classmethod
def tearDownClass(cls):
cls.driver.quit()
if __name__ == '__main__':
tests = [TestFunctions("test_login"), ]
suite = unittest.TestSuite()
suite.addTests(tests)
runner = unittest.TextTestRunner(verbosity=1)
runner.run(suite)
|