2016-11-16 104 views
-1

我正在写一个基本的与Selenium集成的Cucumber测试我想打开一个网站登录并检查我是否已经登录。问题是在测试的第一步中,firefox是opend和imediatly关闭和测试无限期运行。 Here you can see my map structure all the other maps are emptySelenium只打开并直接关闭浏览器

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(之前)。

+0

您的代码在您正在运行的机器上发表了评论吗? – Moshisho

+0

之前,我有评论代码运行和评论它,看看它是否有帮助。它没有,它没有通过受让人的驱动程序,所以它不会运行 – Nick

+0

所以'“na”'不打印?并且Firefox立即打开并关闭? – Moshisho

回答

0

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

相关问题