五、自动化测试框架
1、单元测试框架unittest
class loginTests(unittest.TestCase):
①开始的初始化部分
@classmethod
def setUpClass(cls):
cls.success_url = '######################'
cls.url='###################'
cls.username='################'
cls.password='##############'
# create a new Chrome session
cls.driver = webdriver.Firefox()
ursLogin(cls.driver,cls.url,cls.username,cls.password,cls.success_url)
time.sleep(1)
②中间的测试用例部分
def test_UI_by_xpath(self):
#check room enter
choiseRoomTitle=self.driver.find_element_by_xpath("/html/body/nav/div/div[1]/a")
self.assertTrue(choiseRoomTitle.is_displayed())
self.assertEqual(choiseRoomTitle.text,u'直播间后台管理系统')
try:
self.driver.find_element_by_xpath("//div[@class='m-choose-room']/div/div//div[@class='thumbnail']").click()
time.sleep(1)
# 验证跳转详情页是否成功
if self.driver.current_url=="#####################":
print u"进入分析师详情页 sccessful"
time.sleep(0.5)
else:
print u"无法进入分析师详情页 failure"
except:
print u"进入异常 Exception"
print self.driver.title
print self.driver.current_url
③结尾部分
@classmethod
def tearDown(cls):
# close the browser window
cls.driver.quit()
if __name__ == "__main__":
unittest.main()