I have a bunch of selenium webdriver tests split in different classes. I run these tests across a number of sites but I don't want to run them all on every site.
In the past I used msBuild and c# and wrote testng tests for software automation and I could add something like #Version1.5 after #Test then when I run my tests if the version in my properties file wasn't 5.1 it would skip that test.
Is something like this possible using maven and junit in Java?
Would JUnit Categories to the trick? Maven Surefire supports them but I am not sure how you would dynamically turn them on or off. You could definitely set up maven profiles to turn them on or off and then pass the appropriate profile as part of the maven command.
Related
I'm going to try to phrase this so that it is not an opinion based question. I have been doing some reading into other Maven questions and I do not think this is a duplicate, but if it is, please point me in the right direction.
I am writing a series of WebDriver JUnit tests to test the front end of my institution's web page. The tests are also configurable so as to be used both for regression testing as well as testing new features as they get added to the front end. Essentially module is executed based on the user's selected preferences which will create custom configuration options and custom scripts to execute the tests and then ultimately runs the scripts.
My project is using Maven to manage the dependencies, but was originally using Ant to execute the module and then generate the JUnit report. The question is if Maven would be able execute the project in a similar manner to Ant, as well as be able to generate the JUnit reports (or something equivalent).
Many thanks.
There is a maven-selenium-plugin that can be used to run Selenium tests and maven-failsafe-plugin can be used with it to generate your results. If you would like to see an example in use you could search for "stests" in Rice's pom.xml.
Configuration of properties in your tests can be handled in a variety of ways, I usually make use of System properties and/or property files. Dynamically configuring which tests to run I haven't found a solution I am happy with.
We have a custom framework built for Selenium with Java and we do not use Junit or TestNG and Maven. We are using to ant build our project. So I wanted to understand is it necessary to have Maven and Junit or TestNG to run sauce labs for mobile testing? We are planning to include Appium in our framework and would like explore way for executing our test on sauce lab.
If there are any alternate option we have then please point me to them.
Thanks,
Raghav
So, since you are using Ant, then the answer is No you do not need maven. Both Ant and Maven are project dependency management tools.
As far as the testing framework goes, you don't have to use any of them, but the reason you would want to use them, is for Pass/Fail recognition.
With a testing framework you can run each test individually and see a green pass, or red fail within your IDE. As well as suite management (See TestMethodRunner) It's possible that SauceLabs can detect these frameworks and detect failures as well, so I wouldn't see why you wouldn't use at least jUnit or TestNG.
Is it possible to automate Selendroid Tests for Android as well as Selenium for Web Browsers(together) through maven? Do i need to create seperate pom files for both or is it possible to use a single pom file to run both type of Tests?
Can i use any other framework to test Android and WebApps together through maven?
You can use a single pom file. Just configure plugins for each test type you want to use.
I want to do unit test on Spring Web Application using Spring Test. When I tried to learn in web got all the tutorials with maven. We are not using maven in our project. Is there any way to do this test without maven.
maven is a tool for build processes. You really don't have to use it.
What you need is to write tests with a testing framework, for exapmle junit
The dependencies you need (spring, junit) must be in your classpath. If you're not using maven then any other way you prefer.
You can use this question to run tests from command line if that's what you need.
To make it clear in other words - maven provides you with a build cycle that downloads your dependencies and put them in your classpath. This is something that you can do manually (configure your classpath and put needed jars in the classpath). The second thing maven gives you is the test life-cycle. But you don't have to use it and you can run unit-tests from command line according to the link I put in bullet 3 or running through the IDE. Most of eclipse and Intellij versions come with built-in support for running tests.
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
Define a custom lifecycle where "run-webtests" is a phase in the lifecycle, or
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.