添加获取路径

This commit is contained in:
汪杰 2022-07-04 19:31:24 +08:00
parent d818497463
commit faceffa096
18 changed files with 119 additions and 492 deletions

View File

@ -0,0 +1,23 @@
# !/usr/bin/python
# -*- coding:utf-8 -*-
# @Time : 2022/7/1 20:47
# @Author : wangjie
# @File : dir_path_config.py
# @project : SensoroApi
import os
# 当前项目的路径
BASE_DIR = os.path.split(os.path.split(os.path.abspath(__file__))[0])[0]
# common目录的路径
COMMON_DIR = os.path.join(BASE_DIR, 'common')
# configs目录的路径
CONFIGS_DIR = os.path.join(BASE_DIR, 'configs')
# datas目录的路径
DATAS_DIR = os.path.join(BASE_DIR, 'datas')
# pageApi目录的路径
PAGE_API_DIR = os.path.join(BASE_DIR, 'pageApi')
# testCase目录的路径
TEST_CASE_DIR = os.path.join(BASE_DIR, 'testCase')
# utils目录的路径
UTILS_DIR = os.path.join(BASE_DIR, 'utils')

View File

@ -8,7 +8,7 @@
import pytest import pytest
from py.xml import html from py.xml import html
from page_api.login import Login from pageApi.login import Login
@pytest.fixture(scope="session", autouse=False) @pytest.fixture(scope="session", autouse=False)

View File

@ -5,7 +5,7 @@
- ['12345678901','111111','手机号码格式不正确'] - ['12345678901','111111','手机号码格式不正确']
#手机号错误,登录失败 #手机号错误,登录失败
- ['13718395479','111111','手机号或验证码错误'] - ['13718395479','111111','该手机号尚未注册']
#验证码错误,登录失败 #验证码错误,登录失败
- ['13718395478','123456','手机号或验证码错误'] - ['13718395478','123456','手机号或验证码错误']

View File

@ -5,4 +5,4 @@
- ['12345678901','手机号码格式不正确'] - ['12345678901','手机号码格式不正确']
#手机号非平台号码,获取验证码成功 #手机号非平台号码,获取验证码成功
- ['13718395479','OK'] - ['13718395479','该手机号尚未注册']

4
run.py
View File

@ -5,7 +5,7 @@ import os
import pytest import pytest
from common.mail_sender import MailSender from common.mail_sender import MailSender
from tools.get_yaml_data import get_yaml_data from utils.get_yaml_data import get_yaml_data
if __name__ == '__main__': if __name__ == '__main__':
# # 执行pytest单元测试生成 Allure原始报告需要的数据存在 /Temp 目录 # # 执行pytest单元测试生成 Allure原始报告需要的数据存在 /Temp 目录
@ -31,4 +31,4 @@ if __name__ == '__main__':
smtp_domain=config['smtp_domain'], smtp_domain=config['smtp_domain'],
smtp_port=config['smtp_port'], smtp_port=config['smtp_port'],
) )
ms.attach_text(text_to_send).attach_file(file_path).send() # ms.attach_text(text_to_send).attach_file(file_path).send()

View File

