[英]Getting no result when run through cucumber. Trying to implement BDD
已經嘗試了幾乎所有關於SO的解決方案,但這里仍然缺少一些解決方案。
我創建了簡單的JAVA程序,添加了黃瓜的特征文件和類。 當我運行時,我得到輸出:
@Search方案概述:成功打開Google.com [90m#Open_Google.feature:4 [0m [36m給出[0m [36mUser is空白頁[0m [36mWhen [0m [36mUser輸入URL [0m [36m然后[0m [36mUser打開[0米
0場景
0步
0m0.000s
功能文件:
Feature: Open Google WebSite
@Search
Scenario Outline: Successful Open Google.com
Given User is with blank page
When User enter URL
Then Google WebSite should open
測試跑步者類別:
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "Feature"
)
public class TestRunner {
}
測試用例類別:
public class cucumber_test {
public static WebDriver driver;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.manage().window().maximize();
System.out.println("Google open successfully");
}
}
使用Selenium Webdriver,JAVA,Junit和黃瓜。
我也做對嗎? 使用黃瓜是正確的方法嗎?
跑步者似乎無法找到您的功能文件。 它位於資源中嗎? 如果是這樣,請嘗試引用整個類路徑,例如
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "classpath:com/yourgroup/yourartifact/cucumber/features"
)
public class TestRunner {
}
以上只是一個示例,當然您必須根據功能的位置更改該類路徑。
您需要參考功能部件的位置和步驟定義。 跑步者應該看起來像這樣:
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"path/to/features/"},
glue = {"classpath:package.name.of.stepsDefinitions"},
)
public class TestRunner {
}
請注意特征文件的路徑符號和粘合代碼的包裝符號 (步驟定義)
我相信您仍然面臨同樣的問題。 你可以試試看。
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)@CucumberOptions(plugin = {
"pretty", "json:target/Open-Google-WebSite.json"},
features = {"src/test/FeatureFilePackage"},
glue = {"com.java.cucumber_test"})
public class TestRunner {
}
看來您的測試正在通過testng運行,但沒有顯示任何特定的錯誤,我建議您從pom文件中刪除testNg依賴項(通過Junit)運行測試,您將能夠看到特定的錯誤,解決該錯誤之后,您將能夠輕松上課
預期的錯誤可能是“重復步驟定義”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.