检索测试执行结果:单元测试

时间:2012-12-27 22:42:06

标签: unit-testing maven testng

我是新手测试: 我必须执行selenium测试,因为我正在使用TestNG(因为我需要报告和日志文件),所以在执行后我将显示执行结果或成功,所以我怎样才能得到测试结果

public class GoogleNavigationTest {
@Test
public  void testApp(){


    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    WebDriver driver = new FirefoxDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("cheese!");
        }
    });

    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    //Close the browser
    driver.quit();
}

}

我正在使用maven以mvn test命令行运行测试。

任何肝脏将不胜感激

1 个答案:

答案 0 :(得分:2)

如果您正在测试某个应用程序,那么您将验证一些预期结果。为此,您需要在测试用例中添加断言,以断言您的应用程序的行为方式。 TestNG最近添加了flexible asserts的功能。

TestNG自动生成的报告是输出文件夹中的index.html,它可以为您提供执行详细信息和日志(如果您已记录任何内容)以及失败(如果有)。