2014-05-06 26 views
0

目前正在使用Selenium WebDriver和我正在寫的代碼Java如何使用Java和Selenium WebDriver從屬性文件調用方法?

我創建了一個MasterScript稱爲Master.java這是主要的腳本,它看起來像這樣:

package test; 
import org.openqa.selenium.WebDriver; 
public class MasterScript { 
public static void main(String[] args) throws Exception { 

//***************************************************** 
// Calling Methods 
//***************************************************** 

    LoginOneReports utilObj = new LoginOneReports(); 
    WebDriver driver; 
    driver=utilObj.setUp(); 
    if(utilObj.Login()){ 
     System.out.println("Login sucessfully completed"); 
    } else { 
     System.out.println("Login failed"); 
     System.exit(0); 
    } 

NewPR utilObj1 = new NewPR(driver); // instead of calling one PR it need to pick from the property file and it need to select the KPI in UI 

    if(utilObj1.test()){ 
    System.out.println("NewPR KPI page has opened"); 
    } else { 
     System.out.println("NewPR KPI not able to open"); 
    } 
    FilterSection utilObj2 =new FilterSection(driver); 
    utilObj2.FilterMatching(); 
    } 
} 

將這個動態值的屬性文件,其中每一次它需要去屬性文件並根據相關的java文件需要調用的值獲取該值。

enter image description here

回答

0

嗨就比如說我們會使用屬性的文件SETUP.TXT

比方說你在UR安裝文件的URL爲 「internal.url = https://google.com

創建一個構造

public MasterScript() throws IO Exception 
{ 
    setup_details(); 
    } 

公共無效setup_details()拋出IOException異常{

FileInputStream inStream; 
    inStream = new FileInputStream(new File("Setupfiles\\setup.txt")); 
    Properties prop = new Properties(); 
    prop.load(inStream); 
    internal_url=prop.getProperty("internal.url"); 
     } 

在設置文件*

internal.url = https://google.com

名的TXT文件SETUP.TXT


現在同時使用,在主類你可以使用「driver.get(internal_url);」

希望這可以幫助你...

相關問題