@ -1,461 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Test Report</title>
<style>body {
font-family: Helvetica, Arial, sans-serif;
font-size: 12px;
/* do not increase min-width as some may use split screens */
min-width: 800px;
color: #999;
}
h1 {
font-size: 24px;
color: black;
}
h2 {
font-size: 16px;
color: black;
}
p {
color: black;
}
a {
color: #999;
}
table {
border-collapse: collapse;
}
/******************************
* SUMMARY INFORMATION
******************************/
#environment td {
padding: 5px;
border: 1px solid #E6E6E6;
}
#environment tr:nth-child(odd) {
background-color: #f6f6f6;
}
/******************************
* TEST RESULT COLORS
******************************/
span.passed,
.passed .col-result {
color: green;
}
span.skipped,
span.xfailed,
span.rerun,
.skipped .col-result,
.xfailed .col-result,
.rerun .col-result {
color: orange;
}
span.error,
span.failed,
span.xpassed,
.error .col-result,
.failed .col-result,
.xpassed .col-result {
color: red;
}
/******************************
* RESULTS TABLE
*
* 1. Table Layout
* 2. Extra
* 3. Sorting items
*
******************************/
/*------------------
* 1. Table Layout
*------------------*/
#results-table {
border: 1px solid #e6e6e6;
color: #999;
font-size: 12px;
width: 100%;
}
#results-table th,
#results-table td {
padding: 5px;
border: 1px solid #E6E6E6;
text-align: left;
}
#results-table th {
font-weight: bold;
}
/*------------------
* 2. Extra
*------------------*/
.log {
background-color: #e6e6e6;
border: 1px solid #e6e6e6;
color: black;
display: block;
font-family: "Courier New", Courier, monospace;
height: 230px;
overflow-y: scroll;
padding: 5px;
white-space: pre-wrap;
}
.log:only-child {
height: inherit;
}
div.image {
border: 1px solid #e6e6e6;
float: right;
height: 240px;
margin-left: 5px;
overflow: hidden;
width: 320px;
}
div.image img {
width: 320px;
}
div.video {
border: 1px solid #e6e6e6;
float: right;
height: 240px;
margin-left: 5px;
overflow: hidden;
width: 320px;
}
div.video video {
overflow: hidden;
width: 320px;
height: 240px;
}
.collapsed {
display: none;
}
.expander::after {
content: " (show details)";
color: #BBB;
font-style: italic;
cursor: pointer;
}
.collapser::after {
content: " (hide details)";
color: #BBB;
font-style: italic;
cursor: pointer;
}
/*------------------
* 3. Sorting items
*------------------*/
.sortable {
cursor: pointer;
}
.sort-icon {
font-size: 0px;
float: left;
margin-right: 5px;
margin-top: 5px;
/*triangle*/
width: 0;
height: 0;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
}
.inactive .sort-icon {
/*finish triangle*/
border-top: 8px solid #E6E6E6;
}
.asc.active .sort-icon {
/*finish triangle*/
border-bottom: 8px solid #999;
}
.desc.active .sort-icon {
/*finish triangle*/
border-top: 8px solid #999;
}
</style></head>
<body onLoad="init()">
<script>/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
function toArray(iter) {
if (iter === null) {
return null;
}
return Array.prototype.slice.call(iter);
}
function find(selector, elem) { // eslint-disable-line no-redeclare
if (!elem) {
elem = document;
}
return elem.querySelector(selector);
}
function findAll(selector, elem) {
if (!elem) {
elem = document;
}
return toArray(elem.querySelectorAll(selector));
}
function sortColumn(elem) {
toggleSortStates(elem);
const colIndex = toArray(elem.parentNode.childNodes).indexOf(elem);
let key;
if (elem.classList.contains('result')) {
key = keyResult;
} else if (elem.classList.contains('links')) {
key = keyLink;
} else {
key = keyAlpha;
}
sortTable(elem, key(colIndex));
}
function showAllExtras() { // eslint-disable-line no-unused-vars
findAll('.col-result').forEach(showExtras);
}
function hideAllExtras() { // eslint-disable-line no-unused-vars
findAll('.col-result').forEach(hideExtras);
}
function showExtras(colresultElem) {
const extras = colresultElem.parentNode.nextElementSibling;
const expandcollapse = colresultElem.firstElementChild;
extras.classList.remove('collapsed');
expandcollapse.classList.remove('expander');
expandcollapse.classList.add('collapser');
}
function hideExtras(colresultElem) {
const extras = colresultElem.parentNode.nextElementSibling;
const expandcollapse = colresultElem.firstElementChild;
extras.classList.add('collapsed');
expandcollapse.classList.remove('collapser');
expandcollapse.classList.add('expander');
}
function showFilters() {
const filterItems = document.getElementsByClassName('filter');
for (let i = 0; i < filterItems.length; i++)
filterItems[i].hidden = false;
}
function addCollapse() {
// Add links for show/hide all
const resulttable = find('table#results-table');
const showhideall = document.createElement('p');
showhideall.innerHTML = '<a href="javascript:showAllExtras()">Show all details</a> / ' +
'<a href="javascript:hideAllExtras()">Hide all details</a>';
resulttable.parentElement.insertBefore(showhideall, resulttable);
// Add show/hide link to each result
findAll('.col-result').forEach(function(elem) {
const collapsed = getQueryParameter('collapsed') || 'Passed';
const extras = elem.parentNode.nextElementSibling;
const expandcollapse = document.createElement('span');
if (extras.classList.contains('collapsed')) {
expandcollapse.classList.add('expander');
} else if (collapsed.includes(elem.innerHTML)) {
extras.classList.add('collapsed');
expandcollapse.classList.add('expander');
} else {
expandcollapse.classList.add('collapser');
}
elem.appendChild(expandcollapse);
elem.addEventListener('click', function(event) {
if (event.currentTarget.parentNode.nextElementSibling.classList.contains('collapsed')) {
showExtras(event.currentTarget);
} else {
hideExtras(event.currentTarget);
}
});
});
}
function getQueryParameter(name) {
const match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function init () { // eslint-disable-line no-unused-vars
resetSortHeaders();
addCollapse();
showFilters();
sortColumn(find('.initial-sort'));
findAll('.sortable').forEach(function(elem) {
elem.addEventListener('click',
function() {
sortColumn(elem);
}, false);
});
}
function sortTable(clicked, keyFunc) {
const rows = findAll('.results-table-row');
const reversed = !clicked.classList.contains('asc');
const sortedRows = sort(rows, keyFunc, reversed);
/* Whole table is removed here because browsers acts much slower
* when appending existing elements.
*/
const thead = document.getElementById('results-table-head');
document.getElementById('results-table').remove();
const parent = document.createElement('table');
parent.id = 'results-table';
parent.appendChild(thead);
sortedRows.forEach(function(elem) {
parent.appendChild(elem);
});
document.getElementsByTagName('BODY')[0].appendChild(parent);
}
function sort(items, keyFunc, reversed) {
const sortArray = items.map(function(item, i) {
return [keyFunc(item), i];
});
sortArray.sort(function(a, b) {
const keyA = a[0];
const keyB = b[0];
if (keyA == keyB) return 0;
if (reversed) {
return keyA < keyB ? 1 : -1;
} else {
return keyA > keyB ? 1 : -1;
}
});
return sortArray.map(function(item) {
const index = item[1];
return items[index];
});
}
function keyAlpha(colIndex) {
return function(elem) {
return elem.childNodes[1].childNodes[colIndex].firstChild.data.toLowerCase();
};
}
function keyLink(colIndex) {
return function(elem) {
const dataCell = elem.childNodes[1].childNodes[colIndex].firstChild;
return dataCell == null ? '' : dataCell.innerText.toLowerCase();
};
}
function keyResult(colIndex) {
return function(elem) {
const strings = ['Error', 'Failed', 'Rerun', 'XFailed', 'XPassed',
'Skipped', 'Passed'];
return strings.indexOf(elem.childNodes[1].childNodes[colIndex].firstChild.data);
};
}
function resetSortHeaders() {
findAll('.sort-icon').forEach(function(elem) {
elem.parentNode.removeChild(elem);
});
findAll('.sortable').forEach(function(elem) {
const icon = document.createElement('div');
icon.className = 'sort-icon';
icon.textContent = 'vvv';
elem.insertBefore(icon, elem.firstChild);
elem.classList.remove('desc', 'active');
elem.classList.add('asc', 'inactive');
});
}
function toggleSortStates(elem) {
//if active, toggle between asc and desc
if (elem.classList.contains('active')) {
elem.classList.toggle('asc');
elem.classList.toggle('desc');
}
//if inactive, reset all other functions and add ascending active
if (elem.classList.contains('inactive')) {
resetSortHeaders();
elem.classList.remove('inactive');
elem.classList.add('active');
}
}
function isAllRowsHidden(value) {
return value.hidden == false;
}
function filterTable(elem) { // eslint-disable-line no-unused-vars
const outcomeAtt = 'data-test-result';
const outcome = elem.getAttribute(outcomeAtt);
const classOutcome = outcome + ' results-table-row';
const outcomeRows = document.getElementsByClassName(classOutcome);
for(let i = 0; i < outcomeRows.length; i++){
outcomeRows[i].hidden = !elem.checked;
}
const rows = findAll('.results-table-row').filter(isAllRowsHidden);
const allRowsHidden = rows.length == 0 ? true : false;
const notFoundMessage = document.getElementById('not-found-message');
notFoundMessage.hidden = !allRowsHidden;
}
</script>
<h1>report.html</h1>
<p>Report generated on 20-Jun-2022 at 20:59:32 by <a href="https://pypi.python.org/pypi/pytest-html">pytest-html</a> v3.1.1</p>
<h2>Environment</h2>
<table id="environment">
<tr>
<td>Packages</td>
<td>{"pluggy": "1.0.0", "py": "1.11.0", "pytest": "7.1.2"}</td></tr>
<tr>
<td>Platform</td>
<td>macOS-12.3.1-arm64-arm-64bit</td></tr>
<tr>
<td>Python</td>
<td>3.10.4</td></tr>
<tr>
<td>项目名称</td>
<td>lins接口自动化测试</td></tr></table>
<h2>Summary</h2>
<p>所属部门: 测试组</p>
<p>测试人员: 汪杰</p>
<p>0 tests ran in 0.00 seconds. </p>
<p class="filter" hidden="true">(Un)check the boxes to filter the results.</p><input checked="true" class="filter" data-test-result="passed" disabled="true" hidden="true" name="filter_checkbox" onChange="filterTable(this)" type="checkbox"/><span class="passed">0 passed</span>, <input checked="true" class="filter" data-test-result="skipped" disabled="true" hidden="true" name="filter_checkbox" onChange="filterTable(this)" type="checkbox"/><span class="skipped">0 skipped</span>, <input checked="true" class="filter" data-test-result="failed" disabled="true" hidden="true" name="filter_checkbox" onChange="filterTable(this)" type="checkbox"/><span class="failed">0 failed</span>, <input checked="true" class="filter" data-test-result="error" disabled="true" hidden="true" name="filter_checkbox" onChange="filterTable(this)" type="checkbox"/><span class="error">0 errors</span>, <input checked="true" class="filter" data-test-result="xfailed" disabled="true" hidden="true" name="filter_checkbox" onChange="filterTable(this)" type="checkbox"/><span class="xfailed">0 expected failures</span>, <input checked="true" class="filter" data-test-result="xpassed" disabled="true" hidden="true" name="filter_checkbox" onChange="filterTable(this)" type="checkbox"/><span class="xpassed">0 unexpected passes</span>, <input checked="true" class="filter" data-test-result="rerun" disabled="true" hidden="true" name="filter_checkbox" onChange="filterTable(this)" type="checkbox"/><span class="rerun">0 rerun</span>
<h2>Results</h2>
<table id="results-table">
<thead id="results-table-head">
<tr>
<th class="sortable result initial-sort" col="result">Result</th>
<th>Description</th>
<th class="sortable" col="name">Test</th>
<th class="sortable" col="duration">Duration</th></tr>
<tr hidden="true" id="not-found-message">
<th colspan="4">No results found. Try to check the filters</th></tr></thead></table></body></html>

View File

@ -6,7 +6,7 @@
# @project : SensoroApi # @project : SensoroApi
from time import sleep from time import sleep
from page_api.alarms import Alarms from pageApi.alarms import Alarms
class TestAlarms: class TestAlarms:

View File

@ -3,12 +3,12 @@
import allure import allure
import pytest import pytest
from page_api.login import Login from pageApi.login import Login
from tools.get_yaml_data import get_yaml_data from utils.get_yaml_data import get_yaml_data
class TestLogin: class TestLogin:
data_smsCode = get_yaml_data('datas/smsCode') data_smsCode = get_yaml_data('datas/smsCode.yaml')
@allure.feature('获取手机号验证码测试') @allure.feature('获取手机号验证码测试')
@pytest.mark.run(order=1) @pytest.mark.run(order=1)
@ -19,7 +19,7 @@ class TestLogin:
r = Login().get_sendSms(mobile)['message'] r = Login().get_sendSms(mobile)['message']
assert r == message assert r == message
data_login = get_yaml_data('datas/login') data_login = get_yaml_data('datas/login.yaml')
@allure.feature('登录测试') @allure.feature('登录测试')
@pytest.mark.run(order=2) @pytest.mark.run(order=2)

View File

@ -1,14 +0,0 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import os
import yaml
def get_yaml_data(dir_file_name):
"""获取yaml文件的内容"""
path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.abspath(os.path.join(path, '../'))
with open(file_path + '/' + dir_file_name, 'r', encoding='utf-8') as f:
datas = yaml.safe_load(f)
return datas

View File

@ -7,11 +7,15 @@
import configparser import configparser
import os.path import os.path
from utils.get_dir_path import GetPath
def get_config(file_name): def get_config(file_name):
"""读取config配置文件""" """读取config配置文件"""
path = os.path.dirname(os.path.abspath(__file__)) # path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(path, '../configs', file_name) # file_path = os.path.join(path, '../configs', file_name)
file_path = os.path.join(GetPath.get_configs_path(), file_name)
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(file_path, encoding="utf-8") config.read(file_path, encoding="utf-8")
@ -19,4 +23,5 @@ def get_config(file_name):
if __name__ == '__main__': if __name__ == '__main__':
get_config('lins_environment.ini') config = get_config('lins_environment.ini')
print(config['test']['host'])

52
utils/get_dir_path.py Normal file
View File

@ -0,0 +1,52 @@
# !/usr/bin/python
# -*- coding:utf-8 -*-
# @Time : 2022/7/4 15:26
# @Author : wangjie
# @File : get_dir_path.py
# @project : SensoroApi
from configs.dir_path_config import BASE_DIR, COMMON_DIR, CONFIGS_DIR, DATAS_DIR, PAGE_API_DIR, TEST_CASE_DIR, UTILS_DIR
class GetPath:
"""
获取文件路径
"""
@staticmethod
def get_project_path():
"""获取项目工程路径"""
return BASE_DIR
@staticmethod
def get_common_path():
"""获取common目录路径"""
return COMMON_DIR
@staticmethod
def get_configs_path():
"""获取configs目录路径"""
return CONFIGS_DIR
@staticmethod
def get_datas_path():
"""获取datas目录路径"""
return DATAS_DIR
@staticmethod
def get_page_api_path():
"""获取pageApi目录路径"""
return PAGE_API_DIR
@staticmethod
def get_test_case_path():
"""获取testCase目录路径"""
return TEST_CASE_DIR
@staticmethod
def get_utils_path():
"""获取utils目录路径"""
return UTILS_DIR
if __name__ == '__main__':
print(GetPath.get_datas_path())

22
utils/get_yaml_data.py Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import os
import yaml
from utils.get_dir_path import GetPath
def get_yaml_data(dir_file_name):
"""获取yaml文件的内容"""
# path = os.path.dirname(os.path.abspath(__file__))
# file_path = os.path.abspath(os.path.join(path, '../'))
file_path = os.path.join(GetPath.get_project_path(), dir_file_name)
with open(file_path, 'r', encoding='utf-8') as f:
datas = yaml.safe_load(f)
return datas
if __name__ == '__main__':
print(get_yaml_data('datas/login.yaml'))

View File

@ -8,7 +8,7 @@ from common.http_method import BaseApi
def lock_reset(): def lock_reset():
"""门禁出厂到测试环境""" """门禁出厂需要去configs/lins_environment.ini文件下修改至对应环境的host"""
address = 'enter/v1/enter/release' address = 'enter/v1/enter/release'
data = { data = {
'version': 'OA', 'version': 'OA',

View File

@ -8,7 +8,7 @@ from common.http_method import BaseApi
def temperature_terminal_reset(): def temperature_terminal_reset():
"""测温终端出厂""" """测温终端出厂需要去configs/lins_environment.ini文件下修改至对应环境的host"""
address = 'antiepidemic/v1/antiepidemic/terminal/maker' address = 'antiepidemic/v1/antiepidemic/terminal/maker'
data = { data = {
'version': 'OA', 'version': 'OA',
@ -16,7 +16,7 @@ def temperature_terminal_reset():
# 点军环境:'productId': 'bf9e0e0d-d266-11ec-be12-ee7960eede4b' # 点军环境:'productId': 'bf9e0e0d-d266-11ec-be12-ee7960eede4b'
# 生产环境:'productId': '493107a6-c168-11ec-8fd3-9eb565365869' # 生产环境:'productId': '493107a6-c168-11ec-8fd3-9eb565365869'
# 测试环境:'productId': 'd8d151b9-bb9d-11ec-a9ee-fa2020198fdd' # 测试环境:'productId': 'd8d151b9-bb9d-11ec-a9ee-fa2020198fdd'
'productId': '493107a6-c168-11ec-8fd3-9eb565365869', # 需要去物联网中台换相应环境的ID 'productId': 'bf9e0e0d-d266-11ec-be12-ee7960eede4b', # 需要去物联网中台换相应环境的ID
} }
files = [ files = [
('file', ('测温终端出厂.xlsx', open('/Users/wangjie/Desktop/测温终端出厂.xlsx', 'rb'), ('file', ('测温终端出厂.xlsx', open('/Users/wangjie/Desktop/测温终端出厂.xlsx', 'rb'),
@ -24,7 +24,7 @@ def temperature_terminal_reset():
] ]
headers = { headers = {
# 用0号商户的token # 用0号商户的token
'Authorization': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJhY2NvdW50SWQiOiIxNTI1MDIxNDYxNDEwMTQ0MjU4Iiwibmlja25hbWUiOiLmsarmnbAiLCJleHAiOjE2NTYzMjIxMDEsImlhdCI6MTY1NTcxNzMwMSwidXNlcm5hbWUiOiIrODYxMzcxODM5NTQ3OCIsInJlZnJlc2hUb2tlbiI6ImQzNDllNWUyYTEzNjQ4MWU4NzQ5NDQ5ZTQ5N2EwYmRlIiwibWVyY2hhbnRJZCI6IjAiLCJ1c2VySWQiOiIxNTI1MDIxNDYxNjI0MDUzNzYxIn0.ziWn0BmwL5OsaHCuwKsDkuCreDlSKm7IbMHUn8LTFz8-VU5baOZiVgvR8zAKhFHxxpkXFDKBVzuz6UK8VWcbag' 'Authorization': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJhY2NvdW50SWQiOiIxMjg4ODM2NjI3OTMyMTIzMTM4Iiwibmlja25hbWUiOiLlkajmoYzlhYgiLCJleHAiOjE2NTY5MTY4OTgsImlhdCI6MTY1NjMxMjA5OCwidXNlcm5hbWUiOiIrODYxODA0NTI5NjAxNyIsInJlZnJlc2hUb2tlbiI6IjIwZWEzNjQyMDAzYTQ1NzNiOTM2YjMwNDgzY2U4NmIwIiwibWVyY2hhbnRJZCI6IjAiLCJ1c2VySWQiOiIxMzY1MjE0ODE4Nzk4Mzg3MjAyIn0.SdHQaKXIZ2ZxvX3ARwUDxjM5GUv3xmNEBjJdWaKBM-hrHKHH9qj_L8RunbWV49mjtxaEjsjwNmVCYIvSXDZ5PQ'
} }
return BaseApi().post_(address, data=data, files=files, headers=headers) return BaseApi().post_(address, data=data, files=files, headers=headers)