公共方法:
from selenium import webdriver
import time
def login(self):
self.driver.find_element_by_xpath('/html/body/div/div/form/div[1]/select').click()
time.sleep(2)
self.driver.find_element_by_xpath('/html/body/div/div/form/div[1]/select/option[2]').click()
time.sleep(1)
self.driver.find_element_by_xpath('/html/body/div/div/form/div[2]/input').send_keys('142630170611011230')
time.sleep(1)
self.driver.find_element_by_xpath('/html/body/div/div/form/div[3]/input').send_keys('123456')
time.sleep(2)
self.driver.find_element_by_xpath('/html/body/div/div/form/button').click()
def logout(self):
self.driver.find_element_by_link_text('退出').click()
登录首页测试用例:
from selenium import webdriver
import unittest
import time
from SELENIUM.sx_public import login ,logout
class Testlogin(unittest.TestCase):
#初始化方法,用例执行时先执行这个方法
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(2)
self.url = '测试地址(url)'
self.verificationErrors = []
def testlogin(self):
driver = self.driver
self.driver.get(self.url)
#调用登录方法
login(self)
text = self.driver.find_element_by_class_name('text-muted').text
self.assertEqual(text, '智慧填报系统')
#调用退出方法
logout(self)
#善后工作,关闭浏览器,并验证有没有错误信息
def tearDown(self):
driver = self.driver
self.driver.quit()
self.assertEqual([],self.verificationErrors)
if __name__ == '__main__':
unittest.main()
网友评论