Selenium2學習-006-WebUI自動化實戰執行個體-004-解決 Chrome 瀏覽器認證提示:--ignore-certificate-errors

來源:互聯網
上載者:User

標籤:

此文主要講述 Java 運行 Selenium 指令碼時,如何消除 Chrome 瀏覽器啟動後顯示的認證錯誤判警提示,附帶 Chrome 參數使瀏覽器最大化的參數。

希望能對初學 Selenium2 Web使用者介面自動化測試編程的親們有所協助。若有不足之處,敬請大神指正,不勝感激!

未忽略 Chrome 瀏覽器認證驗證時,Web使用者介面自動化指令碼啟動 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 對應的 webdriver21  *   3.參數化啟動 Chrome22  *   4.開啟百度23  *   5.關閉並退出24  *   25  * @author Aaron.ffp26  * @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 args35      */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      * 關閉並退出 Chrome80      */81     public static void chromeQuit(){82         /* 關閉 chrome */83         cd.close();84         /* 退出 chrome */85         cd.quit();86     }87 }
View Code

 

至此,Web使用者介面自動化功能測試指令碼第 004 篇-解決 Chrome 瀏覽器認證提示:--ignore-certificate-errors 順利完結,希望此文能夠給初學 Selenium 的您一份參考。

最後,非常感謝親的駐足,希望此文能對親有所協助。熱烈歡迎親一起探討,共同進步。非常感謝! ^_^

Selenium2學習-006-WebUI自動化實戰執行個體-004-解決 Chrome 瀏覽器認證提示:--ignore-certificate-errors

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.