Selenium Webdriver using Java(Eclipse IDE) - java

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

Related

chrome and firefox webdriver can not be found under src/main/resources?

I am using Netbeans 8.2 and i am trying to put the chrome and firefox webdrivers under src/main/resources, so that my teat can be run from any other PC, but when i set the system Property to point to src/main/resources/chrome/chromedriver, it gives me the error The driver executable does not exist: /src/main/resources/chromedriver.
But when i put the full path to the webdriver it woks fine like /home/username/NetBeansProjects/projectname/src/main/resources/chrome/chromedriver, the problem is that i want my tests to be runnable on different PCs without any changes, and the first part of the full path must be adjusted from PC to another, but the second part of the path /src/main/resources/chrome/chromedriver that is the one i want to use because that will make my tests runnable in different PCs without any changes in the system property, how can i do that and avoid the above error??
I have searched netbeans documentation but did not find any thing about that, i have also tried the solution in : How to start FireFoxDriver using Selenium 3.4.0 using Maven?
they are saying that it is important to have the drivers under /src/main/resources/ but they did not say any thing about how to avoid the above error
I have also tried How to get the path for .exe file which resides in src/main/resources
But I had the error utilities.Driver.Initialize(Driver.java:34)
thank you for your help in advance,
Try this when specifying your path for the driver
System.getProperty("user.dir")+"/src/main/resources/chromedriver/chromedriver.exe";

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 to get jenkins parameter in selenium / java on run time

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.

Run specific configurations

Hello i am facing a problem with the eclipse run configurations. I searched to find a simple example of how to solve my problem but i havent found any.
Well, my program has a file that it calls smth.model and if i want to run this model file to create an HTML file containing all the information of the model i needed to create a specific configuration that i am pointing to the specific model file and to specific HTML template (egl). Everything is working fine.
What i want now is lets say a user has never use the eclipse environment i want him to right click to his model file and there to have an option to run a specific configuration which i will call it for example "HTML run". When i right click to the model file i have the option Run as which directs me to the run configuration wizard. I dont want that i want the user when he choose the run as to show him my configuration rather the wizard.
Is it possible?Is there an example that will help me?
Thanks in advance!
Find any plug-ins for your specific need on Eclipse marketplace ( Help>>Eclipse Marketplace)
Your menu command can run EGL programatically, that is execute the EGL template that generates the HTML from Java. This example can guide you:
Epsilon Standalone.

Categories

Resources