• python3.6+selenium_多个测试用例


    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2018/11/22 10:10
    # @File : unittest_test2_1.py
    
    '''多个用例写在同一个测试类'''
    import unittest
    from selenium import webdriver
    class SearchTests(unittest.TestCase):
        #初始化浏览器和url
        def setUp(self):
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(30)
            self.driver.maximize_window()
            self.driver.get("https://www.baidu.com/?tn=78000241_12_hao_pg")
    
        #通过分类搜索产品,校验返回的产品数量是否正确
        def test_search_by_category(self):
            self.search_file = self.driver.find_element_by_name('wd')
            self.search_file.clear()
            self.search_file.send_keys('phones')
            self.search_file.submit()
            products = self.driver.find_element_by_xpath('//*[@id="5"]/h3/a')
            '''
            products = self.driver.find_element('xpath','//*[@id="5"]/h3/a')
            find_element()定位方法,
                by_id= "id"
                by_xpath = "xpath"
                by_link_text = "link text"
                by_partial_text = "partial link text"
                by_name = "name"
                by_tag_name = "tag name"
                by_class_name = "class name"
                by_css_selector = "css selector"
            等同于find_element_by方法
            find_elements()也等同于find_elements_by()方法
            '''
            #print('==========')
            print(products.text)
            #print('=========')
            #assert (u'iPhone - Apple (中国)')in products.text
            p=[products,]
            print(len(p))
            self.assertEqual(1,len(p))
    
        #再创建一个测试用例
        def test_search_by_name(self):
            self.search_file = self.driver.find_element_by_name('wd')
            self.search_file.clear()
            self.search_file.send_keys('salt shaker')
            self.search_file.submit()
            product = self.driver.find_element_by_xpath('//*[@id="1"]/h3/a')
            p = [product,]
            self.assertEqual(1,len(p))
    
        #清理所有的 初始化值
        def tearDown(self):
            self.driver.quit()
    
    #运行测试,传递verbosity参数,以便使详细的测试总量显示在控制台
    if __name__=='__main__':
        unittest.main(verbosity=2)
  • 相关阅读:
    pgsql 时间转时间戳
    java SHA-1加密
    java 输出json文件
    按照指定字符串截取文本
    java 科学计数法转换
    【原创】几个常用机场的对比
    【原创】Google Cloud服务器路由分析
    批量转换文件Unicode到中文
    博客搬家
    关于zookeeper
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/10384170.html
Copyright © 2020-2023  润新知