2017-06-28 4 views
0

プロパティファイルとconfig.properitiesファイルをseleniumで作成しました。今私はテストケースでこれらのプロパティを呼び出す必要があります。テストケースでこのコードを呼び出すようにコードがどのように表示されるべきか、私は固執しています。 PropertiesFileSelenium TestNGによって作成された設定プロパティとプロパティファイルを読み込んだので、テストケースで呼び出す必要があります

package config; 

import java.io.FileInputStream; 
import java.io.InputStream; 
import java.util.Properties; 
public class PropertiesFile { 

public static void main(String[] args){ 
    readPropertiesFile(); 
} 

public static void readPropertiesFile(){ 
    Properties prop = new Properties(); 
    try { 


     InputStream input = new 
FileInputStream("C:\\Users\\chetan.patel\\git\\uvavoices- 
automation\\config.properties"); 
     prop.load(input); 
     System.out.println(prop.getProperty("url")); 
     System.out.println(prop.getProperty("username")); 
     System.out.println(prop.getProperty("password")); 


    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 
} 

は、これは私のテストケースである:

public class AcceptanceTest { 

public WebDriver driver; 
public String baseURL; 
private static final Logger log = 
LogManager.getLogger(AcceptanceTest.class.getName()); 
ExtentReports report; 
ExtentTest test; 
WaitTypes wt; 
LoginPageFactory login; 
VoicesPageFactory voices; 
SoftAssert sa; 

@BeforeSuite 
public void beforeSuite(){ 
report = new 
ExtentReports(System.getProperty("user.dir")+"/Reports/AcceptanceTest.html", 
true); 
test = report.startTest("Acceptance test"); 

} 

@BeforeMethod 
public void beforeMethod() { 
    PropertiesFile data = new PropertiesFile(); 
    driver = new FirefoxDriver(); 
    wt = new WaitTypes(driver); 
    login = new LoginPageFactory(driver); 
    voices = new VoicesPageFactory(driver); 
    sa = new SoftAssert(); 



    //Starting the Web Browser and navigating to the UVA Voices development 
environment 


    data.readPropertiesFile(); 
    baseURL = "url"; 
     test.log(LogStatus.INFO, "Browser Started"); 
     log.info("Browser started"); 
     driver.manage().window().maximize(); 
     driver.get(baseURL); 

} 

@Test 
public void VerifyingBubbles() throws InterruptedException { 

    //User Login and Password 

     login.username("chetan.patel"); 
      test.log(LogStatus.INFO, "Entered Username"); 

答えて

0

あなたは、以下の方法を試すことができ、

package config; 

import java.io.FileInputStream; 
import java.io.InputStream; 
import java.util.Properties; 
public class PropertiesFile { 

public static void main(String[] args){ 
    // readPropertiesFile(); 
} 

private java.util.Properties prop=null; 

public void readPropertiesFile(){ 
    prop = new Properties(); 
    try { 


     InputStream input = new 
FileInputStream("C:\\Users\\chetan.patel\\git\\uvavoices- 
automation\\config.properties"); 
     prop.load(input); 
     System.out.println(prop.getProperty("url")); 
     System.out.println(prop.getProperty("username")); 
     System.out.println(prop.getProperty("password")); 


    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    } 
public String getPropertyValue(String key){ 
    return prop.getProperty(key); 
} 

} 

、次のように前の方法では、ベースURLを取得するには、

@BeforeMethod 
public void beforeMethod() { 
    PropertiesFile data = new PropertiesFile(); 
    driver = new FirefoxDriver(); 
    wt = new WaitTypes(driver); 
    login = new LoginPageFactory(driver); 
    voices = new VoicesPageFactory(driver); 
    sa = new SoftAssert(); 



    //Starting the Web Browser and navigating to the UVA Voices development environment 


    data.readPropertiesFile(); 
    String baseURL = data.getPropertyValue("url"); 
     test.log(LogStatus.INFO, "Browser Started"); 
     log.info("Browser started"); 
     driver.manage().window().maximize(); 
     driver.get(baseURL); 

} 
+0

こんにちは@murthi ..私はゲットを保つ私がそれを実行すると、Javaのnullポイントエラーを引き起こすエラーは、この行のプロパティファイルに戻ります。 public String getPropertyValue(String key){ return prop.getProperty(key); } –

+0

メソッドreadPropertiesFileをstatic以外のものにします。私も答えを更新しました – Murthi

+0

ありがとう@Murthiそれは働いた! –

関連する問題