2016-08-19 89 views
0

我有2個場景的Cucumber功能文件,例如:請找到下面的示例文件。來自黃瓜.feature文件的場景未按正確順序運行

@RunFeature 
Feature: Sanity Testing of scenarios 

@LoginFeature 
Scenario: Test xyz feature 
    Given The user is on login page 
    When User enters credentials 
    And clicks on login button 
    Then homepage should be displayed 

@InfoFeature 
Scenario: Test abc feature 
    Given The user is on home page 
    When User enters employee name in textbox 
    And clicks on get details button 
    Then Employee details are displayed 

我嘗試運行用TestNG此功能的文件,

package TestNGClass; 
import java.io.IOException; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.testng.annotations.BeforeClass; 
import org.testng.annotations.Test; 
import cucumber.api.CucumberOptions; 
import cucumber.api.testng.AbstractTestNGCucumberTests; 
import cucumber.api.testng.TestNGCucumberRunner; 

@Test(groups="cucumber") 

@CucumberOptions(
     features ="src/main/resources", 
     glue="stepDefinitions", 
     tags="@RunFeature") 

public class TestNGRunner extends AbstractTestNGCucumberTests{ 


    @Test(groups="cucumber",description="Runs Cucumber Features") 
    public void run_Cukes()throws IOException{ 
     //new TestNGCucumberRunner(getClass()).runCukes(); 
    } 
} 

但我觀察到,有時同時運行在平行的情況下,有時在連續模式。我試圖在順序模式下運行場景。任何人都可以告訴我在testng runner類中需要添加什麼?

+0

依賴於運行的其他功能之前,通常是不好的做法有特點。嘗試捕獲您的Given中所需的所有狀態,以便它們可以按任何順序運行。 – jedifans

+0

好的。但是有沒有控制這個流程的任何參數?因爲我不明白爲什麼有時它會按順序運行,有時會平行運行。 – Saisha

+0

您爲什麼要擴展AbstractTestNG .....類以及實現runCukes方法的任何原因。只要擴大課程範圍,就可以省去剩下的課程。看看這個 - http://sahajamit.github.io/Cucumber-JVM-with-TestNG/。或着名的計算示例 - https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator – Grasshopper

回答

1
  1. 無需標記您的cukes亞軍爲@Test,延長AbstractTestNGCucumberTests足夠
  2. 沒有必要在這個類中,使用步驟類和特性文件來定義測試
  3. 如果您需要一定的前提條件發生考慮在您的步驟類別中使用@Before註釋在您的功能文件中使用關鍵字Background。對於該特徵文件中的每個單個場景,將執行Background部分中描述的句子。就像這樣:

    Background: Test xyz feature 
    Given The user is on login page 
    When User enters credentials 
    And clicks on login button 
    Then homepage should be displayed 
    
    Scenario: Test abc feature 
    Given The user is on home page 
    When User enters employee name in textbox 
    And clicks on get details button 
    Then Employee details are displayed