【发布时间】:2018-04-23 10:49:01
【问题描述】:
我是黄瓜新手,仔细学习了这个文档,以了解如何实现我的第一个黄瓜 java 项目。我做了很多分析,在网上浏览了几乎所有与它相关的文章,为什么它没有拿起步骤定义却找不到原因。不过,按照我的理解,一切似乎都还不错,我很期待你们能一口气找到我的错。
期待 +ve 回复。
因此我要共享代码、消息(在控制台窗口上)和文件夹结构。
谢谢 拉菲
功能文件:
@MyApplication
Feature: Post text Hello Rafi on Rafi facebook account
Scenario: Login successfully on Facebook application
Given Open Facebook application
When Enter valid id and password
And Click on Login button
Then Facebook home page should open
TestRunner 类:
package test.java.runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//glue = {"helpers", "src.test.java.steps"},
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/features"},
glue = {"helpers", "src.test.java.steps"},
plugin = {"pretty","html:target/cucumber-html-report"},
dryRun = true,
monochrome = true,
tags="@MyApplication",
strict=false)
public class TestRunner {
}
StepDefinition 类:
package test.java.steps;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepDefinition {
private static WebDriver driver = null ;
private static String password = "*********";
WebDriverWait wait=new WebDriverWait(driver, 30);
WebElement waitElement;
@BeforeClass
public void setup() throws Throwable
{
System.setProperty("webdriver.gecko.driver", "C:\\Selenium Automation\\selenium\\Selenium 3 and Firefox Geckodriver\\geckodriver.exe");
driver = new FirefoxDriver ();
driver.manage().window().maximize();
}
@AfterClass
public void teardown() throws Throwable
{driver.quit();}
// First scenario
@Given("^Open Facebook application$")
public void open_Facebook_application() throws Throwable{
System.out.println("this is not working");
driver.navigate().to("https://www.facebook.com/");
}
@When("^Enter valid id and password$")
public void enter_valid_id_and_password() throws Throwable{
driver.findElement(By.name("email")).clear();
driver.findElement(By.name("email")).sendKeys("rafiras16@gmail.com");
driver.findElement(By.name("pass")).clear();
driver.findElement(By.name("pass")).sendKeys(password);
}
@When("^Click on Login button$")
public void click_on_Login_button() throws Throwable {
driver.findElement(By.xpath("//input[starts-with(@id,'u_0')]")).click();
}
@Then("^Facebook home page should open$")
public void facebook_home_page_should_open() throws Throwable{
String strTitle = driver.getTitle();
System.out.print(strTitle);
}
}
image for message on console window and folder structure BuildPath details
【问题讨论】:
-
您有任何日志来支持您的问题吗?
-
Hi Himanshu,感谢您的回复,请参考附件图片(第一张用于控制台消息,第二张用于构建路径)...链接在底部。