开发者

How do I run Selenium RC junit tests with Maven outside normal lifecycle?

开发者 https://www.devze.com 2023-03-26 12:31 出处:网络
I have a Maven project that is a set of a Selenium 2 tests that run using JUnit. In other words the only thing in the whole project is JUnit testcases and they all reside in the normal source director

I have a Maven project that is a set of a Selenium 2 tests that run using JUnit. In other words the only thing in the whole project is JUnit testcases and they all reside in the normal source directory i.e. src/main/java since they are the main source files in the project.

I want to be able to run these same tests using Maven, but since these tests are not actual unit tests or integration tests开发者_运维知识库 within the project (they are not testing themselves, they are testing a web app somewhere else), I don't want them to run during the normal build lifecycle. However I still would like to be able to define the test phases/goals within the POM file.

At this point I sort of understand the way the surefire plugin works, I just don't know how to de-couple the executions from the build. I would like all my new executions to be stand-alone so that I can simply run them by doing something like: mvn run-webtests and have the run-webtests phase be something completely different from the compile and package goals of my project.

So I guess I have two overall questions:

1.) Am I on the right track or is there some better way to think of this problem?

2.) What is it that I need to do next to make this work? Create a custom phase? Create a custom goal?

Sorry for asking such a seemingly basic question, but I wasn't able to find any examples of someone doing anything like this.


I think you're on the right track. It's just that Maven is unfortunately lacking in flexibility in some areas. Usually stuff can be made to fit in, but sometimes it can be a real pain. I think the simplest way to make this work is to use a different naming convention for your selenium tests and make sure those are excluded from your "normal" test runs. Then define a profile where you configure the surefire plugin to include your selenium tests and exclude the others. Then to run the selenium tests, you could just

mvn test -P selenium-tests

The only ways that you can set it up so that you could run mvn run-webtests, are

  1. Define a custom lifecycle where "run-webtests" is a phase in the lifecycle, or
  2. Write a plugin, though executing a plugin always has a ':' in it, so it would be more like mvn myplugin:run-webtests.

Those are both more work and harder to maintain than a simple profile in the pom.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号