在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Python/ log4j日志
log4j日志
Selenium IDE測(cè)試創(chuàng)建
Selenium - IDE模式匹配
Selenium教程
多瀏覽器測(cè)試
Selenium IDE下載
Selenium用戶(hù)擴(kuò)展
鍵盤(pán)操作
捕捉屏幕截圖
Selenium網(wǎng)格
Selenium TestNG
Selenium定位器
查找所有鏈接
Selenium測(cè)試設(shè)計(jì)技術(shù)
鼠標(biāo)操作
下拉框交互
Selenium IDE驗(yàn)證點(diǎn)
Selenium IDE- 不同的瀏覽器
Selenium RC
多選擇操作
復(fù)選框交互
單選按鈕互動(dòng)
捕捉視頻
拖放
Selenium IDE 測(cè)試
Synchronization 同步
異常處理
Selenium 環(huán)境安裝設(shè)置
Selenium概述
用戶(hù)交互
Selenium Webdriver
Selenium IDE
Selenium頁(yè)面對(duì)象模型
Selenium IDE 工具特點(diǎn)
使用Excel數(shù)據(jù)驅(qū)動(dòng)
Selenium - Selenese命令

log4j日志

log4j日志

Log4j是審計(jì)日志框架,提供有關(guān)執(zhí)行過(guò)程中發(fā)生了什么樣的信息。它具有以下優(yōu)點(diǎn):

  • 讓我們來(lái)了解應(yīng)用程序運(yùn)行。

  • 日志輸出可以保存,可以在以后進(jìn)行分析。

  • 有助于調(diào)試,以防自動(dòng)化測(cè)試失敗

  • 也可用于審計(jì)目的看應(yīng)用的健康。

組件

1,Logger類(lèi)的實(shí)例。

2,用于記錄該消息為以下之一日志級(jí)別的方法

  • error

  • warn

  • info

  • debug

  • log

示例

讓我們同樣用百分比計(jì)算器這個(gè)演示。

第1步:從https://logging.apache.org/log4j/1.2/download.htmll下載log4j的JAR文件,并將下載JAR文件的解壓縮格式。

selenium_ide_158

第2步:通過(guò)瀏覽到文件菜單中創(chuàng)建'New Java Project'。

selenium_ide_159

第3步:輸入項(xiàng)目的名稱(chēng)為“log4j_demo”,然后單擊“Next”

selenium_ide_160

第4步:單擊添加外部JAR,并添加“Log4j-1.2.17.jar”

selenium_ide_161

第5步:單擊添加外部JAR,并添加Selenium webdriver的類(lèi)庫(kù)。

selenium_ide_162

第6步:單擊添加外部JAR,并添加Selenium webdriver的JAR文件的位于libs文件夾中。

selenium_ide_163

第7步:使用它我們可以指定Log4j的屬性添加一個(gè)新的XML文件。

selenium_ide_164

第8步:輸入日志文件的名稱(chēng)為“log4j.xml”。

selenium_ide_165

第9步:下面的最終文件夾結(jié)構(gòu)如下所示。

selenium_ide_166

第10步:現(xiàn)在增加Log4j 這將被記錄執(zhí)行過(guò)程中的性能。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
	<appender name="fileAppender" class="org.apache.log4j.FileAppender">
		<param name="Threshold" value="INFO" />
		<param name="File" value="percent_calculator.log"/>
			<layout class="org.apache.log4j.PatternLayout">
				<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}  [%c] (%t:%x) %m%n" />
			</layout>
	</appender>
	<root>
		<level value="INFO"/>
		<appender-ref ref="fileAppender"/>
	</root>
</log4j:configuration>

第11步:現(xiàn)在用于演示的目的,我們將結(jié)合log4j在相同的測(cè)試,我們已經(jīng)完成(百分比計(jì)算器)。添加一個(gè)類(lèi)文件“Main”方法功能

package log4j_demo;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;


public class log4j_demo 
{
	
  static final Logger logger = LogManager.getLogger(log4j_demo.class.getName());
  public static void main(String[] args) 
  {

	DOMConfigurator.configure("log4j.xml");

	logger.info("# # # # # # # # # # # # # # # # # # # # # # # # # # # ");
	logger.info("TEST Has Started");
	
	WebDriver driver = new FirefoxDriver();

	//Puts a Implicit wait, Will wait for 10 seconds before throwing exception
	driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

	//Launch website
	driver.navigate().to("http://www.calculator.net/"); logger.info("Open Calc Application");
	
	//Maximize the browser
	driver.manage().window().maximize();

	// Click on Math Calculators
	driver.findElement(By.xpath(".//*[@id='menu']/div[3]/a")).click();  logger.info("Clicked Math Calculator Link");
  
	// Click on Percent Calculators
	driver.findElement(By.xpath(".//*[@id='menu']/div[4]/div[3]/a")).click(); logger.info("Clicked Percent Calculator Link");

	// Enter value 10 in the first number of the percent Calculator
	driver.findElement(By.id("cpar1")).sendKeys("10"); logger.info("Entered Value into First Text Box");


	// Enter value 50 in the second number of the percent Calculator
	driver.findElement(By.id("cpar2")).sendKeys("50");  logger.info("Entered Value into Second Text Box");
	
	// Click Calculate Button
	driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr/td[2]/input")).click(); logger.info("Click Calculate Button");

	// Get the Result Text based on its xpath
	String result = driver.findElement(By.xpath(".//*[@id='content']/p[2]/span/font/b")).getText();  logger.info("Get Text Value");
	
	//Print a Log In message to the screen
	logger.info(" The Result is " + result);
	
	if(result.equals("5"))
	{
		logger.info("The Result is Pass");

	}
	else
	{
		logger.error("TEST FAILED. NEEDS INVESTIGATION");

	}
	
	logger.info("# # # # # # # # # # # # # # # # # # # # # # # # # # # ");
	
	//Close the Browser.
	driver.close();    
  }
}

執(zhí)行

在執(zhí)行日志文件的根文件夾中創(chuàng)建如下圖所示。在Eclipse中不能找出文件。應(yīng)該打開(kāi)“Windows資源管理器”來(lái)顯示相同。

selenium_ide_167

該文件的內(nèi)容如下所示。

selenium_ide_168
 

上一篇:下拉框交互下一篇:Selenium RC