• 10.生成百度测试用例.py


    import unittest
    from Report import HTMLTestRunner
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    class TestCase01(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
    cls.driver = webdriver.Chrome()
    cls.driver.implicitly_wait(10)

    @classmethod
    def tearDownClass(cls):
    cls.driver.quit()

    def test_case_01(self):
    self.driver.get('https://www.baidu.com/')
    title = self.driver.title
    self.assertEqual(title, '百度一下,你就知道')

    def test_case_02(self):
    self.driver.get('https://www.hao123.com/')
    title = self.driver.title
    self.assertEqual(title, 'hao123 上网从这里开始')

    def test_case_03(self):
    self.driver.get('https://pythonav.com/login/')
    self.driver.find_element_by_id('id_username').send_keys('亚洲')
    self.driver.find_element_by_id('id_password').send_keys('喜欢bao哥')
    code = self.driver.find_element_by_id('id_code')
    code.send_keys('abc', Keys.ENTER)
    msg = self.driver.find_element_by_xpath('//*[@id="fm"]/div[3]/div/div[1]/span').text
    if '验证码错误,请重新输入。' == msg:
    # self.driver.save_screenshot('error.png')
    self.assertFalse('验证码错误,请重新输入。')

    if __name__ == '__main__':
    suite = unittest.makeSuite(TestCase01)
    f = open('report.html', 'wb')
    HTMLTestRunner(
    stream=f,
    verbosity=2,
    title='百度首页测试报告',
    description='判断title是否符合预期',
    tester='张开'
    ).run(suite)

  • 相关阅读:
    1094 纪念品分组
    1803 凌乱的yyy
    1181 数列分段1
    1223排队接水
    1616 疯狂的采药(完全背包问题)
    1305 新二叉树
    1280 尼克的任务
    1020 导弹拦截
    快速学会如何使用Shiro
    mysql 让清空表且自增的id重新从0开始的命令
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12292579.html
Copyright © 2020-2023  润新知