Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium仅打开和直接关闭浏览器_Java_Selenium_Browser_Cucumber - Fatal编程技术网

Java Selenium仅打开和直接关闭浏览器

Java Selenium仅打开和直接关闭浏览器,java,selenium,browser,cucumber,Java,Selenium,Browser,Cucumber,我正在用Selenium integrated编写一个基本的Cucumber测试,我想打开一个站点登录并检查我是否已登录。问题是在测试的第一步,firefox即时打开和关闭,测试无限期运行。 这是我的跑步课 Feature: To If i can login Scenario: Check if login is complete Given I am on the website When I click on login And Populate the

我正在用Selenium integrated编写一个基本的Cucumber测试,我想打开一个站点登录并检查我是否已登录。问题是在测试的第一步,firefox即时打开和关闭,测试无限期运行。

这是我的跑步课

Feature: To If i can login

  Scenario: Check if login is complete
    Given I am on the  website
    When I click on login
    And Populate the contact form
    Then I should be on the account page
这是我的特色

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import static junit.framework.TestCase.assertTrue;


public class StepDefinitions {

    private WebDriver driver;

    @Given("^I am on the  website$")
    public void ShouldnavigateToWebsite(){
        System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
        System.out.println("voor");
        driver = new FirefoxDriver();
        System.out.println("na");
        driver.get("http://www.store.demoqa.com");
    }


    @When("^I click on login$")
    public void ClickOnLink(){
        driver.findElement(By.id("account")).click();
    }

    @And("^Populate the contact form$")
    public void PopulateForms(){
        driver.findElement(By.id("log")).sendKeys("TimoTest");
        driver.findElement(By.id("pwd")).sendKeys("TimoTest1");
        driver.findElement(By.id("login")).click();
    }

    @Then("^I should be on the account page$")
    public void ShouldBeOnContactPage(){
        assertTrue("Not one account page",driver.getTitle().equals("your-account"));
    }
}
这就是测试本身。
他打印的唯一东西是voor(以前)

我认为您的问题在于版本。在没有Selenium的情况下打开Firefox,查看它是否没有挂起的更新。如果有,则更新到最新版本。并确保使用最新的
seleniumjava
,即3.0.1。希望它能解决您的问题。

您的代码在您运行的机器上有注释吗?在我运行注释代码并对其进行注释以查看是否有帮助之前。它没有,也没有通过受让人驱动程序,所以它没有运行,所以没有打印
“na”
?Firefox会立即打开和关闭吗?是的(在荷兰语中na的意思是“之后”),您的问题在于
新的FirefoxDriver()
,请查找特定的异常。
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import static junit.framework.TestCase.assertTrue;


public class StepDefinitions {

    private WebDriver driver;

    @Given("^I am on the  website$")
    public void ShouldnavigateToWebsite(){
        System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
        System.out.println("voor");
        driver = new FirefoxDriver();
        System.out.println("na");
        driver.get("http://www.store.demoqa.com");
    }


    @When("^I click on login$")
    public void ClickOnLink(){
        driver.findElement(By.id("account")).click();
    }

    @And("^Populate the contact form$")
    public void PopulateForms(){
        driver.findElement(By.id("log")).sendKeys("TimoTest");
        driver.findElement(By.id("pwd")).sendKeys("TimoTest1");
        driver.findElement(By.id("login")).click();
    }

    @Then("^I should be on the account page$")
    public void ShouldBeOnContactPage(){
        assertTrue("Not one account page",driver.getTitle().equals("your-account"));
    }
}