2012-12-27 175 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