<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 具有 Selenium 教程的 Log4j:下載,安裝,使用&示例 > 原文: [https://www.guru99.com/tutorial-on-log4j-and-logexpert-with-selenium.html](https://www.guru99.com/tutorial-on-log4j-and-logexpert-with-selenium.html) ## 什么是 Log4j? Log4j 是一種快速,靈活且可靠的日志記錄框架(APIS),該框架以 [Java](/java-tutorial.html) 于 1996 年初開發。它根據 [Apache](/apache.html) 軟件許可進行分發。 Log4J 已移植到 C,C ++,C#, [Perl](/perl-tutorials.html) , [Python](/python-tutorials.html) ,Ruby 和 Eiffel 語言中。 它是用于小型到大型 Selenium Automation 項目的工具。 ## 為什么要使用 Log4j? * 它是一個開源的 * 使用 Log4j,可以將 Selenium Automation 的流程詳細信息存儲在文件或數據庫中 * Log4j 用于大型和小型項目 * 在 Log4j 中,我們在代碼中使用日志語句而不是 SOPL 語句來了解項目在執行時的狀態 ## Log4j 具有三個主要組件 ![Log4j with Selenium Tutorial](https://img.kancloud.cn/0b/a3/0ba364b34cec300d14f1e62bfdf4373b_634x304.png "Log4j and LogExpert with Selenium Tutorial") 1. **記錄器**:它負責記錄信息。 要將記錄器實施到項目中,需要執行以下步驟- * **為記錄器類**創建一個實例:Logger 類是一個基于 Java 的實用程序,已經實現了使用 log4j 的所有通用方法。 * **定義 Log4j 級別**:主要有五種日志級別 1. 全部-此級別的日志記錄將記錄所有內容(它將打開所有日志) 2. 調試–打印調試信息,對開發階段有幫助 3. INFO –打印信息性消息,突出顯示應用程序的進度 4. WARN –警告–打印有關系統故障和意外行為的信息。 5. 錯誤–打印錯誤消息,可能允許系統繼續 6. 致命–打印導致系統崩潰的系統關鍵信息 7. 關–不記錄 2. **Appenders**: It is used to deliver LogEvents to their destination. It decides what will happen with log information. In simple words, it is used to write the logs in file. Following are few types of Appenders 1. ConsoleAppender 記錄到標準輸出 2. 文件附加器將日志打印到某些文件 3. 將文件追加器滾動到最大大小的文件 注意:在 log4j 屬性中,我們可以使用任何名稱調用 appender。 也有其他附加程序,但我們將限于這幾個。 3. **布局**:它負責格式化不同樣式的日志信息。 Logger 類提供了不同的方法來處理日志記錄活動。 它提供了兩種用于獲取 Logger 對象的靜態方法。 ``` Public static Logger getRootLogger() Public static Logger getLogger(String name) ``` ## 如何配置 log4j? 要配置 log4j,我們必須確定要實現的附加程序。 因此,將設置附加器的參數。 * 我們將使用 DEBUG 級別和 RollingFileAppender * 我們將做兩個配置或日志, * 首先:root logger,它將以文件名(即 Selenium.logs)寫入所有系統生成的日志 * 第二:將手動命令生成的信息以代碼形式寫入文件名 Manual.logs * 布局將為 PatternLayout #根記錄器 ``` log4j.rootLogger=DEBUG,file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=D:\\Guru99\\src\\Selenium.logs log4j.appender.file.maxFileSize=900KB log4j.appender.file.maxBackupIndex=5 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c<strong>{1}</strong>:%L - %m%n log4j.appender.file.Append=false ``` #應用程序日志 ``` log4j.logger.devpinoyLogger=DEBUG, dest1 log4j.appender.dest1=org.apache.log4j.RollingFileAppender log4j.appender.dest1.maxFileSize=900KB log4j.appender.dest1.maxBackupIndex=6 log4j.appender.dest1.layout=org.apache.log4j.PatternLayout log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n log4j.appender.dest1.File=D:\\ Guru99\\src\\Manual.logs log4j.appender.dest1.Append=false ``` 在上面的示例中,我們配置了 log4j 來登錄名為 Selenium.log 和 Manual.log 的兩個不同文件。 * file 和 dest1 是兩個標識符。 * “文件”用于指定將在其中保存日志的文件名 * “ maxFileSize”用于配置日志文件的最大大小。 當文件達到此大小時,將創建一個具有相同名稱的新文件,并將舊文件名添加為索引。 * “ maxBackupIndex”用于配置要備份的最大文件數。 * “布局”用于設置日志文件的格式。 * “追加”用于設置追加功能。 如果將其設置為 false,則每次創建新文件而不是使用舊文件進行日志記錄 ## 在腳本中如何使用 log4j? 在代碼中,我們已將“ log”用作引用 Logger 類的 getLogger 方法的參考變量 ``` Logger log = Logger.getLogger("devpinoyLogger"); ``` 使用“ log”引用變量和調試方法來記錄所需的信息。 ``` log.debug("--information--"); ``` ## 什么是 LogExpert 工具? 1. LogExpert 工具是 Windows 開發的用于尾隨日志的工具 2. 它是免費的開源日志查看器。 3. 它是一個日志分析工具,具有多種功能,例如搜索,過濾,添加書簽和突出顯示日志 4. 在此工具日志中,文件在打開時會自動更新 5. 在此工具中,我們可以在不同的選項卡中打開多個日志文件 6. 我們還可以在書簽上添加評論,并且有快捷鍵可以在不同的書簽之間導航。 我們還可以看到完整的書簽列表并從那里導航 7. 該工具的快捷方式在幫助文件中提供,以便可以參考該工具。 ## 將 Log4j 與 Selenium 結合使用的步驟 **步驟 1)**在 Eclipse 中創建一個名稱為 log4j_demo 的新項目。 ![Log4j with Selenium Tutorial](https://img.kancloud.cn/86/f6/86f682cfd6b1a36073a6119aa6af42a9_311x223.png "Log4j and LogExpert with Selenium Tutorial") **步驟 2)**右鍵單擊 src->構建路徑->配置構建路徑 ![Log4j with Selenium Tutorial](https://img.kancloud.cn/a9/cb/a9cbcc5b31a58bb18ca1bd6e54d503b0_718x479.png "Log4j and LogExpert with Selenium Tutorial") **步驟 2)**單擊 Libraries 并添加 Log4J Library。 您可以從 [https://logging.apache.org/log4j/1.2/download.html](https://logging.apache.org/log4j/1.2/download.html) 下載 ![Log4j with Selenium Tutorial](https://img.kancloud.cn/02/a0/02a09362c33de742d5581c3f19aea520_774x564.png "Log4j and LogExpert with Selenium Tutorial") **步驟 3)**創建一個新文件。 該文件將包含所有 log4j 配置 1. 右鍵單擊 src->新建->其他->常規->文件 2. 將文件名命名為“ log4j.properties” 3. 點擊完成 再創建兩個文件,并為其命名,例如 Selenium.logs 和 Manual.logs。 這些文件將包含系統創建的所有日志和手動記錄的語句 ![Log4j with Selenium Tutorial](https://img.kancloud.cn/96/e2/96e2e3e29dec4aa7f1b4f0e1405398a9_547x140.png "Log4j and LogExpert with Selenium Tutorial") **步驟 4)**在 log4j.properties 中復制整個配置。 ![Log4j with Selenium Tutorial](https://img.kancloud.cn/73/8f/738fb2bbbf2824e4743d0d3c58a6598b_684x356.png "Log4j and LogExpert with Selenium Tutorial") **步驟 5)**創建主類: 1. 右鍵單擊默認軟件包->新建->類 2. 輸入課程名稱,然后單擊完成 ![Log4j with Selenium Tutorial](https://img.kancloud.cn/f7/30/f73009b026c443da9dc58455dacd1ab7_530x533.png "Log4j and LogExpert with Selenium Tutorial") **步驟 6)**將以下代碼復制到主類中 ``` import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.apache.log4j.Logger; public class LoggingDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); Logger log = Logger.getLogger("devpinoyLogger"); driver.get("http://healthunify.com/bmicalculator/"); log.debug("opening webiste"); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); log.debug("entring weight"); driver.findElement(By.name("wg")).sendKeys("87"); log.debug("selecting kilograms"); driver.findElement(By.name("opt1")).sendKeys("kilograms"); log.debug("selecting height in feet"); driver.findElement(By.name("opt2")).sendKeys("5"); log.debug("selecting height in inchs"); driver.findElement(By.name("opt3")).sendKeys("10"); log.debug("Clicking on calculate"); driver.findElement(By.name("cc")).click(); log.debug("Getting SIUnit value"); String SIUnit = driver.findElement(By.name("si")).getAttribute("value"); log.debug("Getting USUnit value"); String USUnit = driver.findElement(By.name("us")).getAttribute("value"); log.debug("Getting UKUnit value"); String UKUnit = driver.findElement(By.name("uk")).getAttribute("value"); log.debug("Getting overall description"); String note = driver.findElement(By.name("desc")).getAttribute("value"); System.out.println("SIUnit = " + SIUnit); System.out.println("USUnit = " + USUnit); System.out.println("UKUnit = " + UKUnit); System.out.println("note = " + note); driver.quit(); } } ``` 在上面的代碼中,我們訪問 [http://healthunify.com/bmicalculator/](http://healthunify.com/bmicalculator/) 并驗證 BMI 計算器。 輸入的重量為 87KG,高度為 5 英尺 10 英寸。 該腳本以 SE,US 和 UK 單位檢查輸出。 使用 Logger.getLogger(“ devpinoyLogger”)我們創建系統級日志 使用 log.debug 方法,我們將數據存儲到 Manual.log **步驟 7)**運行腳本。 打開“手動”和“硒”日志的位置以檢查日志數據。 ## 如何使用 LogExpert 工具分析日志 1. Download the tool from [http://logexpert.codeplex.com/](http://logexpert.codeplex.com/) . Go to LogExpert download folder ![Log4j with Selenium Tutorial](https://img.kancloud.cn/4e/05/4e0504014eb25d08b398b5fe6ad718db_316x141.png "Log4j and LogExpert with Selenium Tutorial") 2. 打開 LogExpert.exe 3. 單擊文件->打開并瀏覽到 Manual.log 和 Selenium.log 文件的存儲路徑。 選擇文件 4. Select the "Follow tail" option ![Log4j with Selenium Tutorial](https://img.kancloud.cn/d9/74/d9746e09ff10eb5cbeab2235024f2832_578x85.png "Log4j and LogExpert with Selenium Tutorial") 選擇跟隨尾部選項將啟用日志尾部,這意味著在腳本處于執行階段時,LogExpert 自動更新日志文件。 如果我們使用其他任何編輯器(如記事本),則必須關閉并重新打開文件一次以更新日志。 但是,如果 ExpertTool 處于“跟蹤尾巴”模式,則不需要這樣做。 下圖顯示了日志的布局 ![Log4j with Selenium Tutorial](https://img.kancloud.cn/e8/f3/e8f318ac67370e5b8cd5f9c7db9c58b0_917x620.png "Log4j and LogExpert with Selenium Tutorial") ![Log4j with Selenium Tutorial](https://img.kancloud.cn/c8/5c/c85c9843883653ba32aef8562323144e_1109x765.png "Log4j and LogExpert with Selenium Tutorial") 使用 LogExpert 工具,可以調試 selenium Webdriver 創建的日志,就像在此工具中一樣 * 搜索任何文本和正則表達式, * 創建書簽并對其進行注釋,還可以在書簽之間導航,這是其他任何工具所無法實現的, * 過濾日志并搜索文本范圍,還可以將其他過濾器應用于之前過濾的日志, * 根據某些單詞突出顯示不同的行。 該工具還有助于將數據劃分為不同的列。
                  <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>

                              哎呀哎呀视频在线观看