<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 如何在 Selenium WebDriver 中創建 Firefox 配置文件 > 原文: [https://www.guru99.com/firefox-profile-selenium-webdriver.html](https://www.guru99.com/firefox-profile-selenium-webdriver.html) Firefox 配置文件是可以在 Firefox 瀏覽器上完成的設置,自定義,加載項和其他個性化設置的集合。 您可以自定義 Firefox 配置文件以適合您的 Selenium 自動化要求。 此外,Firefox 或任何其他瀏覽器都會處理 SSL 證書設置。 因此,將它們自動化以及測試執行代碼非常有意義。 簡而言之,配置文件是用戶的個人設置。 當您想在 Firefox 瀏覽器上運行可靠的自動化程序時,建議制作一個單獨的配置文件。 在本教程中,您將學習- * [配置文件文件夾在磁盤](#1)中的位置 * [如何創建 Firefox 配置文件](#2) * [硒自動化腳本](#3) * [Firefox 配置文件示例 1](#4) * [Firefox 配置文件示例 2](#5) ## 您的配置文件文件夾在磁盤中的位置 Firefox 配置文件就像使用 Firefox 的其他用戶一樣。 Firefox 保存個人信息,例如書簽,密碼和用戶首選項,可以使用程序管理器進行編輯,刪除或創建。 ![How to Create Firefox Profile in Selenium WebDriver](https://img.kancloud.cn/43/6d/436ddb27d21f09e11835392c7afdb898_223x84.png "Firefox Profile - Selenium WebDriver") 配置文件的位置如下 * 對于 Windows 7 > /AppData/MozillaFirefoxProfile_name.default * 對于 [Linux](/unix-linux-tutorial.html) > /.mozilla/firefox/profile_name.default/ * 對于 Mac OS X >?/ Library / ApplicationSupport / Firefox / Profiles / profile_name.default / 為了運行成功的 Selenium 測試,Firefox 配置文件應為- * 易于裝載 * 代理設置(如果需要) * 根據自動化需求的其他用戶特定設置 ## 如何創建 Firefox 配置文件 讓我們逐步介紹如何創建 Firefox 配置文件。 **步驟 1)**首先,如果打開 Firefox,則將其關閉。 **步驟 2)**打開運行(Windows 鍵+ R)并鍵入 firefox.exe –p,然后單擊“確定”。 ![How to Create Firefox Profile in Selenium WebDriver](https://img.kancloud.cn/07/8d/078d4d66933a745d64eb8c09ed9296f6_420x222.png "Firefox Profile - Selenium WebDriver") 注意:如果無法打開,則可以嘗試使用引號中的完整路徑。 * 在 32 位 Windows 上:“ C:Program FilesMozilla Firefox.exe” –p * 在 64 位上:Windows:“ C:Program Files(x86)Mozilla Firefox.exe” –p **步驟 3)**將打開一個名為 Firefox 的對話框-選擇用戶個人資料 ![How to Create Firefox Profile in Selenium WebDriver](https://img.kancloud.cn/52/36/523628936dfdf3893ee414ff1cfeda85_379x305.png "Firefox Profile - Selenium WebDriver") **步驟 4)**從窗口中選擇選項“創建配置文件”,將打開一個向導。 點擊下一步 ![How to Create Firefox Profile in Selenium WebDriver](https://img.kancloud.cn/49/57/4957427ae85a162f0923838096c01649_374x302.png "Firefox Profile - Selenium WebDriver") **步驟 5)**輸入您要創建的個人資料名稱,然后點擊完成按鈕 ![How to Create Firefox Profile in Selenium WebDriver](https://img.kancloud.cn/d0/6f/d06fb7ab34ab1f16ab3918d4ff873cb3_440x336.png "Firefox Profile - Selenium WebDriver") 現在您的個人資料已準備就緒,您可以選擇您的個人資料并打開 Firefox。 您會注意到,新的 Firefox 窗口不會顯示任何“書簽”和“收藏夾”圖標。 **注意:**上一次選擇的配置文件將在下次 Firefox 啟動時自動加載。 如果要更改配置文件,則需要重新啟動配置文件管理器。 ## 硒自動化腳本 要在 Selenium Webdriver 軟件測試中訪問新創建的 Firefox 配置文件,我們需要使用 webdrivers 內置類'profilesIni'及其方法 getProfile,如下所示。 **配置文件**的硒代碼 這是實現配置文件的代碼,可以嵌入到硒代碼中。 ``` ProfilesIni profile = new ProfilesIni(); ``` //這將為 Firefox 配置文件創建一個對象 ``` FirefoxProfile myprofile = profile.getProfile("xyzProfile"); ``` //這將初始化 Firefox 驅動程序 ``` WebDriver driver = new FirefoxDriver(myprofile) ``` 讓我們在以下示例中查看此代碼的實現。 ### Firefox 配置文件示例 1 ![How to Create Firefox Profile in Selenium WebDriver](https://img.kancloud.cn/17/24/172469c473de15ebf356c37a157c9b92_537x322.png "Firefox Profile - Selenium WebDriver") ``` // import the package import java.io.File; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.internal.ProfilesIni; public class FirefoxProfile { public static void main(String[] args) { ProfilesIni profile = new ProfilesIni(); FirefoxProfile myprofile = profile.getProfile("xyzProfile"); // Initialize Firefox driver WebDriver driver = new FirefoxDriver(myprofile); //Maximize browser window driver.manage().window().maximize(); //Go to URL which you want to navigate driver.get("http://www.google.com"); //Set timeout for 5 seconds so that the page may load properly within that time driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //close firefox browser driver.close(); } } ``` **代碼解釋:** 以下是逐行代碼的說明。 * **代碼行 2-7** :首先,我們需要導入運行硒代碼所需的包。 * **代碼行 8** :設置一個公共類“ FirefoxProfile”。 * **代碼行 9** :制作一個對象(您需要具有 oops 概念的基本知識)。 * **代碼行 10-11** :我們需要使用 myprofile 對象初始化 Firefox 配置文件。 * **代碼行 13** :為 Firefox 創建對象 * **代碼行 15** :最大化窗口。 * **代碼行 17** :Driver.get 用于導航到給定的 URL。 * **代碼行 19** :設置超時用于等待一段時間,以便瀏覽器可以在繼續下一頁之前加載頁面。 * **代碼行 21** :關閉 Firefox。 讓我們再看一個例子。 ### Firefox 配置文件示例 2 ![How to Create Firefox Profile in Selenium WebDriver](https://img.kancloud.cn/33/75/337560f7dabd3513bb596f9be3d5688e_733x314.png "Firefox Profile - Selenium WebDriver") ``` import java.io.File; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.internal.ProfilesIni; public class FirefoxProfile2{ public static void main(String[] args) { // Create object for FirefoxProfile FirefoxProfilemyprofile=newFirefoxProfile (newFile("\c:users\AppData\MozillaFirefoxProfile_name.default ")); // Initialize Firefox driver WebDriver driver = new FirefoxDriver(myprofile); //Maximize browser window driver.manage().window().maximize(); //Go to URL driver.get("http://www.google.com"); //Set timeout driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //close firefox browser driver.close(); } ``` **代碼**的說明: Below is the explanation of code line by line. * **代碼行 1-6:**首先,我們需要導入運行硒代碼所需的包。 * **代碼行 8** :設置一個公共類 FirefoxProfile 2。 * **代碼行 12** :通過引用精確路徑來創建 myprofile 對象。 * **代碼行 14** :為 Firefox 創建對象 * **代碼行 16** :最大化窗口。 * **代碼行 18** :Driver.get 用于導航到給定的 URL。 * **代碼行 20** :設置超時用于等待一段時間,以便瀏覽器可以在繼續下一頁之前加載頁面。 * **代碼行 22** :關閉 Firefox。 **摘要**: * 自動化 Firefox 配置文件非常有意義,因為它們可以處理 SSL 證書設置。 * 可以自定義 Firefox 配置文件以適合您的 Selenium 自動化要求。 * Firefox 配置文件應易于加載,并具有一些特定于用戶的代理設置以運行良好的測試。 * 要在 Selenium Webdriver 軟件測試中訪問新創建的 Firefox 配置文件,我們需要使用 webdrivers 內置類'profilesIni'及其方法 getProfile。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看