zoukankan      html  css  js  c++  java
  • 自动化测试模型

    概念:

    1、线性测试:单纯模拟用户完整的操作场景,每个脚本相对独立,且不产生依赖与调用。

    2、模块化与类库:把重复的操作单独封装成公共模块,需要时进行调用。

    3、数据驱动测试:参数化测试数据。

    4、关键字驱动测试:把自动化操作封装成为“关键字”

    模块化与参数化:

    163邮箱登录与退出:save as: test_mail.py

    from selenium import webdriver
    from time import sleep
    
    driver = webdriver.Chrome()
    driver.get("https://mail.163.com/")
    driver.implicitly_wait(10)
    
    #登录
    iframe = driver.find_element_by_css_selector("iframe")
    driver.switch_to.frame(iframe)
    driver.find_element_by_css_selector("[name = 'email']").send_keys("****")
    driver.find_element_by_css_selector("[name = 'password']").send_keys("***")
    driver.find_element_by_id("dologin").click()
    driver.switch_to.default_content()
    
    #退出
    driver.find_element_by_id("_mail_icon_0_0").click()
    driver.find_element_by_id("_mail_component_72_72").click()

    模块化:save as :module.py

    class Mail:
        def __init__(self,driver):
            self.driver = driver
    
        def login(self):
            """登录"""
    
            iframe = self.driver.find_element_by_css_selector("iframe")
            self.driver.switch_to.frame(iframe)
            self.driver.find_element_by_css_selector("[name = 'email']").send_keys("***")
            self.driver.find_element_by_css_selector("[name = 'password']").send_keys("***")
            self.driver.find_element_by_id("dologin").click()
            self.driver.switch_to.default_content()
    
        def logout(self):
            """退出"""
            self.driver.find_element_by_id("_mail_icon_0_0").click()
            self.driver.find_element_by_id("_mail_component_72_72").click()
        

    修改test_mail.py文件调用Mail中的login() 、logout()

    from selenium import webdriver
    from time import sleep
    from module import Mail
    
    driver = webdriver.Chrome()
    driver.get("https://mail.163.com/")
    driver.implicitly_wait(10)
    
    mail = Mail(driver)
    
    mail.login()
    
    mail.logout()

    参数化(用户名密码)登录:修改module代码如下:

    class Mail:
        def __init__(self,driver):
            self.driver = driver
    
        def login(self,username,password):
            """登录"""
    
            iframe = self.driver.find_element_by_css_selector("iframe")
            self.driver.switch_to.frame(iframe)
            self.driver.find_element_by_css_selector("[name = 'email']").clear()
            self.driver.find_element_by_css_selector("[name = 'email']").send_keys(username)
            self.driver.find_element_by_css_selector("[name = 'password']").clear()
            self.driver.find_element_by_css_selector("[name = 'password']").send_keys(password)
            self.driver.find_element_by_id("dologin").click()
            self.driver.switch_to.default_content()
    

    不同数据调用Login():

    from selenium import webdriver
    from time import sleep
    from module import Mail
    
    driver = webdriver.Chrome()
    driver.get("https://mail.163.com/")
    driver.implicitly_wait(10)
    
    mail = Mail(driver)
    
    mail.login("error","error")
    sleep(2)
    mail.login("123","123")
  • 相关阅读:
    iOS 开发中的坑与相关技巧
    SDK 封装的相关看法
    线程问题---在iPad上会崩溃,在iPhone上不会崩溃
    添加新手引导页需要注意的几个小点
    iOS 七牛云上传并获取图片----【客户端】
    iOS 线程相关-----绝对de干货
    Vue.js 基础示例
    lib-flexible 结合 WKWebView 的样式错乱解决方法
    基于CommentCoreLibrary简单的弹幕实现
    页面上动态编译及执行java代码
  • 原文地址:https://www.cnblogs.com/yijierui/p/13449577.html
Copyright © 2011-2022 走看看