我有一個機器人框架測試套件,它使用「username」參數調用Powershell腳本。這是正確的,直到用戶名在這種情況下包含非ASCII(非英文)字符。機器人正在正確輸出字符(我通過記錄數值檢查並寫入了一個文本文件,它們總是正確的)。從Robot Framework傳遞到Powershell的非ASCII字符以問號形式顯示
但是當它到達Powershell腳本時,用戶名只會顯示一行問號。
我知道這是與文本編碼有關,但無法弄清楚/有什麼辦法來處理它。
我有一個解決方法選項是將Robot的用戶名寫入臨時文本文件,然後讓Powershell腳本從文本文件中讀取該值。這可以成功運行,但在多臺機器上運行這些腳本時效率非常低。
測試套件我有如下(只突出線拉出):
*** Variables ***
${user_name} ÀÀÀ
*** Test Cases ***
Write foreign username
Write Username ${user_name}
*** Keywords ***
Write Username
[Arguments] ${user_name}
Run powershell.exe -file ".\\..\\Powershell\Write-Username.ps1" -UserName "${user_name}"
PowerShell腳本則包含以下代碼:
param
(
[parameter(Mandatory=$True)]
[string]$UserName
)
$username | Out-File C:\Temp\Test.txt -Encoding UTF8
,而無需腳本很難猜測。首先記住'$ OutputEncoding = [Console] :: OutputEncoding' – Deptor