TesNG和Selenium集成使用
TestNG 是一个设计用来简化广泛的测试需求的测试框架,从单元测试(隔
离测试一个类)到集成测试(测试由有多个类多个包甚至多个外部框架组成的整
个系统,例如运用服务器)。
TestNG 是一个设计用来简化广泛的测试需求的测试框架,从单元测试到
集成测试
这个是TestNG 设计的出发点,不仅仅是单元测试,而且可以用于集成测试。
运行批处理文件
@echo off
rem test.bat src\testng.xml https:\/\/192.168.0.156
setlocal DisableDelayedExpansion
if "%1%"=="" (
set TESTSUIT=src\testng.xml
) else (
set TESTSUIT=%1%
)
if not "%2%"=="" (
attrib -R src\testng.xml
Rem 替换测试的URL
type %TESTSUIT% | C:\test\UnxUtils\usr\local\wbin\sed.exe -e "s/http:\/\/localhost\/test.htm/%2%/g" >test.xml
rem copy /Y test.xml %TESTSUIT%
) else (
copy /Y %TESTSUIT% test.xml
)
endlocal
rem ===================================
setlocal EnableDelayedExpansion
set JAVA_HOME=%JAVA_HOME%
rem set PATH=%PATH;%JAVA_HOME%\bin
set CLASSPATH=./bin;
set LIBS=
pushd libs
for /f "delims=" %%s in ('dir /b') do (
rem echo %%s
set LIBS=!LIBS!;./libs/
set LIBS=!LIBS!%%s;
)
popd
rem echo %LIBS%
set CLASSPATH=./bin/;%LIBS%
rem echo %CLASSPATH%
rem pause
java -classpath %CLASSPATH% org.testng.TestNG test.xml
endlocal
testng的配置文件例子
<?xml version='1.0' encoding='UTF-8' ?>
<suite name="Parallel Tests" verbose="1" thread-count="4"
parallel="tests">
<tests>
<test name="Windows+IE8 Test">
<parameters>
<parameter name="platform" value="Windows" />
<parameter name="browser" value="Internet Explorer" />
<parameter name="version" value="8" />
<parameter name="url" value="http://localhost/test.htm" />
</parameters>
<classes>
<class name="logon" />
</classes>
</test>
<test name="Windows+Firefox4 Test">
<parameters>
<parameter name="platform" value="Windows" />
<parameter name="browser" value="Firefox" />
<parameter name="version" value="4" />
<parameter name="url" value="http://localhost/test.htm" />
</parameters>
<classes>
<class name="logon" />
</classes>
</test>
<test name="Windows+Chrome Test">
<parameters>
<parameter name="platform" value="Windows" />
<parameter name="browser" value="chrome" />
<parameter name="version" value="31" />
<parameter name="url" value="http://localhost/test.htm" />
</parameters>
<classes>
<class name="logon" />
</classes>
</test>
</tests>
</suite>