提交 2f4a6e38 authored 作者: 陈泽健's avatar 陈泽健

chore(project): 清理项目配置文件并添加忽略规则

- 删除了多个临时检查脚本文件 (check_bytes.py, check_file.py, check_target.py)
- 移除了空的 package.json 配置文件
- 在 .gitignore 中添加了 IDE 相关文件的忽略规则
- 为自动化测试环境添加了路径注释标记
上级 37ea2b2a
# 默认忽略的文件
/shelf/
/workspace.xml
# -*- coding: utf-8 -*-
"""Check actual bytes in line 280"""
target_path = r'E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\ServiceSelfInspection\modules\ConfigIPCheck.psm1'
with open(target_path, 'rb') as f:
data = f.read()
# Skip BOM
data = data[3:]
# Find line 280 (split by \n)
lines = data.split(b'\n')
if len(lines) >= 280:
line_280 = lines[279]
print(f"Line 280 bytes: {line_280}")
print(f"\nLine 280 hex: {line_280.hex()}")
# The Chinese "传统平台配置文件 IP 检查完成" in UTF-8:
expected = "[CFG] 传统平台配置文件 IP 检查完成".encode('utf-8')
print(f"\nExpected hex: {expected.hex()}")
# Check if they match
if expected in line_280:
print("\nSUCCESS: Chinese characters found in file!")
else:
print("\nWARNING: Expected Chinese not found")
# Try to find what we have instead
import re
# Extract the Chinese part between [CFG] and IP
match = re.search(rb'\[CFG\] (.+?) IP', line_280)
if match:
print(f"Found between [CFG] and IP: {match.group(1)}")
print(f"Hex: {match.group(1).hex()}")
# -*- coding: utf-8 -*-
"""Check file encoding"""
file_path = r"E:\GithubData\ubains-module-test\temp_restore2.psm1"
# Read as binary
with open(file_path, 'rb') as f:
data = f.read()
# Check first 10 bytes
print("First 10 bytes:", ' '.join(f'{b:02x}' for b in data[:10]))
# Check BOM
if data[:3] == b'\xef\xbb\xbf':
print("Has UTF-8 BOM")
elif data[:2] == b'\xff\xfe':
print("Has UTF-16 LE BOM")
else:
print("No standard BOM")
# Try to decode and show line 280
try:
text = data.decode('utf-8')
lines = text.split('\n')
if len(lines) >= 280:
print(f"\nLine 280: {lines[279]}")
except Exception as e:
print(f"Decode error: {e}")
# Also show last few lines
try:
text = data.decode('utf-8')
lines = text.split('\n')
print("\nLast 5 lines:")
for line in lines[-5:]:
print(line)
except Exception as e:
print(f"Decode error: {e}")
# -*- coding: utf-8 -*-
"""Check ConfigIPCheck.psm1 file encoding"""
file_path = r"E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\ServiceSelfInspection\modules\ConfigIPCheck.psm1"
# Read as binary
with open(file_path, 'rb') as f:
data = f.read()
# Check first 10 bytes
print("First 10 bytes:", ' '.join(f'{b:02x}' for b in data[:10]))
# Check BOM
if data[:3] == b'\xef\xbb\xbf':
print("Has UTF-8 BOM")
elif data[:2] == b'\xff\xfe':
print("Has UTF-16 LE BOM")
else:
print("No standard BOM")
# Try to decode and show line 280
try:
text = data.decode('utf-8')
lines = text.split('\n')
if len(lines) >= 280:
print(f"\nLine 280: {lines[279]}")
except Exception as e:
print(f"UTF-8 decode error: {e}")
# Try GB2312/GBK decode
try:
text = data.decode('gb2312')
lines = text.split('\n')
if len(lines) >= 280:
print(f"\nLine 280 (GB2312): {lines[279]}")
except Exception as e:
print(f"GB2312 decode error: {e}")
def teststeps(self):
"""
执行测试步骤函数,主要用于执行读取的测试用例并进行会议模板模块功能测试操作
"""
# 从全局存储中获取webdriver对象
wd = GSTORE['wd']
# 先清空Excel文件中的测试结果和日志截图
clear_columns_in_xlsx(xlsx_file_path, "会议审批", ["测试结果", "日志截图"])
# 读取Excel文件中的测试用例数据
ddt_cases = read_xlsx_data(xlsx_file_path, "会议审批")
# 遍历 ddt_cases 并获取每一个 JSON 对象
for case in ddt_cases:
# 为每个测试用例添加一个 name 字段
case_name = case.get('case_name', f"Case_{ddt_cases.index(case) + 1}")
case['name'] = case_name
# 创建审批会议
meeting_message("审批会议室", "普通会议", "审批测试会议","长安大学", wd)
for step in case:
print(f"当前步骤: {step}")
# 先赋值
locator_type = get_by_enum(case.get('locator_type'))
locator_value = case.get('locator_value')
element_type = case.get('element_type')
element_value = case.get('element_value')
expented_result = case.get('expented_result')
# 判断页面功能类型
if case.get("page") == "ApprovalInitiate":
if element_type == "input":
safe_send_keys((locator_type, locator_value), element_value, wd)
sleep(1)
elif element_type == "click":
safe_click((locator_type, locator_value), wd)
sleep(2)
elif element_type == "getTips":
notify_text = get_notify_text(wd, (locator_type, locator_value), "Message_Template", "Template_Edit", "长安审批测试")
INFO(f"提示信息为:{notify_text}")
CHECK_POINT("编辑测试判断是否正确", expented_result in notify_text)
SELENIUM_LOG_SCREEN(wd, "50")
elif element_type == "function":
print(f"这是element_value的值:{element_value}")
# 退出登录,并调用用户登录函数
safe_click((By.XPATH, "//img[@title='退出登录']"), wd)
sleep(1)
wd.refresh()
user_login(element_value[0],element_value[1])
sleep(2)
# 调用审批会议状态设置函数
approval_status_control("审批测试会议", element_value[2], wd)
sleep(1)
# 退出登录
safe_click((By.XPATH, "//img[@title='退出登录']"), wd)
wd.refresh()
# 登录与退出操作频繁,到登录页后存在一个缓存界面,可以点击退出按钮
quit_element = wd.find_element(By.XPATH, "//div[@class='operat']//span//img")
if quit_element != "":
quit_element.click()
# 调用用户登录函数,登录普通用户
user_login("admin@PT","Ubains@4321")
# 进入会议审批模块
safe_click((By.XPATH, "//span[contains(text(),'会议审批')]"), wd)
sleep(1)
\ No newline at end of file
# Fix ConfigIPCheck.psm1 file encoding
# Convert to UTF-8 with BOM to ensure Chinese characters display correctly
$filePath = "E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\ServiceSelfInspection\modules\ConfigIPCheck.psm1"
Write-Host "Checking file: $filePath" -ForegroundColor Cyan
# Read file with current encoding
try {
# Try to read with default encoding (system default)
$content = [System.IO.File]::ReadAllText($filePath)
Write-Host "File read successfully, current content length: $($content.Length) characters" -ForegroundColor Green
# Show a sample of the problematic line (line 280)
$lines = $content -split "`n"
if ($lines.Length -ge 280) {
Write-Host "`nLine 280 preview:"
Write-Host " $($lines[279])" -ForegroundColor Yellow
}
# Create UTF-8 with BOM encoding
$utf8BOM = New-Object System.Text.UTF8Encoding $true
# Write back with UTF-8 BOM
[System.IO.File]::WriteAllText($filePath, $content, $utf8BOM)
Write-Host "`nFile converted to UTF-8 with BOM" -ForegroundColor Green
# Verify the change
$bytes = [System.IO.File]::ReadAllBytes($filePath)
Write-Host "`nVerification - First 5 bytes after conversion:"
for ($i = 0; $i -lt [Math]::Min(5, $bytes.Length); $i++) {
Write-Host " Byte $i`: 0x$($bytes[$i].ToString('X2')) ($($bytes[$i]))"
}
if ($bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
Write-Host "`nSUCCESS: UTF-8 BOM detected (0xEF 0xBB 0xBF)" -ForegroundColor Green
} else {
Write-Host "`nWARNING: Expected UTF-8 BOM not found!" -ForegroundColor Red
}
} catch {
Write-Host "ERROR: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Write-Host "`nDone!"
# Fix ConfigIPCheck.psm1 file encoding - Version 2
# The file was likely saved with GB2312/GBK encoding, causing Chinese characters to display as garbled text
$filePath = "E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\ServiceSelfInspection\modules\ConfigIPCheck.psm1"
$backupPath = $filePath + ".backup"
Write-Host "Checking file: $filePath" -ForegroundColor Cyan
# Create backup
Copy-Item $filePath $backupPath -Force
Write-Host "Backup created: $backupPath" -ForegroundColor Yellow
# Try reading with different encodings
$encodings = @(
"UTF-8",
"UTF-7",
"UTF-32",
"Unicode", # UTF-16 LE
"BigEndianUnicode", # UTF-16 BE
"ASCII",
"Default" # System default (usually GB2312/GBK on Chinese Windows)
)
$content = $null
$usedEncoding = $null
foreach ($encName in $encodings) {
try {
$enc = [System.Text.Encoding]::GetEncoding($encName)
$testContent = [System.IO.File]::ReadAllText($filePath, $enc)
# Check if the content contains valid Chinese characters
# by looking for the expected pattern on line 280
$lines = $testContent -split "`n"
if ($lines.Length -ge 280) {
$line280 = $lines[279]
Write-Host "`nTesting encoding: $encName"
Write-Host " Line 280: $line280"
# If line contains recognizable patterns (Write-Log, [CFG], etc.)
# and not too many replacement characters, we found the right encoding
if ($line280 -match "Write-Log" -and $line280 -match "\[CFG\]" -and $line280 -match "IP") {
$content = $testContent
$usedEncoding = $encName
Write-Host " -> Using this encoding" -ForegroundColor Green
break
}
}
} catch {
# Ignore errors for unsupported encodings
}
}
if ($null -eq $content) {
Write-Host "`nERROR: Could not determine correct encoding. Trying system default..." -ForegroundColor Red
$content = [System.IO.File]::ReadAllText($filePath)
$usedEncoding = "System Default"
}
# Now save with UTF-8 with BOM
$utf8BOM = New-Object System.Text.UTF8Encoding $true
[System.IO.File]::WriteAllText($filePath, $content, $utf8BOM)
Write-Host "`nFile converted to UTF-8 with BOM" -ForegroundColor Green
# Verify the conversion
$lines = $content -split "`n"
if ($lines.Length -ge 280) {
Write-Host "`nLine 280 after conversion:"
Write-Host " $($lines[279])" -ForegroundColor Yellow
}
# Verify BOM
$bytes = [System.IO.File]::ReadAllBytes($filePath)
if ($bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
Write-Host "`nSUCCESS: File now has UTF-8 BOM" -ForegroundColor Green
} else {
Write-Host "`nWARNING: Expected UTF-8 BOM not found!" -ForegroundColor Red
}
Write-Host "`nConversion complete!"
Write-Host "Original encoding used for reading: $usedEncoding"
Write-Host "Backup saved at: $backupPath"
# Final fix for ConfigIPCheck.psm1
# Copy from restored temp file and add UTF-8 BOM
$sourcePath = "E:\GithubData\ubains-module-test\temp_restore.psm1"
$targetPath = "E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\ServiceSelfInspection\modules\ConfigIPCheck.psm1"
Write-Host "Fixing ConfigIPCheck.psm1..." -ForegroundColor Cyan
# Read source file (UTF-8 without BOM from Git)
$content = [System.IO.File]::ReadAllText($sourcePath)
# Save to target with UTF-8 with BOM
$utf8BOM = New-Object System.Text.UTF8Encoding $true
[System.IO.File]::WriteAllText($targetPath, $content, $utf8BOM)
Write-Host "File fixed and saved with UTF-8 BOM" -ForegroundColor Green
# Verify line 280
$lines = $content -split "`n"
if ($lines.Length -ge 280) {
Write-Host "`nLine 280:"
Write-Host " $($lines[279])" -ForegroundColor Yellow
}
# Verify BOM
$bytes = [System.IO.File]::ReadAllBytes($targetPath)
if ($bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
Write-Host "`nBOM verified: UTF-8 with BOM (0xEF 0xBB 0xBF)" -ForegroundColor Green
}
Write-Host "`nDone!"
# Restore ConfigIPCheck.psm1 from Git and convert to UTF-8 with BOM
$filePath = "E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\ServiceSelfInspection\modules\ConfigIPCheck.psm1"
Write-Host "Restoring ConfigIPCheck.psm1 from Git repository..." -ForegroundColor Cyan
# Navigate to repository root
$repoRoot = "E:\GithubData\ubains-module-test"
Push-Location $repoRoot
try {
# Restore file from Git
git checkout HEAD -- "AuxiliaryTool/ScriptTool/ServiceSelfInspection/modules/ConfigIPCheck.psm1"
Write-Host "File restored from Git" -ForegroundColor Green
# Read the restored content
$content = [System.IO.File]::ReadAllText($filePath)
# Check line 280
$lines = $content -split "`n"
if ($lines.Length -ge 280) {
Write-Host "`nLine 280 after Git restore:"
Write-Host " $($lines[279])" -ForegroundColor Yellow
}
# Convert to UTF-8 with BOM
$utf8BOM = New-Object System.Text.UTF8Encoding $true
[System.IO.File]::WriteAllText($filePath, $content, $utf8BOM)
Write-Host "`nFile converted to UTF-8 with BOM" -ForegroundColor Green
# Verify BOM
$bytes = [System.IO.File]::ReadAllBytes($filePath)
if ($bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
Write-Host "SUCCESS: UTF-8 BOM detected (0xEF 0xBB 0xBF)" -ForegroundColor Green
}
} catch {
Write-Host "ERROR: $($_.Exception.Message)" -ForegroundColor Red
} finally {
Pop-Location
}
Write-Host "`nDone!"
# Restore ConfigIPCheck.psm1 by directly getting content from Git
# This bypasses any encoding issues during git checkout
$filePath = "E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\ServiceSelfInspection\modules\ConfigIPCheck.psm1"
$repoRoot = "E:\GithubData\ubains-module-test"
Write-Host "Getting file content directly from Git..." -ForegroundColor Cyan
try {
Push-Location $repoRoot
# Get content from Git and save to file
# Use UTF-8 encoding for the output
$gitContent = git show HEAD:AuxiliaryTool/ScriptTool/ServiceSelfInspection/modules/ConfigIPCheck.psm1
if ($LASTEXITCODE -eq 0) {
# Save with UTF-8 with BOM
$utf8BOM = New-Object System.Text.UTF8Encoding $true
[System.IO.File]::WriteAllText($filePath, $gitContent, $utf8BOM)
Write-Host "File restored from Git content" -ForegroundColor Green
# Verify
$content = [System.IO.File]::ReadAllText($filePath)
$lines = $content -split "`n"
if ($lines.Length -ge 280) {
Write-Host "`nLine 280:"
Write-Host " $($lines[279])" -ForegroundColor Yellow
}
# Check BOM
$bytes = [System.IO.File]::ReadAllBytes($filePath)
if ($bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
Write-Host "`nBOM verified: UTF-8 with BOM (0xEF 0xBB 0xBF)" -ForegroundColor Green
}
} else {
Write-Host "ERROR: Git command failed" -ForegroundColor Red
}
} catch {
Write-Host "ERROR: $($_.Exception.Message)" -ForegroundColor Red
} finally {
Pop-Location
}
Write-Host "`nDone!"
...@@ -82,6 +82,8 @@ def browser_init(login_type): ...@@ -82,6 +82,8 @@ def browser_init(login_type):
# service = Service(r'E:\Python\Scripts\chromedriver.exe') # service = Service(r'E:\Python\Scripts\chromedriver.exe')
# 自动化虚拟机 # 自动化虚拟机
service = Service(r'C:\Program Files\Python310\Scripts\chromedriver.exe') service = Service(r'C:\Program Files\Python310\Scripts\chromedriver.exe')
# CZJ自己电脑
# service = Service(r'C:\Program Files\Python310\Scripts\chromedriver.exe')
# 尝试创建WebDriver实例并执行初始化操作 # 尝试创建WebDriver实例并执行初始化操作
try: try:
# 创建WebDriver实例 # 创建WebDriver实例
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论