How to get jenkins parameter in selenium / java on run time - java

I am working on a automation project which uses selenium with webdriver (Java) to record the steps and maven + jenkins to execute the scripts .
Script has been completed and working fine. Issue is I have to deploy it over the 3 environments QAMachine, Staging.
We initiate the build link like http://testsite.com:8080/jenkins/job/FaizanTest/ via our testing portal
What I want is to enhance.
so that I can access the link (modified link lets say http://testsite.com:8080/jenkins/job/FaizanTest?env=qa OR env=stag) and the build auto executed on the specified machine.
I know this is called parametrized build and I know how to put parameter on jenkins but the issue is how I find in selenium/java which uses property file to execute URL (environment)

If you user parametrized build you can use build step "Execute Shell":
echo 'env='${ENVIRONMENT} > suite.properties
where,
ENVIRONMENT is Jenkins variable which was defined in parameters,
env.properties properties file in your framework.
This script will write this variable to properties file, so you will be able to read it from file in your selenium/java framework.

Related

Web Application Code Coverage using JaCoCo

I have been assigned a task where I want to generate the code coverage report of web application execution (development code) when a manual or automation test script is executed, I have to identify (using any tool) what percent of development code has been executed against that particular action.
After doing my RnD, I found that this can be achieved using JaCoCo (Java Code Coverage). JaCoCo uses class file instrumentation to record execution coverage data. Class files are instrumented on-the-fly using a Java agent. I have used the java command in the java agent flag.
Points to Mention
Application front-end is Angular, backend is Java/BPM and is deployed on JBoss Server.
Backend code contain multiple modules.
Testcase are executed from my local machines, that hits the application deployed on the server.
APPROACH
I have added the below mentioned command in /app/JBoss-EAP-7.2/bin/standalone.sh file because this is the file that is executed when the server starts.
Javaagent:<path_to>/jacocoagent.jar=classdumpdir=<path_to>/jacocoClassDump, destfile=<path_to>/jacocoST.exec
Restart JBoss server. [After this jacocoST.exec file is created in the respective folder]
Run automated testcase using maven on my local machine.
Stop the JBoss server. [so that jacocoST.exec file is updated]
Run the command:
java -jar <path_to>/jacococli.jar report <path_to>/jacoco-it.exec -- classfiles=<path_to>/jacocoClassDump --html /app/Jacocoreport --xml cov.xml
The above steps show error Can't add different class with same name
Why do I get the error "Can't add different class with same name"?
The FAQ that I’ve come across from JaCoCo Official Documentation
For coverage report generation all classes within a group must have unique names. You get this error during report generation if JaCoCo is supplied with multiple different class files with the same name. To fix this remove those duplicate classes or create separate reports or report groups for each version.
The main problem is the error which I am getting. According to FAQ, they suggest to delete duplicate files but there are no duplicate class files (each class files has unique number at the end).If somebody has done such work so please guide me, Are the steps which I followed right?

Selenium Webdriver using Java(Eclipse IDE)

I have automated a web app using seleinium webdriver in Eclipse IDE. I am picking the login credential(other dynamic parameters) from one properties file.The automation is working perfectly fine. Now if I want to run the automation in a different machine with different credential.
Could anyone please guide me on how to create the jar file and run it in a different machine.I should be able to change the parameter as per my requirement.
Instead of property file You can keep Your parameters in testNG xml
file. Even for each and every test also you can configure different
parameters. Refer : Testng Parameter help document
And For executing in remote machine You have to look at 'Remote
webdriver' in selenium. Selenium Remote Webdriver help document
you can read the property file using the below command
String propertyFileLocation = System.getProperty("property.file.location");
pass the value for "property.file.location" from the command prompt.
You can call your jar file as
java -cp jarfilelocation -Dproperty.file.location= classlocation
Right click on the project and export it as jar file.
Hope this helps

Jenkins & Java : How to specify input file location

I have a java project which compares data in two excel files and displays the output. IN my eclipse project i created a folder data and in the code I wrote code read from root/data and it works fine as well. But my manager asked me to move this job to Jenkins. So my question is how do i specify the input folder path in Jenkins , Should it be the same server where Jenkins is installed or Jenkins can read data from another location in another server ?
By default, Jenkins will work on the Job's workspace location, if you provide a path in the job (be it via Parameter or Env. variable etc), it will be relative to that location.
However, you can specify an absolute path for anywhere on the Jenkins Server, which will also work.
If you wish to read data from another server, you will need to make it available to the job's runtime/access level.
One example would be to put this file on IIS or Network Share or other form of sharing, and download it during your chef job into the workspace.
Powershell example for downloading a file from IIS site:
$source = "http://my-web-server-ip/download/mycsvfile.csv"
$destination = "c:\my-jenkins-job-workspace\mycsvfile.csv"
Invoke-WebRequest $source -OutFile $destination
Please consider the above is just a basic implementation of this, and this can be accomplish in a number of ways - which some may be better than others.

How to run TestNG file which is hosted on different server using MAVEN

I want my POM XML to choose TestNG XML which is hosted on different server .
Basically I have integrated my project with jenkins. But i want to change the groupings ( BVT, Sanity , Regression) very frequently , this requires the checkin-checkout of TestNG XML file.
Instead I want host XML file on some server and Maven/Projects reads server .
Thanks and Regards
Sudarshan
You can use beanshell to make groups configurable - details here
Make the changes in your single testng xml file and then run mvn test with -Dgroups=whatever
You can create different jobs for different groups.

How can I checkout different Subversion tags/branches of the same Java project while using Ant/Jenkins?

Here is my dev configuration:
Under Subversion,
- I have my project_X/trunk (with my latest dev),
- I have my project_X/tags (with different releases),
- I am thinking of adding a branch folder.
I am using Jenkins to build my project_X/trunk using an Ant script.
My Ant script does many things, it checks-out, compiles, creates the documentation with graphs, runs the unit tests, performs pmd, creates a jar and zips everything.
I would like to be able to use my Ant script on tags or branches (as well as the trunk) for the same Project.
What's the easiest way to do this:
I think it is just a question of checking out the right path to the Subversion repository, Right?
- If I am correct, I should make the path to the Subversion dynamic.
- In my Ant script should my Subversion path be a variable?
- How do I pass the path value from Jenkins' interface?
- Is there a plugin that lets me pass the Subversion path value from Jenkins to the Ant script?
- Or should I just create a new job in Jenkins (with the same script but different path)?
Hope
Thanks in advance for your help,
Best regards,
You should parameterize your build by tag/branch name. The easiest way to do it is to add a parameter (say, SVN_BRANCH_DIR) to your Jenkins job which will have values such as trunk, branches/branch1, tags/sometag.
Now, if you use Jenkins ANT build step that parameter will be passed automatically to your ANT script as a property (by way of ANT -D option). So you can use ${SVN_BRANCH_DIR} in it (e.g. svn://myserver/myrepo/${SVN_BRANCH_DIR}).
Jenkins Subversion Plugin provides a "List subversion tags (and more)" project parameter since Version 1.24 (Mar 22, 2011).
Literally,
When used, this parameter will display a field at build-time so that the user is able to select a Subversion tag from which to create the working copy for this project.
Once the two fields Name and Repository URL are set, you must (1) ensure the job uses Subversion and (2) set the Repository URL field of Subversion by concatenating the two fields of this parameter. For instance, if Name is set to SVN_TAG and Repository URL is set to https://svn.jenkins-ci.org/tags, then Subversion's Repository URL must be set to https://svn.jenkins-ci.org/tags/$SVN_TAG.
Notice that you can set the Repository URL field to a Subversion repository root rather than just pointing to a tags dir (ie, you can set it to https://svn.jenkins-ci.org rather than https://svn.jenkins-ci.org/tags). In that case, if this repository root contains the trunk, branches and tags folders, then the dropdown will allow the user to pick the trunk, or a branch, or a tag.
For unattended integration builds you could use the default "trunk" parameter value.
I hope this helps.

Categories

Resources