黄瓜框架设置

时间:2018-04-11 04:38:18

标签: java selenium cucumber

我收到以下错误消息

  

注释类型Given的属性值未定义。   导入的cucumber.annotation无法解析

查看代码

package annotation;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;

public class annotation {
    WebDriver driver = null;
    @Given("^I am on Facebook login page$")

    public void goToFacebook() {
        driver = new FirefoxDriver();
        driver.navigate().to("https://www.facebook.com/");
    }

    @When("^I enter username as \"(.*)\"$")
    public void enterUsername(String arg1) {
        driver.findElement(By.id("email")).sendKeys(arg1);
    }

    @When ("^I enter password as \"(.*)\"$")
    public void enterPassword(String arg1) {
        driver.findElement(By.id("pass")).sendKeys(arg1);
        driver.findElement(By.id("u_0_v")).click();
    }

    @Then("^Login should fail$")
    public void checkFail() {
        if(driver.getCurrentUrl().equalsIgnoreCase(
          "https://www.facebook.com/login.php?login_attempt=1&lwv=110")) {
            System.out.println("Test1 Pass");
        } else {
            System.out.println("Test1 Failed");
        }
        driver.close();
    }

    @Then("^Relogin option should be available$")
    public void checkRelogin() {
      if(driver.getCurrentUrl().equalsIgnoreCase(
        "https://www.facebook.com/login.php?login_attempt=1&lwv=110")){
          System.out.println("Test2 Pass");
      } else {
          System.out.println("Test2 Failed");
      }
      driver.close();
    }
}

1 个答案:

答案 0 :(得分:0)

使用这些导入语句

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

将类'注释'或包命名为相同并且也使用命名标准也不是一个好主意。类似的课程应该以大写字母开头。 http://www.oracle.com/technetwork/java/codeconventions-135099.html