Java + Selenium + TestNG + Maven framework for Web Automation

Source: Internet
Author: User
Tags testng

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.