美文网首页
使用python参数化测试

使用python参数化测试

作者: 测试老杨 | 来源:发表于2019-01-17 14:41 被阅读7次

思路

1)使用parameterized工具进行参数化(将测试数据传递给参数)
2)使用selenium框架操作浏览器
3)使用unittest框架进行验证

设计python脚本

# coding=utf-8

from time import *
from selenium.webdriver import *
import unittest
from parameterized import parameterized
import sys
reload(sys)
sys.setdefaultencoding('utf-8')


class SearchTest(unittest.TestCase):
    """
    搜索测试类
    """
    @parameterized.expand([
        ("https://cn.bing.com", "sb_form_q", "sb_form_go", u"赵丽颖", u"冯绍峰"),
        ("https://www.sogou.com/", "query", "stb", u"赵薇", u"黄有龙")
    ])
    def test_search(self, url, search_box_id, search_btn_id, keyword, expected):
        """
        测试用例
        :param url:
        :param search_box_id:
        :param search_btn_id:
        :param keyword:
        :param expected:
        :return:
        """
        driver = Chrome()    # 创建驱动工具
        driver.maximize_window()        # 最大化窗口
        driver.implicitly_wait(15)      # 设置默认的等待时长
        driver.get(url)      # 打开必应搜索
        driver.find_element_by_id(search_box_id).clear()     # 清空搜索框里面的文本
        driver.find_element_by_id(search_box_id).send_keys(keyword)  # 输入关键字
        driver.find_element_by_id(search_btn_id).click()     # 点击搜索按钮
        sleep(3)
        self.assertTrue(expected in driver.page_source)
        driver.close()


if __name__ == "__main__":
    unittest.main()

运行python脚本

selenium190117.gif

扫码关注本人公众号

image.png

相关文章

网友评论

      本文标题:使用python参数化测试

      本文链接:https://www.haomeiwen.com/subject/jkdidqtx.html