zoukankan      html  css  js  c++  java
  • selenium 实战

    说明:

    1.包内实现 函数方法 

    2.unittest实现 case的组合

    3.在unitest 中通过实例调用 ,完成不同的case场景

    4.用于测试数据和测试代码分离

    ——————————————————————————

    以下是包内的方法

    ---》method.method_login 包
    #!/user/bin/python3
    #coding=utf-8
    #2020/3/25 --17:28
    #author :hui
    import time
    from selenium import webdriver
    dr = webdriver.Chrome() #通过全局设置浏览器只启动一次
    class Login(object):
    def __init__(self,username,password,driver=dr):
    self.username = username
    self.password = password
    self.driver = driver
    self.url = 'http://xxx.xx.xxx.250:xxx/' #公司地址
    self.driver.get(self.url)
    time.sleep(3)
    self.driver.find_element_by_id('username').send_keys(self.username)
    time.sleep(2)
    self.driver.find_element_by_id('password').send_keys(self.password)
    time.sleep(2)
    self.driver.find_element_by_id('submit').click()
    time.sleep(2)

    ——————————————————————————————————————————————————————————————————————————————————

    以下是 unittest 方法:

    #!/user/bin/python3
    #coding=utf-8
    #2020/3/25 --18:04
    #author :hui

    '''
    1.包实现 方法
    2.unitrest 实现 测试的集合
    '''

    from method.method_login import Login #导入 方法包
    # 单元测试必须要引入unittest模块
    import unittest

    class TestCase(unittest.TestCase):
    @classmethod
    def setUp(self):
    print("Test Start测试开始")


    def test01(self):
    '''用户名为空'''
    s=Login("","11111")
    def test02(self):
    '''密码为空'''
    s=Login("admin","")
    def test03(self):
    '''都为空登录'''
    s=Login("","")
    def test04(self):
    '''正确登录'''
    s = Login("admin","111111")

    # @classmethod
    # def tearDown(self):
    # print("Test end测试结束")

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











  • 相关阅读:
    多态
    封装
    继承
    面向对象
    2.机器学习相关数学基础
    作业1 机器学习概述
    作业15 语法制导的语义翻译
    作业14 算符优先分析
    作业13 自下而上语法分析
    作业12 实验二 递归下降语法分析
  • 原文地址:https://www.cnblogs.com/yanhuidj/p/12568539.html
Copyright © 2011-2022 走看看