1. /**
  2. * rewrite the get method, adding user defined log</BR>
  3. * 地址跳转方法,使用WebDriver原生get方法,加入失败重试的次数定义。
  4. *
  5. * @param url the url you want to <span id="2_nwp" style="width: auto; height: auto; float: none;"><a target=_blank id="2_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=11&is_app=0&jk=69829344341ee6cd&k=open&k0=open&kdi0=0&luki=2&n=10&p=baidu&q=v77y4_cpr&rb=0&rs=1&seller_id=1&sid=cde61e3444938269&ssp2=1&stid=0&t=tpclicked3_hc&td=2102575&tu=u2102575&u=http%3A%2F%2Fwww%2Eylzx8%2Ecn%2Fzonghe%2Fopen%2Dsource%2F247951%2Ehtml&urlid=0" target="_blank" mpid="2" style="color: rgb(1, 70, 108); text-decoration: none;"><span style="color: rgb(0, 0, 255); width: auto; height: auto;">open</span></a></span>.
  6. * @param actionCount retry times when load timeout occuers.
  7. * @throws RuntimeException
  8. */
  9. protected void get(String url, int actionCount) {
  10. boolean inited = false;
  11. int index = 0, timeout = 10;
  12. while (!inited && index < actionCount){
  13. timeout = (index == actionCount - 1) ? maxLoadTime : 10;//最后一次跳转使用最大的默认超时时间
  14. inited = navigateAndLoad(url, timeout);
  15. index ++;
  16. }
  17. if (!inited && index == actionCount){//最终跳转失败则抛出运行时异常,退出运行
  18. throw new RuntimeException("can not get the url [" + url + "] after retry " + actionCount + "times!");
  19. }
  20. }
  21. /**
  22. * rewrite the get method, adding user defined log</BR>
  23. * 地址跳转方法,使用WebDriver原生get方法,默认加载超重试【1】次。
  24. *
  25. * @param url the url you want to open.
  26. * @throws RuntimeException
  27. */
  28. protected void get(String url) {
  29. get(url, 2);
  30. }
  31. /**
  32. * judge if the url has navigate and page load completed.</BR>
  33. * 跳转到指定的URL并且返回是否跳转完整的结果。
  34. *
  35. * @param url the url you want to open.
  36. * @param timeout the timeout for page load in seconds.
  37. * @return if page load completed.
  38. */
  39. private boolean navigateAndLoad(String url, int timeout){
  40. try {
  41. driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
  42. driver.get(url);
  43. return true;//跳转并且加载页面成功在返回true
  44. } catch (TimeoutException e) {
  45. return false;//超时的情况下返回false
  46. } catch (Exception e) {
  47. failValidation();//共用的异常处理方法
  48. LOG.error(e);//记录错误日志
  49. throw new RuntimeException(e);//抛出运行时异常,退出运行
  50. }finally{
  51. driver.manage().timeouts().pageLoadTimeout(maxLoadTime, TimeUnit.SECONDS);
  52. }
  53. }

最新文章

  1. SiteMesh, SpringMVC, Shiro 配置
  2. Lua语言的特别之处
  3. 【项目管理和构建】十分钟教程,eclipse配置maven + 创建maven项目(三)
  4. 检索COM 类工厂中CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败
  5. Linux系统上安装软件(JDK以及tomcat服务器)
  6. (转载)SQL语句,纵列转横列
  7. MVC学习系列——参考
  8. hibernateTemplate的load方法
  9. jquery mobile (一)
  10. JS验证手机号码
  11. C#系列教程——switch定义及使用
  12. CVTE 嵌入式软件工程师 二面
  13. js获取页面宽高
  14. TCP传输协议使用
  15. JAVA Socket编程(一)之UDP通信
  16. HDU 4315 Climbing the Hill [阶梯Nim]
  17. 配置WebLogic的详细步骤
  18. 利用MYSQL的函数实现用户登录功能,进出都是JSON(第二版)
  19. git 入门教程之版本管理
  20. Fixation index

热门文章

  1. 产品如何进行大屏数据可视化.md
  2. GitHub+Octopress搭建免费blog
  3. mac 安装scrapy
  4. 转: WebRTC音视频引擎研究(1)--整体架构分析
  5. java内存模型(Java Memory Model)
  6. spring security开发步骤
  7. vue class绑定 组件
  8. hihocoder 1032 manachar 求回文串O(n)
  9. 嵌入式Linux驱动案例之中的一个
  10. Linux基础(3)- 正文处理命令及tar命令、vi编辑器、硬盘分区、格式化及文件系统的管理和软连接、硬连接