2012-06-12 156 views
0

我是新来的测试世界。我使用硒IDE来记录测试。另外,我将测试用例导出为JUnit4测试用例。我的出口看起来像:运行硒IDE出口测试用例

package com.example.tests; 

import java.util.regex.Pattern; 
import java.util.concurrent.TimeUnit; 
import org.junit.*; 
import static org.junit.Assert.*; 
import static org.hamcrest.CoreMatchers.*; 
import org.openqa.selenium.*; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.Select; 

public class Test { 
    private WebDriver driver; 
    private String baseUrl; 
    private StringBuffer verificationErrors = new StringBuffer(); 
    @Before 
    public void setUp() throws Exception { 
     driver = new FirefoxDriver(); 
     baseUrl = "http://192.168.8.207/"; 
     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    } 

    @Test 
    public void test() throws Exception { 
     driver.get(baseUrl + "/"); 
     driver.findElement(By.name("user")).clear(); 
     driver.findElement(By.name("user")).sendKeys("admin"); 
     driver.findElement(By.name("password")).clear(); 
     driver.findElement(By.name("password")).sendKeys("infineta123"); 
     driver.findElement(By.id("btnLogin-button")).click(); 
    } 

    @After 
    public void tearDown() throws Exception { 
     driver.quit(); 
     String verificationErrorString = verificationErrors.toString(); 
     if (!"".equals(verificationErrorString)) { 
      fail(verificationErrorString); 
     } 
    } 

    private boolean isElementPresent(By by) { 
     try { 
      driver.findElement(by); 
      return true; 
     } catch (NoSuchElementException e) { 
      return false; 
     } 
    } 
} 

如何执行此测试用例?在那之后,我该如何自动执行几个这样的测试用例呢?

回答

3

使用此代码作为您的测试的跑步者。

import org.junit.runner.JUnitCore; 
import com.example.tests; 

public static void main(String[] args) { 
    Result result = JUnitCore.runClasses(Test.class); 
    for (Failure failure : result.getFailures()) { 
     System.out.println(failure.toString()); 
    } 
} 

Test.class是包含测试代码的文件名(Test)。如果您有多个测试用例,您可以添加类别列表。

0

看看这个页面:http://code.google.com/p/selenium/wiki/UsingWebDriver

你可能会下载硒和进口它的项目。通过运行在NetBeans中我做到这一点 - -

如果这样做了,你可以去“测试” - 这取决于研究与开发工具,您使用的测试文件(Ctrl + F6我认为)