2016-04-26 15 views
0

想要從concordion打開瀏覽器。
嘗試從System.java類打開瀏覽器。但觀察到WebDriver driver = new FirefoxDriver();未執行。如何從concordion框架初始化瀏覽器

這裏是我的項目結構; -

enter image description here

System.java類: -

package com.tutorialspoint; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class System { 
    public String initization(String browserName){ 
     String url = null; 
     if (browserName=="firefox") 
     { 
      WebDriver driver = new FirefoxDriver(); 
      driver.get("http://www.google.com"); 
      url = driver.getCurrentUrl(); 

     } 
    return url; 

    } 
} 

這是我BrowserFixture.java類: -

package specs.tutorialspoint; 
@RunWith(ConcordionRunner.class) 
public class BrowserFixture { 
    System system = new System(); 
    public String initization(String browserName){ 

     return system.initization(browserName); 

    } 
} 

這裏是我的.html輸入: -

<html xmlns:concordion="http://www.concordion.org/2007/concordion"> 
<head> 
    <link href="../concordion.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <h1>Browser Initilization</h1> 
     <div class="example"> 
     <h3>Example</h3> 
     <table> 
     <tr> 
     <th>browserName</th> 
     <th>initization</th> 
     </tr> 
     <tr concordion:execute="#result = initization(#browserName)"> 
     <td concordion:set="#browserName">firefox</td> 

     </tr> 

    </table> 
    </div> 
</body> 
</html> 
+0

您可能希望從https://github.com/concordion/concordion-scope-examples/tree/per_spec_parallel使用Concordion 2.x下載工作示例。這包含一套基於瀏覽器的測試,每個規格打開一個瀏覽器,並行運行規格。存儲庫的其他分支包含用於打開/關閉瀏覽器的不同範圍。有關詳細信息,請參閱https://github.com/concordion/concordion-scope-examples/blob/master/README.md。 –

+0

通常,瀏覽器初始化將被「隱藏」在夾具類中,以便規範引用用戶試圖實現的內容,而不是他們如何做到這一點。有關更多詳細信息,請參閱http://concordion.org/technique/java/markdown/。 –

+0

此外,Concordion 2.x允許您使用Markdown編寫您的規範,比HTML更易於閱讀和編寫。這些在上面引用的工作示例中進行了演示,並在http://concordion.org/上進行了記錄。 –

回答

0

您需要使用string.equals(Object other)函數來比較字符串,而不是==運算符。

瀏覽器打開OK,如果你更換:

if (browserName=="firefox") 

有:

if (browserName.equals("firefox")) 

詳情請參閱How do I compare Strings in Java

另請參閱我對此問題的評論,以獲得關於此示例的一些常規觀察。