Intellij IDEA maven配置执行自动化测试

版权声明:本文为博主原创文章,未经博主允许欢迎转载。 https://blog.csdn.net/wuzuyu365/article/details/78773818

从下面网址下载maven安装包: 

http://maven.apache.org/download.cgi ,当前最新的版本是3.5.2,就下载最新的,因为这个版本里面有surefire report



解压到一个地方:



进入 apache-maven-3.5.2/conf,编辑settings.xml:把mirrors部分替换为阿里云的maven镜像,会快点

 <mirrors>
		<mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <url>http://repo1.maven.org/maven2/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
        <mirror>
            <id>ibiblio</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
        </mirror>
        <mirror>
            <id>jboss-public-repository-group</id>
            <mirrorOf>central</mirrorOf>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
        </mirror>
        <mirror>
            <id>google-maven-central</id>
            <name>Google Maven Central</name>
            <url>https://maven-central.storage.googleapis.com
            </url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        
        <mirror>
            <id>maven.net.cn</id>
            <name>oneof the central mirrors in china</name>
            <url>http://maven.net.cn/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
     </mirrors>


添加M2_HOME到环境变量:


在IDEA中点击右上角的搜索图标,然后在Search Everywhere中输入maven,点击maven settings



设置Maven home directory等:



按Alt+F12,调出命令行终端,输入  

mvn -Dtest=Case* test


调用mvn实现对所有Case开头的测试用例进行测试,运行成功

D:\workspace\AppiumTest>mvn -Dtest=Case* test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AppiumTest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ AppiumTest ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.1:compile (default-compile) @ AppiumTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ AppiumTest ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\AppiumTest\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.1:testCompile (default-testCompile) @ AppiumTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ AppiumTest ---
[INFO] Surefire report directory: D:\workspace\AppiumTest\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running android.Case0003
08:29:17.381 [main] INFO android.Case0003 - ANDROID.CASE0003 Start =====>
十二月 11, 2017 8:29:45 上午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: OSS
08:29:45.555 [main] INFO android.Case0003 - photoView Start =====>
08:29:47.790 [main] INFO utils.ActionUtil - step1:模拟用户点击引导页跳过按钮...
08:29:49.791 [main] INFO utils.ActionUtil - step2:等待2秒
08:29:59.486 [main] ERROR utils.ScreenshotUtil - 测试失败,保存异常截图目录:D:\workspace\AppiumTest/Screenshot
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 42.483 sec <<< FAILURE!

Results :

Tests in error:
  photoView(android.Case0003)
  photoView(android.Case0003)

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 44.288 s
[INFO] Finished at: 2017-12-11T08:29:59+08:00
[INFO] Final Memory: 12M/307M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test (default-test) on project AppiumTest: There are test failures.
[ERROR]
[ERROR] Please refer to D:\workspace\AppiumTest\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

D:\workspace\AppiumTest>mvn -Dtest=Case* test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AppiumTest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ AppiumTest ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.1:compile (default-compile) @ AppiumTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ AppiumTest ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\AppiumTest\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.1:testCompile (default-testCompile) @ AppiumTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ AppiumTest ---
[INFO] Surefire report directory: D:\workspace\AppiumTest\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running android.Case0003
08:33:22.583 [main] INFO android.Case0003 - ANDROID.CASE0003 Start =====>
十二月 11, 2017 8:33:38 上午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: OSS
08:33:38.054 [main] INFO android.Case0003 - photoView Start =====>
08:33:39.747 [main] INFO utils.ActionUtil - step1:模拟用户点击引导页跳过按钮...
08:33:41.748 [main] INFO utils.ActionUtil - step2:等待2秒
08:33:47.144 [main] INFO utils.ActionUtil - step3:模拟用户发送账号..
08:33:49.145 [main] INFO utils.ActionUtil - step4:等待2秒
08:33:54.844 [main] INFO utils.ActionUtil - step5:模拟用户发送密码..
08:33:56.844 [main] INFO utils.ActionUtil - step6:等待2秒
08:33:57.457 [main] INFO utils.ActionUtil - step7:模拟用户点击手机用户登录..
08:34:12.458 [main] INFO utils.ActionUtil - step8:等待15秒
08:34:12.693 [main] INFO utils.ActionUtil - step9:点击图片模块
08:34:14.693 [main] INFO utils.ActionUtil - step10:等待2秒
08:34:14.921 [main] INFO utils.ActionUtil - step11:点击打开第一张图
08:34:19.921 [main] INFO utils.ActionUtil - step12:等待5秒
08:34:19.921 [main] INFO android.Case0003 - photoView Over =====>
08:34:22.146 [main] INFO android.Case0003 - ANDROID.CASE0003 Test Over =====>
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 59.71 sec

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:01 min
[INFO] Finished at: 2017-12-11T08:34:22+08:00
[INFO] Final Memory: 12M/307M
[INFO] ------------------------------------------------------------------------

D:\workspace\AppiumTest>


查看surefire-reports:


注意maven的jdk配置,不要用IDE自带的jdk,否则可能会出现一些错误



执行 mvn surefire-report:report,会在target/site下生成surefire-report.html:可以看到执行了2个用例,1个出错


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页