Java + Selenium + TestNG + Maven 框架实现Web Automation

环境准备:

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 was 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.com/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 was 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:
Open Eclipse -> Select Window -> Preferences -> Maven
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

创建Maven Project

1. New a Maven Project
Open Eclipse -> Select File -> New -> Project -> Select Maven -> Maven Project -> Click 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 -> Other -> select TestNG -> TestNG class -> 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 -> Other -> 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 was 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"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %logger{-3}:%L - %msg%n" />
        </Console>
        <RollingFile name="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 />
                <SizeBasedTriggeringPolicy size="20 MB" />
            </Policies>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Console" />
            <AppenderRef ref="RollingFile" />
        </Root>
    </Loggers>
</Configuration>

原文地址:https://www.cnblogs.com/daly/p/8987484.html

时间: 2024-08-21 15:22:46

Java + Selenium + TestNG + Maven 框架实现Web Automation的相关文章

MyEclipse使用总结——在MyEclipse中新建Maven框架的web项目[转]

前面的文章我们已经在本机安装好了maven,同时在myeclipse中配置好了maven的插件. 链接如下: Maven安装----在Windows上安装Maven myeclipse安装maven插件 现在我们就开始在myeclipse中新建一个maven框架的web项目 新建项目 填写项目名称,一定记得勾选Add Maven support (java EE如果选取5.0报错,则选6.0) 我们的maven项目就新建好了,相关基本的依赖已经在pom.xml中.项目机构如下: 可能出现的错误及

Mac系统搭建java+selenium+testng环境

Mac系统搭建java+selenium+testng环境: 1.   配置java环境,安装eclipse 2.  离线安装testng插件 3.  配置maven环境 4.  安装谷歌浏览器,下载对应浏览器版本的chromedriver 陆陆续续遇到的一些小问题记录: 1.  testng是使用离线方式安装的,离线包下载地址:http://dl.bintray.com/testng-team/testng-eclipse-release/ 下载完成后将其放到eclipse的dropins文件

java+Selenium+TestNg搭建自动化测试架构(1)实现代码和数据的分离

1.主要介绍介绍Java+Selenium+POM的自动化测试框架的搭建,第一个首先实现代码和账号URL等信息的分离.第二点支持跨浏览器,通过读取配置文件的方式实现. 1)将账号URL等信息添加在properties文件中然后读取 2)编写浏览器类通过去取配置文件实现浏览器的切换 3)测试浏览器类 项目结构: 1.新建一个文件夹将properties文件放在文件夹中内容如下: # browser switcher #browserName = FirefoxbrowserName = Chrom

Java&amp;Selenium&amp;TestNG&amp;ZTestReport 自动化测试并生成HTML自动化测试报告

一.摘要 本篇博文将介绍如何借助ZTestReport和HTML模版,生成HTML测试报告的ZTestReport 源码Clone地址为 https://github.com/zhangfei19841004/ztest,其中ZTestReport.java 和其template是我们需要的关键. 二.ZTestReport.java 根据我的需要,在源码基础上进行了稍微修改,其中几个注释的地方需要注意,将其集成进自己的自动化框架时需要做相应的修改 package util; import co

java+Selenium+TestNg搭建自动化测试架构(2)实现跨浏览器功能

1.切换浏览器类:其中包含了切换浏览器的方法,以及关闭浏览器,设置等待时间,以及重写的断言方法 package com.rrx.framework; import java.io.IOException;import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium

selenium第一课(selenium+java+testNG+maven)

selenium介绍和环境搭建 一.简单介绍 1.selenium:Selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE.Mozilla Firefox.Chrome等.支持自动录制动作和自动生成,Net.Java.Python等不同语言的测试脚本.Selenium 测试脚本可以在 Windows.Linux 和 Macintosh等多种平台上运行. 2.TestNG:TestNG是一个测试框架,其灵感来自JU

selenium+java+testNG+maven环境搭建

一.简单介绍 1.selenium: Selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE.Mozilla Firefox.Chrome等.支持自动录制动作和自动生成,Net.Java.Python等不同语言的测试脚本.Selenium 测试脚本可以在 Windows.Linux 和 Macintosh等多种平台上运行. 2.TestNG: TestNG是一个测试框架,其灵感来自JUnit和NUnit的,但引入

我的自动化测试历程(Selenium+TestNG+Java+ReportNG+Jenkins)

原地址:http://blog.csdn.net/shilinjie_8952/article/details/53380373?locationNum=11&fps=1 测试环境:Java+Selenium+TestNG,Jenkins持续集成. 测试代码 代码结构 采用页面对象模型(Page Object),减少UI修改后,对代码的影响. Java编写,采用TestNG测试框架. 先说点概念的: Selenium Selenium是一套完整的Web应用程序测试系统,它包含了测试的录制(Sel

Web automation test splinter and selenium usage

There is sth wrong with input on my ubuntu. So the first blog would be written in english about what i am doing during this weekend. i study python for a while about algorith and network and now  find some small project for practice. One of pratice i