`
shishi11
  • 浏览: 115697 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

selenium在m2eclipse下的集成测试

阅读更多

前两天开始了学习,但后来因为领导要我干别的,有一段时间没看了,这两天紧不紧慢不慢的,又看上了持续集成。

上次试验收在ff下的selenium IDE的使用,看到了好处,但用于实际工作中的集成测试,特别是自动化妆持续集成,还是需要代码一级的。于是开始找资料,搭环境了。

我的环境是m2eclipse,因为要持续集成,所以要mavn2的支持,selenium的例子倒是好找,到处都是,于是我用webapp的模式以maven2先搭起架子。再指定test的目录以输出目录,因为是测试类,所以要发到test-classes里,而不要混到原始代码中。由此还想到,单元测试与功能测试的区别,单元测试是可以由代码员自己来开发的,代到cvs中,而功能测试或集成测试应该由测试员来开发,放到持续集成服务器上,进行功能测试。

按网上的例子建的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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>selenium</groupId>
    <artifactId>selenium</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>selenium Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium.client-drivers</groupId>
            <artifactId>selenium-java-client-driver</artifactId>
            <version>1.0-beta-2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>selenium</finalName>
        <defaultGoal>package</defaultGoal>
        <plugins>
        <!-- compiler插件,设定JDK版本及编码 -->
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!-- tomcat在集成测试时启动,在完成后结束 -->
            <!--<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <url>http://localhost:8080/manager
                    </url>
                    <server>myserver</server>
                </configuration>
                <executions>
                    <execution>
                        <id>tomcat_start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                             在没有tomcat的情况下,以RUN方式启动自带的TOMCAT
                            <goal>run</goal>
                             goal>undeploy</goal>
                            <goal>deploy-only</goal
                        </goals>
                    </execution>
                    <execution>
                        <id>tomcat_stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            --><!-- selenium也需要单独启动 -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>selenium-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start-server</goal>
                        </goals>
                        <configuration>
                            <background>true</background>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop-server</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                            <skip>true</skip>
                        </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                           
                            <skip>false</skip>
                            <includes>
                                <include>**/*.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>cn_repository</id>
            <name>cn_repository</name>
            <url>http://maven.net.cn/content/groups/public
            </url>
        </repository>
    </repositories>
    <reporting>
        <outputDirectory>${basedir}/target/site/maven</outputDirectory>
    <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-project-info-reports-plugin</artifactId>
         <version>2.0.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.4.2</version>
        <configuration>
           <outputDirectory>${basedir}/target/newsite</outputDirectory>
        </configuration>
      </plugin>
      <!--plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>2.0-beta-6</version>
        <configuration>
           <outputDirectory>${basedir}/target/newsite</outputDirectory>
        </configuration>
      </plugin-->
    </plugins>
      </reporting>
</project>

 

 

由于是测google的例子,所以也没有启动tomcat,如果是自己的应用,则可以先启动tomcat之后,再测,如果是验收测试,则可以在演示服务器上跑,也不用启动内部的tomcat。

 

另,selenium的程序比较新,maven2的仓库里下不到,自己install了一个

mvn install:install-file -Dfile=selenium-java-client-driver.jar -DgroupId=org.seleniumhq.selenium.client-drivers -DartifactId=selenium-java-client-driver -Dversion=1.0-beta-2 -DgeneratePom=true -Dpackaging=jar

这里就是我老出错的地方,pom.xml中必须依赖这个类,后面的test才能运行,要不就说classnotfound。

结果如下:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building selenium Maven Webapp
[INFO]
[INFO] Id: selenium:selenium:war:0.0.1-SNAPSHOT
[INFO] task-segment: [integration-test]
[INFO] ------------------------------------------------------------------------
[INFO] Attempting to resolve a version for plugin: org.codehaus.mojo:selenium-maven-plugin using meta-version: LATEST
[INFO] Using version: 1.0-rc-1 of plugin: org.codehaus.mojo:selenium-maven-plugin
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] No sources to compile
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Tests are skipped.
[INFO] [war:war]
[INFO] Packaging webapp
[INFO] Assembling webapp[selenium] in [C:\eclipse\workspace\selenium\selenium\target\selenium]
[INFO] Processing war project
[INFO] Webapp assembled in[31 msecs]
[INFO] Building war: C:\eclipse\workspace\selenium\selenium\target\selenium.war
[INFO] [selenium:start-server]
Launching Selenium Server
Waiting for Selenium Server...
[INFO] User extensions: C:\eclipse\workspace\selenium\selenium\target\selenium\user-extensions.js
log4j:WARN No appenders could be found for logger (org.openqa.selenium.server.SeleniumServer).
log4j:WARN Please initialize the log4j system properly.
Selenium Server started
[INFO] [surefire:test]
[INFO] Surefire report directory: C:\eclipse\workspace\selenium\selenium\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.example.tests.test
init selenium
start successfully
enter testGoogleTestSearch
open the google.com
input type condition
begin search
finsh assert
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.688 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16 seconds
[INFO] Finished at: Thu May 07 08:17:15 CST 2009
[INFO] Final Memory: 4M/13M
[INFO] ------------------------------------------------------------------------

附件中是原来的测试文件,POM.xml的部分是参看的mojo中selenium-maven-plugin的说明(with surefire)

对于maven的集成测试还刚明白一点儿。

 

分享到:
评论

相关推荐

    Selenium终极自动化测试环境搭建(一):Selenium+Eclipse+Junit+TestNG.docx

    Selenium 终极自动化测试环境搭建需要完成以上七个步骤,包括安装 JDK、下载 Eclipse 和 Selenium 相关组件、下载 Firefox、安装插件、启动 SeleniumRC 服务器和在 Eclipse 中执行 Selenium 的 Java 实例。

    零成本实现Web功能自动化测试--基于Eclipse+Python+Selenium自动化测试技术分享

    零成本实现Web功能自动化测试 基于Eclipse+Python+Selenium自动化测试技术

    Selenium+Eclipse+Junit+TestNG.docx

    创建一个新的 Java 项目,在 Eclipse 中新建一个 Java 项目,添加 Junit 4 和 Selenium 相关的 Jar 包,然后创建一个新的包和类,以便编写自动化测试脚本。 相关知识点 * Selenium 自动化测试框架的搭建 * JDK 的...

    终极自动化测试环境搭建:Selenium+Eclipse+Junit+TestNG+Python

    终极自动化测试环境搭建:Selenium+Eclipse+Junit+TestNG+Python 本文旨在指导读者搭建一个终极自动化测试环境,利用 Selenium+Eclipse+Junit+TestNG+Python 实现自动化测试。下面是详细的搭建过程: 一、安装 JDK...

    selenium+eclipse开发需要的所有jar包

    在这里,我们将探讨如何在Eclipse中使用Selenium进行Web自动化测试,并关注与"43.3版本Firefox"相关的配置。 首先,标题中的“selenium+eclipse开发需要的所有jar包”指的是Selenium WebDriver与Eclipse开发环境所...

    selenium 深入浅出 软件测试 集成测试

    ### Selenium深入浅出:软件测试与集成测试 #### Selenium—Web界面测试工具 Selenium是一个强大的开源工具套件,主要用于自动化Web应用的测试。它支持多种编程语言,如Java、Python、C#等,以及各种现代浏览器。...

    Selenium终极自动化测试环境搭建【Eclipse+Junit+TestNG+Python】

    在搭建 Selenium 终极自动化测试环境时,需要安装 JDK、Eclipse、Junit、TestNG 和 Python 等软件。其中,JDK 是 Java 开发工具包,Eclipse 是一个集成开发环境,Junit 和 TestNG 是测试框架,Python 是一种流行的...

    Selenium:Selenium测试框架集成.zip

    史上最全软件测试技术全套教程,包括: Postman Selenium 单元测试 压力测试 回归测试 安全测试 性能测试 测试工具 集成测试 等流行技术的系列教程

    eclipse下Selenium2.0+-Maven+TestNG环境搭建

    本文将详细介绍如何在 Eclipse IDE 中搭建基于 Selenium 2.17.0、Maven 3.0.4 和 TestNG 6.3.1 的自动化测试环境。 #### 环境准备 在开始搭建之前,请确保已完成了以下准备工作: 1. **Java 开发工具包 (JDK) 安装...

    selenium2 python自动化测试 PDF学习

    在编写自动化测试脚本时,Python可以非常方便地与其他库、框架进行集成,极大地简化了测试代码的编写和维护工作。Python的标准库已经足够强大,再结合一些专门针对测试的第三方库,比如unittest和nose,可以用来组织...

    selenium在eclipse上运行的jar包

    在Eclipse这样的集成开发环境中运行Selenium测试,通常需要添加相应的库依赖。** 这个名为“selenium3.4JAR包”的压缩文件包含了Selenium的Java兼容包和Server-Standalone包。这两个组件在Selenium的Java测试项目中...

    testng selenium eclipse

    TestNG、Selenium和Eclipse是软件测试领域中三个非常重要的工具,它们共同构成了一个强大的自动化测试框架...通过熟悉和掌握这三个工具,无论是初级测试工程师还是经验丰富的开发者,都能在测试工作中获得显著的优势。

Global site tag (gtag.js) - Google Analytics