2016-11-16 105 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。希望它能解決你的問題。

相關問題