zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    Spring Cloud(4):断路器(Hystrix)
    Spring Cloud(3):配置服务(Config)
    Spring Cloud(2):服务发现(Eureka)
    Docker常用命令
    Spring Cloud(1):概览
    Spring Cloud(0):目录
    Spring Boot JDBC:加载DataSource过程的源码分析及yml中DataSource的配置
    Java集合(7):散列与散列码
    [Linux]RabbitMQ
    [Linux]查看硬件及操作系统信息
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12292579.html
Copyright © 2011-2022 走看看