2012-12-27 262 views
0

我是新来的测试: 我必须执行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命令行一起运行测试。

任何HEP可以理解

回答

2

如果您正在测试的应用程序,你会被验证一些预期的结果。为此,您需要将断言添加到测试用例中,以断言您期望的是您的应用程序的行为方式。 TestNG最近增加了flexibleasserts的功能。

通过TestNG的自动生成的报告是在你的输出文件夹的index.html,它可以给你的执行细节和日志(如果您已经登录的话),如果任何故障。

+0

所以我会从index.html得到它。很多谢谢:) – AmiraGL