zoukankan      html  css  js  c++  java
  • Selenium2学习-006-WebUI自动化实战实例-004-解决 Chrome 浏览器证书提示:--ignore-certificate-errors

    此文主要讲述 Java 运行 Selenium 脚本时,如何消除 Chrome 浏览器启动后显示的证书错误报警提示,附带 Chrome 参数使浏览器最大化的参数。

    希望能对初学 Selenium2 WebUI 自动化测试编程的亲们有所帮助。若有不足之处,敬请大神指正,不胜感激!

    未忽略 Chrome 浏览器证书验证时,WebUI 自动化脚本启动 Chrome 浏览器后,浏览器显示如下:

    闲话少述,以下为设置 Chrome 启动参数的实例脚本源代码:

     1 /**
     2  * Aaron.ffp Inc.
     3  * Copyright (c) 2004-2015 All Rights Reserved.
     4  */
     5 package main.java.aaron.sele.demo;
     6 
     7 import java.util.Arrays;
     8 import java.util.concurrent.TimeUnit;
     9 
    10 import org.openqa.selenium.WebDriver;
    11 import org.openqa.selenium.chrome.ChromeDriver;
    12 import org.openqa.selenium.chrome.ChromeOptions;
    13 import org.openqa.selenium.remote.DesiredCapabilities;
    14 
    15 /**
    16  * UI自动化功能测试脚本:参数化启动 Chrome 浏览器
    17  * 
    18  * 实现 Chrome 浏览器启动的步骤如下:
    19  *   1.设定需要启动的 Chrome 的安装路径
    20  *   2.设定 Chrome 对应的 webdriver
    21  *   3.参数化启动 Chrome
    22  *   4.打开百度
    23  *   5.关闭并退出
    24  *   
    25  * @author Aaron.ffp
    26  * @version $Id: StartBrowerChromeIgnoreCert.java, V0.1 2015年1月20日 下午8:30:44 Aaron.ffp Exp $
    27  */
    28 public class StartBrowerChromeIgnoreCert {
    29     private static WebDriver cd;
    30     private static String baseUrl;   // 百度首页网址
    31 
    32     /**
    33      * 主方法入口
    34      * @param args
    35      */
    36     public static void main(String[] args) {
    37         /* 启动 chrome */
    38         chromeStart();
    39         /* 打开百度 */
    40         cd.get(baseUrl);
    41         /* 等待加载 */
    42         cd.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    43         /* 关闭 chrome */
    44 //        chromeQuit();
    45     }
    46     
    47     /**
    48      * Chrome WebDriver 设置, 网址及搜索内容初始化, 打开 Chrome 浏览器
    49      */
    50     public static void chromeStart(){
    51         /* 设定 chrome 启动文件的位置, 若未设定则取默认安装目录的 chrome */
    52         System.setProperty("webdriver.chrome.bin", "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
    53         /* 设定 chrome webdirver 的位置 */
    54         System.setProperty("webdriver.chrome.driver", "C:/Windows/System32/chromedriver.exe");
    55         /* 百度首页网址赋值 */
    56         baseUrl = "http://www.baidu.com/";
    57         /* 启动 chrome 浏览器 */
    58         cd = new ChromeDriver(chromeOptions());
    59     }
    60     
    61     /**
    62      * 设置 Chrome 浏览器的启动参数, 设置启动后浏览器窗口最大化, 忽略认证错误警示
    63      * 
    64      * @return ChromeOptions Chrome 参数设置
    65      */
    66     public static ChromeOptions chromeOptions(){
    67          ChromeOptions options = new ChromeOptions();
    68          DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    69          capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
    70          /* 浏览器最大化 */
    71          options.addArguments("--test-type", "--start-maximized");
    72          /* 忽略 Chrome 浏览器的认证错误 */
    73          options.addArguments("--test-type", "--ignore-certificate-errors");
    74          
    75          return options;
    76      }
    77     
    78     /**
    79      * 关闭并退出 Chrome
    80      */
    81     public static void chromeQuit(){
    82         /* 关闭 chrome */
    83         cd.close();
    84         /* 退出 chrome */
    85         cd.quit();
    86     }
    87 }
    View Code

     

    至此,WebUI 自动化功能测试脚本第 004 篇-解决 Chrome 浏览器证书提示:--ignore-certificate-errors 顺利完结,希望此文能够给初学 Selenium 的您一份参考。

    最后,非常感谢亲的驻足,希望此文能对亲有所帮助。热烈欢迎亲一起探讨,共同进步。非常感谢! ^_^

     

  • 相关阅读:
    react系列(二)高阶组件-HOC
    【译】2分钟介绍Rx
    react系列(一)JSX语法、组件概念、生命周期介绍
    react系列(零)安装
    函数节流和函数防抖
    观察者模式和发布订阅模式(下)
    观察者模式和发布订阅模式(上)
    java学习第二天 20207/7
    2020/7/6博客日报Java的开始--pthread的安装
    node.js实现excel导出/exceljs实现导出
  • 原文地址:https://www.cnblogs.com/fengpingfan/p/4236730.html
Copyright © 2011-2022 走看看