2017-08-11 33 views
1

事情的心臟是我的IDE(的IntelliJ)內,我可以用鼠標右鍵點擊一個個人.feature文件,並運行良好,但不讀取Runner類中的任何參數。從命令行,它工作正常。 mvn clean compile test -Dcucumber.options="--tags @calculator"運行IDE內.feature文件不能讀取黃瓜亞軍類

我正在使用單個框架來處理多個Web應用程序。所以每個應用程序都在一個單獨的子文件夾中。

+---test 
    +---java 
     +---com 
      +---company 
       +---app 
       ¦ +---app1 
       ¦ ¦ +---common 
       ¦ ¦ +---page 
       ¦ ¦ +---step 
       ¦ +---app2 
       ¦  +---common 
       ¦  +---page 
       ¦  +---step 
       +---core 

該框架將使用PageObject模式,使page將包含每個頁面的詳細信息,common將是在整個應用程序共同的特徵,並step是給定的,當,然後步驟。

在資源文件夾中我有一個類似的佈局

+---resources 
    +---com 
     +---company 
      +---app 
       +---app1 
       ¦ +---feature files go here 
       +---app2 
        +---feature files go here 

的亞軍類是主要app文件夾。

package com.company.app; 

import com.company.core.Browser; 
import com.company.core._Start; 
import cucumber.api.CucumberOptions; 
import cucumber.api.SnippetType; 
import cucumber.api.junit.Cucumber; 
import org.junit.AfterClass; 
import org.junit.BeforeClass; 
import org.junit.runner.RunWith; 

import java.io.File; 
import java.net.InetAddress; 
import java.net.UnknownHostException; 

@RunWith(Cucumber.class) 
@CucumberOptions(
     plugin = {"pretty", 
       "html:target/cucumber", 
       "json:report/report.json", 
       "com.cucumber.listener.ExtentCucumberFormatter:" 
     }, 
     tags = {"[email protected]"}, 
     snippets = SnippetType.CAMELCASE 
) 
public class _RunnerTest extends _Start { 
    private static String reportFile = "report.html"; 
    private static String configFile = "extent-config.xml"; 

    @BeforeClass 
    public static void setup() { 
    // Stuff 
    } 

    @AfterClass 
    public static void teardown() { 
     // Stuff 
    } 
} 

因此,通過Maven命令行運行,一切都按預期工作。如果我在.feature文件(或與它的場景)的測試(S)將運行右鍵單擊,但所以沒有報告,以及@BeforeClass和@AfterClass被忽略不使用亞軍類。

有什麼我失蹤了嗎?

+0

在我結束試了一下。遇到同樣的問題。但是想知道,@ BeforeClass和'@ AfterClass'是否在runner類或stepdefination類中? 另外請注意,因爲我們是直接運行特徵文件,沒有與亞軍類沒有互動,所以代碼將不會執行。 –

+0

@AshishDeshmukh,如圖所示,'''@ BeforeClass'''和'''@ AfterClass'''是澆道的一部分。他們目前所包含的內容是報告電話。理想情況下,我想將瀏覽器啓動並關閉。但是因爲如果在IDE中運行跑步者沒有被調用,那就沒有意義了。 – MivaScott

+0

我認爲要實現你所說的(將瀏覽器啓動並關閉),我們可以爲此創建單獨的功能,並使用嵌套步驟來實現使用跑步者類的相同效果。 –

回答

2

當您直接運行特徵文件,它不能運行使用的亞軍。如果你想讓你的測試使用runner中定義的@BeforeClass和@AfterClass,你必須運行runner。

另請注意,雖然Cucumber支持JUnits @ClassRule@BeforeClass@AfterClass註釋,但不建議使用這些註釋,因爲它限制了不同跑步者之間的可移植性; 使用命令行或IDE時它們可能無法正確執行 相反,建議使用黃瓜BeforeAfter鉤子。