Should selenium tests be kept in separate project - selenium

I have a Java web app (Maven) where I have some Selenium tests.The testing framework is Junit 4.x.
I'm also using Jenkins for CI. Right now all my tests (integration + selenium) are kept under the src/test folder of the project.(classic maven structure)
Due to the fact that Jenkins cannot run selenium tests (it is not configured to do this - I'm running on a linux machine without a graphical interface and the solutions under this circumstances seems a little clumsily, but I was thinking to run a selenium server so that I can run all these tests on a windows slave machine ) I have to manually "remove from execution the selenium tests", otherwise I'll have a lot of failed tests.
What I want to accomplish is a scenario where:
1.Commit to SVN
2.Jenkins creates a build
3.Run the tests and if there is no problem here move to next step, otherwise,stop
4.Deploy the app to an app server
5.Run the selenium tests against that deployment as a post build script in Jenkins.
In order to have this running do I have to extract the selenium tests to other project ? (in order to avoid Jenkins running this tests along with the other integration/unit tests)

As you are using Maven and you say kept under the src/test folder of the project sounds just Perfecto.
You havn't mentioned in your question why Jenkins cannot run selenium tests (it is not configured to do this). As later in your question you have mentioned Run the tests, presumming you are using TestNG it's just one step configuration for Jenkins to execute pom.xml of Maven which will inturn call the *testng.xml as mentioned below :
Ensure your Automated Test Suite executes properly as TestNG Suite and Maven Test.
Start Jenkins and browse to Manage Jenkins -> Configure System
Scroll Down to JDK -> JDK installations and ensure JAVA_HOME is set to C:\path\to\jdk1.8.0_144. Uncheck Install automatically
Scroll Down further to Maven -> Maven installations and provide Name as MAVEN_HOME & MAVEN_HOME as C:\path\to\apache-maven-3.3.3. Uncheck Install automatically
Scroll Down to JDK -> JDK installations and ensure Local Maven Repository is set to Default(~/.m2/repository).
Apply & Save
On Jenkins Dashboard, Create a New Item as Maven project.
Scroll Down to Build section and provide Root POM as absolute path of the pom.xml e.g. C:\Users\<user_name>\LearnAutmation\maven.jenkins\pom.xml
Set Goals and options to clean install
The final step would be to move the testng.xml within \ProjectWorkSpace\src\main\resources\testng.xml and your pom.xml you have to mention the location of testng.xml as below :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Build your project through Jenkins
As per your specific question In order to have this running do I have to extract the selenium tests to other project ? the answer is No.
Solution :
If you want to execute both the Suites Integration and Selenium, this setup is yours.
If you want to execute either of the Suites seperately, divide the Integration and Selenium suites in different TestNG Groups and turn ON & OFF the execution of the TestNG Groups.

Related

TestNG options not display in Run As in eclips even I added Test NG Jar

I have added testng-7.4.0.jar in my project as external jar but I am not getting TestNG as options to run the program under run as in eclipse . I can see TestNg jar present in Referenced Libraries
I tried this in both version of eclipse oxygen and Neon
enter image description here
Install Testng plugin from eclipse market place and restart the IDE. And when you run it for the first time configure the run with run configurations.
You must have TestNG.xml file configured to run in eclipse.

Selenium With Jenkins- Continuous Integration and Deployment

I am new to Jenkins.
I have automation scripts designed in Selenium as Maven Project.
I am able to trigger the build (execute POM.XML from GIT repository) from Jenkins.
My current Flow is as below.
Eclipse -> GIT ->Jenkins (trigger POM.xml available in GIT).
This approach is only for the test team wherein the push the selenium code changes to GIT branch and the code is tested by executing the POM.xml file.
I want to include the Deployment step (for DEV team) in this cycle. So that the automation script executes on the latest deployment. So the flow should look something like below.
Eclipse (Dev code) -> GIT repo -> Jenkins (build) -> Jenkins (deployment in test environment) -> Jenkins (trigger POM.xml available in GIT)
This way I would be able to execute my POM.xml on every latest build.
Any help will be appreciated.
If you are a novice with Jenkins, start playing with it and download and install localy (https://jenkins.io/download/).
It is not that much to it. Here are a few simple steps.
install Jenkins, and probably have Maven, Java,
setup path in Jenkins to Maven and Java in Global Tool Configuration section ins Jenkins settings,
create a new Freestyle job,
connect to git to the desired project on git,
In section, build triggers add maven command like in console (without mvn) as "Invoke top-level Maven targets" with commands from maven like install, test etc.
Start job.
Hope this helps.
Jenkin has integration with Maven via Maven Plugin so
If you're using a freestyle project just add the relevant build step in Jenkins GUI
If you're using Jenkins Pipeline - declare your test execution via Pipeline Maven Plugin like:
node{
stage ('Automation') {
git url: 'https://path/to/your/test/repo'
withMaven(
maven: 'maven-3',
mavenSettingsConfig: 'my-maven-settings') {
sh "mvn clean test"
}
}
}
Be aware that Jenkins might not have GUI therefore you may need to either use headless browsers versions or install extra software to simulate display like Xvfb

TestNG tests don't start in IntelliJ 13.1.4

I am unable to run or debug any TestNG tests in IntelliJ 13.1.4 on my Mac. When I try to run the test in debug mode, the IDE is hung starting the test - it never completes.
However, I can work with the same test using an older version of IntelliJ (12.1.7).
So far I've tried changing the JDK, replacing the testng jar in ../IntelliJ13/plugins/testng/lib, reimporting all maven dependencies, rebuilding IntelliJ indices.
Any ideas about how to fix my IntelliJ 13.1.4 environment?
I had similar issue - it turns out that I need to config my JVM options and connection used.
Update:
Sadly no, they are internal resources. But the algorithm should be the same (for your case):
goto Run/Debug Configuration
select TestNG
add your Name for the new configuration
select path to your test suite in Suite
in JDK settings tab, find VM options input your connection configs
run/debug for the Run/Debug Configuration - menu arrows
this worked for me.

Custom "Custom Run Configurations" in Intellj

I would like to create two custom run configuraion runners for testng. The first would be the default TestNG runner and the second would start jetty for integration tests before running them. I use the CMD+SHIFT+R and CMD+R a lot to run individual tests or a whole class, but it is hard to use this feature whe I cannot start my server before an integration test runs.
Is there a way to set up two configurations, so when I run a test in a package that matches something it uses one configuration, otherwise it will use another?
Maven profiles sounds like a good tool for the job, yes.
A simple and very common approach is to split your tests into unit tests (which are plain vanilla java code) and integration tests (which require other fancy stuff to run).
I see the maven-surefire-plugin supports TestNG, so you are fine there.
Now, to set up jetty, the second pom at this link describes how to start and stop jetty on the maven pre-integration-test and post-integration-test phases.
Then, after you bind the relevant tests to the maven integration-test phase, you can execute everything (start jetty -> integration tests -> stop jetty) via this command:
mvn verify
There are other ways to do it but this is a good starting point.
Good luck.

How to add task to run parallel selenium tests in build.gradle

In our project we are using gradle to nuke the DB and also using gradle to run the selenium test cases in different suites. I am trying to run selenium test casses parallely. How to add task for that.