用Maven在Eclipse中配置Selenium WebDriver——方法1

1. 下载Maven并配置环境变量

设置变量名: M2_HOME=Maven安装目录

设置path: 把%M2_HOME%\bin添加到path变量中

2. 新建文件夹MavenProject

3. 打开cmd,进入到MavenProject文件夹,执行如下命令:

mvn archetype:generate

当回车至出现Define value for groupId: :时,输入com.projectA,回车

之后再输入artifactId,回车

当出现要求输入package时,输入任意packageName,回车

至提示说BUILD SUCCESS.

4. 进入MavenProject下的projectA文件夹,打开pom.xml

<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.projectA</groupId>
  <artifactId>packageName</artifactId>
  <version>1</version>
  <packaging>jar</packaging>

  <name>joy</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>GBK</project.build.sourceEncoding>
  </properties>
    <build>
        <finalName>packageName</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>GBK</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
  
   /*此处dependency根据项目不同配置,如下为Selenium配置*/
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.25.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.3.1</version> <scope>test</scope> </dependency> </dependencies> </project>

5. 在packageName文件夹下面,新建build.bat,编辑如下:

@echo off
setlocal
call mvn eclipse:clean
call mvn -npu eclipse:eclipse -Dwtpversion=1.0 -DdownloadSources=true
pause
endlocal

运行build.bat. 如果看到BUILD SUCCESS,表示项目建成功!

6. 打开Eclipse,右击选择import,导入所建的packageName下面的项目

至此,Selenium WebDriver就在Eclipse中配置成功了!

posted @ 2012-10-26 15:58  Joy0724  阅读(7579)  评论(0编辑  收藏  举报