总结Selenium自动化测试方法(五)自动化测试框架

五、自动化测试框架

1、单元测试框架unittest

class loginTests(unittest.TestCase):

①开始的初始化部分

@classmethod

def setUpClass(cls):

cls.success_url = 'http://qz.fa.163.com/management/room/analyst#choose-room'

cls.url='http://qz.fa.163.com/login'

cls.username='urstest379_88@163.com'

cls.password='qwer1234'

# 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=="http://qz.fa.163.com/management/room/analyst#room/76":

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()

上一篇:js1常用的东西


下一篇:iOS知名第三方框架和流行APP们所用的第三方框架小结