selenium系列-自动化测试模型

自动化测试模型可以认为是自动化测试框架与工具的设计的思想。随着自动化测试技术的发展,演化为一下几种模型:线性测试、模块化驱动测试、数据驱动测试和关键字驱动测试。

1.线性测试:每个测试脚本相对独立,且不产生其他依赖与调用,这也是早期自动化测试的一种形式,就是单纯的来模拟用户完整的操作场景。

2.模块化驱动测试:借鉴了编程语言中的模块化的思想,把重复的操作独立成公共模块,当用例执行过程中需要用到这一模块时则被调用,最大限度的消除了重复,提高测试用例的可维护性。

3.数据驱动测试:数据驱动测试说的直白些就是数据的参数化,因为输入数据的不通从而引起输出结果的不同。

4.关键字驱动测试:理解数据驱动,无非是把“数据”换成“关键字”,通过关键字的改变引起测试结果的改变。

实例:通过2中方式完成参数化数据登陆,第一种方式模块化

public.py文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/python
#coding:utf-8
#############################################################
#操作:参数化DLMMCP系统的用户名和密码
#date:20170727
#version:V1.0
#author:ZLL
##############################################################
class Login():
    def user_login(self,driver,username,password):
        driver.find_element_by_id("username").clear()
        driver.find_element_by_id("username").send_keys(username)
        driver.find_element_by_id("password").clear()
        driver.find_element_by_id("password").send_keys(password)
        driver.find_element_by_id("enter").click()
    def user_logout(self,driver):
        driver.find_element_by_xpath("/html/body/div[1]/div[1]/div/div[2]/div/div[1]/a/i").click()
        driver.find_element_by_xpath("/html/body/div[1]/div[1]/div/div[2]/div/div[2]/label/a/span").click()
        driver.quit()

login.py文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
#coding:utf-8
#############################################################
#操作:分别通过服务委和企业用户登录Dlmmcp系统;
#version:V1.0
#author:ZLL
##############################################################
from selenium import webdriver
from public import Login
 
class LoginTest():
    def __init__(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(10)
        self.driver.get("http://192.168.39.141:8080/dlmmcp/index.action")
 
    #服务委用户
    def test_admin_login(self):
        username = 'yjs'
        password = 'yjs12345678'
        Login().user_login(self.driver,username,password)
        self.driver.quit()
 
    #企业用户
    def test_company_login(self):
        username = 'yyk'
        password = 'yyk12345678'
        Login().user_login(self.driver,username,password)
        self.driver.quit()
 
LoginTest().test_admin_login()
LoginTest().test_company_login()

第二种方式,通过读取txt文件实现

user_info.txt文件内容

yyk,yyk12345678
yjs,yjs12345678
root,root12345678
www,www12345678

login.py文件源码(public.py文件内容不变):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
#coding:utf-8
#############################################################
#操作:1.读取txt文件,将用户名密码参数化登录Dlmmcp系统;
#data:20170727
#version:V1.0
#author:ZLL
##############################################################
from selenium import webdriver
from public import Login
import time 
 
class LoginTest():
    def __init__(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(10)
        self.driver.get("http://192.168.39.141:8080/dlmmcp/index.action")
 
    def test_admin_login(self): 
        Login().user_login(self.driver,username,password)
        time.sleep(2)
        self.driver.quit()
 
#从txt文本中读取用户名和密码
 
if __name__ == "__main__":
    user_file = open('user_info.txt','r')   #以“r”形式打开user_info.txt文件
    lines = user_file.readlines()           #读取每一行
    user_file.close()
    for line in lines:
        username = line.split(',')[0]        #user_info.txt文件存放yyk\yjs\root\www等4个真实用户,循环登录
        password = line.split(',')[1]
        LoginTest().test_admin_login()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值