我有一個global.properties檔案,必須在這個屬性檔案中定義檔案路徑。
SheetPath=C:Users estAutomation-ScriptDataTable.xlsx
這是一個絕對路徑,但需要一種方法來定義一個相對路徑,以便在呼叫時可以消耗。
uj5u.com熱心網友回復:
屬性檔案:
testPath=API_Files/duplicateToken.json
加載屬性檔案:
public static void loadPropertiesFile() {
File propertiesFile = new File(屬性檔案的位置)。
try {
FileInputStream fileInput = new FileInputStream( propertiesFile)。
propertiesFile.load(fileInput)。
} catch (Exception e) {
Logger.LogError("加載屬性檔案時出錯" e.getMessage())。
}
}
讀取屬性檔案并獲得絕對路徑:
public static Properties readProperties = new Properties() 。
String testPath = readProperties.getProperty("testPath").trim()。
File absolutePath = new File(System. getProperty("user.dir") testPath)。)
System.out.println(absolutePath)。
示例輸出:
C:Users estAutomation-ScriptduplicateToken.json
uj5u.com熱心網友回復:
屬性檔案應該是相對于classpath的。你可以在src級別創建一個 "configs "檔案夾,并使用下面的代碼來讀取該檔案。參考這個以獲得更多解釋和技巧。
private Properties屬性。
private final String propertyFilePath= "configs//Configuration.properties"/span>。
BufferedReader reader = new BufferedReader(new FileReader(propertyFilePath))。
Properties properties = new Properties()。
properties.load(reader)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/318365.html
標籤:
上一篇:將TestObject轉換為List<WebElement>,并將其作為引數傳遞。
下一篇:過濾從Selenium回傳的資訊
