当前位置:网站首页>Login and parameterization of interface test
Login and parameterization of interface test
2022-06-11 07:53:00 【zljun8210】
I studied before UI automated testing , Today, let's look at interface testing , Realize the login and parameterization of a project , The code is as follows :
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: LoginsTest.py
Description :
Author : Zeng Liangjun
QQ: 277099728
Date: 8/11/2021 3:46 PM
-------------------------------------------------
Change Activity:
8/11/2021:
-------------------------------------------------
"""
__author__ = 'ljzeng'
import unittest
from urllib import parse
import requests
import uuid
import random
import time
import ddt
sn = random.uniform(0,1) # Used to generate random floating point numbers
uid = str(uuid.uuid4())
uid = ''.join(uid.split('-')) # Used to generate UUID( Universal unique identification code )
url = 'http://*/Host.ashx?SN=%s' %sn
testdata = (('ad','1',''), # Correct user name and password
('x','a','Invalid Username or Password.'), # Users who don't exist
('ficro','2','Invalid Username or Password.'),
('ficro','3','Invalid Username or Password.'),
('unactive','Win.12345','User account is not currently active.'), # Inactive users
('ficro','d','The user account has been locked.') # User locked
)
@ddt.ddt
class LoginsTest(unittest.TestCase):
@ddt.data(*testdata)
@ddt.unpack
def test_login(self, user, pw, mess):
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie': uid,
'Proxy-Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
headerout = {
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': uid
}
datas = '{"LanguageID":"en-us","UtcOffset":-480,"Flag":0,"AppName":"","ServiceType":"","MethodName":"LoginSystem",' \
'"Parameters":["%s","%s",""],"RequestTime":633687529425210000}' % (user, pw)
datat = parse.quote(datas)
req = requests.post(url=url, data=datat, headers=headers)
res = req.text.split('{')[-1:]
res = res[0]
print("\n Currently logged in user : ",user)
code = res.split(':')[1][0]
expms = mess
time.sleep(1)
if code == "0":
print("Test Pass! ")
# G5 If the user in the project has logged in , Must exit later , Otherwise, you will be prompted when you log in with this account next time Signed in elsewhere
time.sleep(5)
outdata = {'logout': 'logout'}
logout = requests.post(url='http://*/loginSession.ashx', data=outdata,
headers=headerout)
print(logout.text)
elif expms in res:
print("Test Pass! ")
else:
print("Test Fail !")
if __name__ == '__main__':
unittest.main()边栏推荐
- C language - growth diary-04- preliminary exploration of local variables (local variables)
- 134. gas station
- 【集群】haproxy负载均衡
- Collation of basic knowledge of intermediate development of Andrews (for interview)
- Image processing operation record
- 【AtCoder2304】Cleaning
- 【集群】LVS+keepalived高可用集群
- Figure seamless database integration tushare interface
- Lesson 1 about Xiaobai's C language
- [noip2016 d1t3] changing classrooms (expectation dp+floyd) (trap of extreme thinking!)
猜你喜欢

二本毕业,银行外包测试工作 4 个月有余。聊聊一些真实感受 ...

C language - Growth Diary -02- function

如何做好空状态设计?来看这份全面总结

A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language

零基础自学SQL课程 | OUTER JOIN外连接

使用 COCO 数据集训练 YOLOv4-CSP 模型

C language lesson 2

2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings

Batch splice string

How to output the percent sign "%" in printf function in C language
随机推荐
Remote office experience | community essay solicitation
String Simulation Implementation
Storage of floating point in memory
Introduction to operations research
forEach 中 return 和 for 中 break
Crawl Baidu Baipin dynamic page
Activity中,View#postDelay会导致内存泄漏,但是不会影响Activity的生命周期执行。
二本畢業,銀行外包測試工作 4 個月有餘。聊聊一些真實感受 ...
Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
Getting started with bladed tutorial (video)
Socket [5] - struct linker usage
860. 柠檬水找零
C language lesson 2
Sort - select sort
Simple configuration of vscade
Simple use of string
Remote office experience sharing | community essay solicitation
multi-sig SC
[poj3691] DNA repair (AC automata +dp)
Bidirectional linked list simple template (pointer version)