有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我正在用Selenium integrated编写一个基本的Cucumber测试,我想打开一个站点登录并检查我是否已登录。问题是在测试的第一步,firefox即时打开和关闭,测试无限期运行。 Here you can see my map structure all the other maps are empty

import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class CucumberRunner {
}

这是我的跑步课

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(以前)


共 (1) 个答案

  1. # 1 楼答案

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