1. /** 2. * 組件類 3. * @author renzq 4. * 5. */ 6. public class GooglePageSearchComponent { 7. 8. /** 9. * 進行查詢操作 10. * @param content 查詢的內容 11. * @throws SeleniumHelperNotExistException 12. */ 13. public void search(String content) throws SeleniumHelperNotExistException{ 14. GoogleGuis.SearchPage.PageOpen(); 15. GoogleGuis.SearchInput.type(content); 16. GoogleGuis.SearchButton.click(); 17. GoogleGuis.SearchPage.WaitForPageReady("3000"); 18. 19. } 20. /** 21. * 校驗查詢javascript:tagshow(event, '%BD%E1%B9%FB');" href="javascript:;" target=_self>結果是否含有內容 22. * @param content 內容 23. * @return 根據是否含有,返回判斷的值 24. * @throws SeleniumHelperNotExistException 25. */ 26. public boolean checkText(String content) throws SeleniumHelperNotExistException{ 27. return GoogleGuis.SearchPage.PageTextContain(content); 28. } 29. 30. } |
第四層,應該就是測試斷言層,這個部分用來執行testcase。
Java代碼:
1. public class GoogleSearch extends SeleneseTestCase{ 2. 3. public void setUp() throws Exception { 4. super.setUp("http://www.google.com/", "*iexplore"); 5. com.asiainfo.selenium.gui.UIObjectHelper.SeleniumHelper=selenium; 6. } 7. 8. public void testNew() throws Exception { 9. GooglePageSearchComponent gpsc=new GooglePageSearchComponent(); 10. gpsc.search("asiainfo"); 11. assertTrue(gpsc.checkText("asiainfo")); 12. 13. } 14. } |
如果使用testsuite就應該有第五層,這層主要用來組織testcase。
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/