第二层主要是构件层,主要用来描述页面上的控件,这里我用了最简单的静态变量的方法,还可以使用yml,xml,json甚至某种格式的文本文件进行描述,之后根据文件生成,这样可能会更加方面修改。
代码如下:
Java代码:
1. public class GoogleGuis { 2. public static PageUIObject SearchPage = new PageUIObject("/"); 3. public static TextFieldUIObject SearchInput = new TextFieldUIObject("q"); 4. public static ButtonUIObject SearchButton = new ButtonUIObject("btnG"); 5. } |
第三层应该叫组件层,可以页面切分成大组件,然后对组件进行相关的操作,这里把Google的搜索作为一个组件,代码如下:
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. * 校验查询结果是否含有内容 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. } |