您的位置:首页 > 编程语言 > Java开发

从零开始自动化测试框架设计:自动化测试环境搭建一:eclipse+svn+selenium+Junit+maven

2014-01-02 18:18 976 查看
本机环境:window7 旗舰版 Service Pack 1   64位操作系统

一、安装JDK:官网下载jdk1.6.0_17或以上版本,本人用的是jdk1.6.0_17.下载完后安装在C盘根目录C:\jdk1.6.0_17,配置系统环境变量:PATH: C:\jdk1.6.0_17\bin; CLASSPATH:  .;C:\jdk1.6.0_17\lib\dt.jar;C:\jdk1.6.0_17\lib\tools.jar;    cmd中运行java -version;javac  出现相关信息成功。

二、安装eclipse,下载Eclipse Kepler (4.3.1),安装

三、eclipse中安装svn和maven插件:

 

1.DownloadMaven 

http://maven.apache.org/download.html 

apache-maven-3.1.1-bin.tar.gz

http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.1.1-bin.tar.gz 

2.InstallMaven

(1) Unzip apache-maven-3.1.1-bin.tar.gz to E:\apache-maven-3.1.1 

(2) My Computer --> Property --> EnvironmentVariant--> System Variant-->

Add-->choosePath-->edit-->add the last: ;E:\apache-maven-3.1.1\bin-->OK-->OK-->OK 

(3) cmd--> mvn -v

Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:2

2+0800)

Maven home: E:\apache-maven-3.1.1

Java version: 1.6.0_17, vendor: Sun Microsystems Inc.

Java home: C:\jdk1.6.0_17\jre

Default locale: zh_CN, platform encoding: GBK

OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

3.Use Maven in Eclipse

(1) cmd-->mvn help:system (This willdownload many files to .m2 folder) 

(2) copy M3_HOME\conf\settings.xml to .m2/settings.xml 

(3) Start Eclipse-->Help-->Install NewSoftware...-->Add...-->

Name: m2e

Location: http://download.eclipse.org/technology/m2e/releases

-->OK-->Choose m2e- Maven Integration for Eclipse--->Next-->Next-->I accept the terms ofthe license agreement-->Finish-->Restart Now 

(4) Start Eclipse-->Help-->Install NewSoftware...-->Add...-->

Name: subclipse

Location: http://subclipse.tigris.org/update_1.8.x

-->ChooseSubclipse,SVNKit all-->Next-->Next-->I accept the terms of the licenseagreement-->Finish-->OK-->Restart Now 

(5) StartEclipse-->File-->New-->Other...-->Maven-->Maven Project-->Ifyou see Maven Project ,it is said that Maven is installed perfectly. 

(6) Use Maven outside of Eclipse,Windows --> Preferences--> Maven-->Installations--> Add...--> Next-->

E:\apache-maven-3.1.1-->OK-->OK

4. First Maven Project : hello-world-m2e (EclipseIDE)(Create a new Maven project)

(1) Start Eclipse-->File-->Other...-->Maven-->MavenProject-->Cancel Use default Workspace location-->Location:...\workspace\-->Next-->Next-->

org.apache.maven.archetypes: maven-archetype-quickstart-->

Next-->

Group Id:com.lijiming

Artifact Id:test

Version: 0.0.1-SNAPSHOT

Package:com.lijiming.test

 

-->Finish-->

(2) Run maven(mvn clean install)-->point pom.xml-->Run As-->Maven install-->

 

(3) We want to run mvn clean test -->point pom.xml-->Run As-->Run Configurations-->MavenBuild-->New-->

Name: test

Base directory:${workspace_loc:/test}

Goals: clean test

-->JRE-->InstalledJREs...-->Add...-->StandardVM-->Next-->Directory...-->C:\jdk1.6.0_17-->Finish-->

choose jdk1.6.0_17-->ok-->AlternateJRE: jdk1.6.0_31-->Apply-->Run

POM.xml文件内容:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.lijiming</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.37.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<!--<scope>test</scope> -->
</dependency>
<dependency>
<groupId>com.opera</groupId>
<artifactId>operadriver</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.opera</groupId>
<artifactId>operadriver</artifactId>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/*AppTest.java</include>
</includes>
<excludes>
<exclude>**/SampleTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>utf8</encoding>  
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- 配置site 的国际化,默认为en,更改为zh_CN,以及设置编码格式,默认utf-8 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<configuration>
<locales>zh_CN</locales>
<outputEncoding>utf-8</outputEncoding>
</configuration>
</plugin>
<!-- 
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<instrumentation>
<excludes></excludes>
</instrumentation>
</configuration>

</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.16</version>
<configuration>
<showSuccess>true</showSuccess>
</configuration>
</plugin>
</plugins>
</reporting>

</project>

如此,环境搭建完成,pom插件使用的都是最新版本。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