我试图通过使用Eclipse和黄瓜的selenium webdriver来实现工作中的自动化。在运行我的特性文件时,我得到了以下错误
java.lang.Error:未解决的编译问题:驱动程序无法解决
如下所示,在我的Tests_Steps.java类中,我正确地声明了变量“驱动程序”。我还将对象分配给类的实例(FirefoxDriver)。下面是我的密码。
package stepDefinition;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class Tests_Steps {
@Given("^User is on the Home Page$")
public void user_is_on_the_Home_Page() throws Throwable {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.get("http://www.gmail.com/login");
}
@When("^User Clicks on the Login$")
public void user_Clicks_on_the_Login() throws Throwable {
driver.findElement(By.xpath(".//*[@id='login']")).click();
}
@When("^User enters UserName and Password$")
public void user_enters_UserName_and_Password() throws Throwable {
driver.findElement(By.id("login")).sendKeys("ab24146_111");
driver.findElement(By.id("psw")).sendKeys("Password1");
driver.findElement(By.id("loginButton")).click();
}
@Then("^Message displayed LogIn Successfully$")
public void message_displayed_LogIn_Successfully() throws Throwable {
System.out.println("Login Successfully");
}
出于某种原因,在第二步和第三步,我的司机变量没有被识别。我看到红线,当我把鼠标悬停在红线上时,它说“司机无法解决”,在第一步,它的工作很好。
你们能帮我做些什么吗。
发布于 2016-10-17 17:22:50
java.lang.Error:未解决的编译问题:驱动程序无法解决
实际上,您是在本地的WebDriver
中声明user_is_on_the_Home_Page()
变量,因此这是有限的,并且只能用于此方法。
您应该全局声明此变量,该变量可用于所有这些方法,如下所示:
public class Tests_Steps {
WebDriver driver = null;
@Given("^User is on the Home Page$")
public void user_is_on_the_Home_Page() throws Throwable {
driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.get("http://www.gmail.com/login");
}
------------
------------
}
发布于 2016-10-17 17:07:58
您已经在user_is_on_the_Home_Page()方法中声明了变量,因此它的作用域仅限于该方法,并且在方法完成时被销毁。
移动为类的实例变量,并在构造函数中初始化它。
https://stackoverflow.com/questions/40097883
复制相似问题