Environment Preparation:
1. Java:
Install Java JDK:
Version: java 1.8 or above
Configure Java Environment Variables:
ADD Java_home
ADD CLASSPATH
Add to Path
Verify Java is Configured:input javac in CMD can get output successfully.
2. Eclipse https://www.eclipse.org/
Unzip the Eclipse file > Open eclipse.exe to launch Eclipse SDK:
VERSION:OXYGEN.1A (4.7.1A)
Set Workspace
Set Layout and Text Editor
3. TestNG
Install TestNG online in Eclipse:
Click Help, Install New software ...-click Add, Set name:testng for Eclipse and location: http://beust.c Om/eclipse -Select TestNG to install
4. Maven
Copy Maven package to the machine:
Configure Maven Environment Variables:
ADD maven_home
Add to Path
Verify Maven is Configured:input mvn–v in CMD can get output successfully.
5. Configure Maven and Eclipse
Click Help, Install New software ...-click Add, Set name:maven for Eclipse and location: http://download . eclipse.org/technology/m2e/releases- Select Maven integration for Eclipse to install
Set Maven Repository:
Set localrepository in maven_home/conf/settings.xml, such as:
<localRepository>D:/AutomationProjects/Eclipse/repository</localRepository>
Configure Maven in Eclipse:
Maven, Preferences, Open Eclipse, Select Window
Click installations , click Add to add the installation used to launch Maven--click Apply
Click User Settings , click Browse to select the Maven_home/conf/settings.xml-click
Create Maven Project
1. New a Maven Project
Open Eclipse, select File, New project, select maven , maven project , Clic K Next, click Next, click Next, Input Group ID and Artifact ID, then click Finish.
2. New a TestNG class
Right click in the Maven Project > select New- -- TestNG - TestNG class< /c6>, click Next, Input Class Name and click Finish.
Write the test scenarios in the class.
3. Add TestNG Dependency in Pom.xml
Pom.xml:Project Object Model. Maven configuration file.
4. Run the test scripts via TestNG
New a TestNG xml:
Right click the Maven Project > select New - ---Select XML --XML File-- Click Next, Input File name and click Finish.
Input the TestNG XML content like:
5. Build test Project via Maven
ADD build project information in Pom.xml
Open CMD, CD to the project folder
Compile the project via command:
>mvn Clean Compile
Build the project via command:
>mvn Clean Package
If Build The project success, the. jar file is located in target folder like:
.. \target\cpstestdemo-0.0.1.jar
6. Execute. Jar without Eclipse
7. Log
Using log4j2 to log console log output
<?XML version= "1.0" encoding= "UTF-8"?><ConfigurationStatus= "WARN"> <appenders> <Consolename= "Console"Target= "System_out"> <Patternlayoutpattern= "%d{yyyy-mm-dd HH:mm:ss. SSS} [%-5level]%logger{-3}:%l-%msg%n " /> </Console> <Rollingfilename= "Rollingfile"FileName= "Log/console.log"Filepattern= "log/$${date:yyyy-mm-dd}/console-%d{mm-dd-yyyy}-%i.log.gz"> <Patternlayout> <Pattern>%d [%p]%logger{-3}:%l-%m%n</Pattern> </Patternlayout> <Policies> <Onstartuptriggeringpolicy/> <Timebasedtriggeringpolicy/> <Sizebasedtriggeringpolicysize= "MB" /> </Policies> </Rollingfile> </appenders> <Loggers> <Root Level= "Debug"> <Appenderrefref= "Console" /> <Appenderrefref= "Rollingfile" /> </Root> </Loggers></Configuration>
Java + Selenium + TestNG + Maven framework for Web Automation