2015-08-13 31 views

回答

0

您可以使用屬性類從Java庫

Properties prop = new Properties(); 
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(propFileName); 
prop.load(inputStream); 

的,你可以得到的值作爲

prop.getProperty("propertyname"); 
+1

無需Classloader。 'getClass()。getResourceAsStream(「filename.properties」)'應該足夠了。 – Carsten

0

試試下面的代碼:

Properties prop = new Properties(); 
InputStream input = null; 

try { 
    input = new FileInputStream("your_config.properties"); 
    prop.load(input); 
    System.out.println(prop.getProperty("xOffset")); 
    System.out.println(prop.getProperty("yOffset")); 
} catch (IOException e) { 
    // ... 
} 
0

如上所述創建在Selenium驅動構造函數中或之前讀取屬性文件的函數。所以你可以在測試中使用它們(Desire Capability Impl中的幫助)。

存放在公共靜態最終值(如果你不不希望改變他們的硒和默認屬性輸入使用)

當值硒驅動程序,以便之前的Java Propertie文件或config文件中讀取您可以在Driver構造函數中使用它們,或者如果您不希望在項目中的任何位置使用這些屬性作爲Static存儲。這些值充當GLOBAL參數。

相關問題