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

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";

Related

How to use Gecko driver in Dynamic Web Application

I am using Selenium to crawl a website using Java and Gecko driver. When I run the project on a local Tomcat v.9 server I am able to get the path of the Gecko driver directly. But what I want is to be able to run the Gecko exe from within the project folder. The image below shows the project hierarchy. I have added the exe in the "resources" folder under "src". How do I get the path of the driver to use it in my code?
Project hierarchy
Turns out it was pretty easy. I noticed that Catalina base has a similar directory to where WEB-INF is. So I did the following;
String catalinaBase= System.getProperty("catalina.base");
so the output is;
C:\Users\<user>\EE
Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Which means I would have to keep this Path up until the ".metadata" part (excluding it).
catalinaBase = catalinaBase.split(".metadata")[0];
I then excluded anything after the "EE Workspace" by splitting the Path String.
mainPath = catalinaBase + "\\Crawler\\src\\main\\webapp\\WEB-INF\\geckodriver.exe";
I concatenated the Path String I got from step no.2 and the rest of the path I know is the same.
System.setProperty("webdriver.gecko.driver",mainPath);
Last but not least I set the system property for gecko driver using the final Path String I created on step 3.
Bear in mind. I am unaware if this is working when you extract the WAR file. For a local Tomcat server it will work.
If someone can let me know if this works when a WAR is exported and
deployed on a real Tomcat server I would appreciate it.

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

How can I resolve Windows vs Linux properties file paths?

I have a java project on a Windows box which builds successfully and all tests pass locally. This project is then checked in and built with Jenkins on a Linux box.
The problem I am having is related to path issues in my properties file which is used for running tests. I point to a resources dir for part of a file path like this: "./src/test/resources".
I am trying to access two files which reside in the same directory. File1 is accessed successfully. Then File2 access is attempted, but it returns a file not found exception.
I've tried using an absolute path like this: "/code/myproject/main/src/test/resources/..." This again works on my local box, but not on Jenkins because Jenkins only knows about" "/myproject/main/src/test/resources/..."
How can this be resolved?
Today I learned Linux is case sensitive. The file name extension is upper case, but I was pointing to a lower case one.
Depending on your version of Windows... Windows 7 (don't know since when this was implemented) understand linux-style / separator just fine, as long as the whole path is relative.

Java App unexpected behavior when exported

I have a very strange problem, that I can't figure out, the thing is that my aplication runs perfectly on the IDE (Eclipse), but not when exported, when I run the jar (double click) the aplication start but some functionality is missing (loading from a template file, but this does not happend when loading from a normal file), when I try to run it from console (java - jar my.jar) in order to see any error message it turns out that my aplication works perfectly fine! :S ...
Some more info:
My app is running over windows 7
I start the task manager, and I noticed that when I start my aplication using double click its under the name java.exe *32, and when I do it from command line its under the name java.exe (without "*32"), as far as I know I programmed nothing related to a 32 or 64 bits functionallity.
"Solved"
Well I was not able to solve it the way I wanted, as far as I was able to find, i found that there were a problem between the 2 java versions I was running x32 & x64, I deleted the 32 bit version and it start working as a charm, but I'm still not sure about what happend, I give my thanks to #Sajal Dutta one of its comments help me to understand part of the problem, thanks to all of you anyway, I'll keep searching until I find the problem...
When you create a jar from Eclipse, your assets don't get copied over to jar or location is not preserved. Open the jar and check if you have your templates in the right location or you have it at all.
To have the exported jar include your assets/resources-
Right click on your project in Eclipse. Then New -> Source Folder.
Name the source folder anything. e.g. template_src.
Copy or drag the entire directory of your template to template_src. Then make the jar.
Since it works via the command line but not when double-clicking the jar, it is likely that the working directory is different (and that you're loading the template with a relative path). When you run an executable jar by double-clicking, on some operating systems, the working directory is the home directory whereas when you run from the command line, it's the directory you're currently in.
The "files" in the jar are not handled by File, but are resources;
URL url = getClass().getResource("...");
InputStream in = getClass().getResourceAsStream("...");
Then, the file paths inside a jar, or on a non-Windows platform are case-sensitive.
"Template_A.xml"
is not
"template_a.xml"
Also you might inspect the jar with 7zip or WinZip.

jTDS - No Suitable Driver Exception when running a Maven built project

We have a simple [spring-hibernate] application (console app) where in we have set the classpath in manifest file of the executable JAR file. And the app connects to the database using jTDS JDBC Driver, Everything works as expected on Windows machine and JDK 1.6, but on Linux, the app is unable to find the driver,
We are running the program using java -jar MainClassName.
Any suggestions why this might be happening is greatly appreciated.
This issue occurred because our jdbc.url had invalid url. This was because maven treats jdbc.url property as a special property and while profiling, instead of url defined in the filter.properties. And that is the reason "No Suitable Driver" exception. The question should have been more clear.
Anyways to fix that we had to rename jdbc.url properties to jdbc.url.somename. This fixed our issue with maven profiling. We also had a similar maven profiling issue for a property called "server.name" This filter property was also confusing maven profiling . We had to change the name of that property as well.
Thanks again Fernando.
Honestly it sounds like bad CLASSPATH. One thing I suggest to start debugging this problem is copying the jtds package to same path as your main packages/classes and see if it works. This way you can assure the Classpath manifest is or isn't the problem. The Spring/Hibernate relies on the lib directory, so it will always be on classpath because it's main structure. Use the lib directory also to test.
Hope this guidelines will help. Also send more information, like paths, classpath and manifest files.
It is a Maven bug
http://jira.codehaus.org/browse/MNG-3563

Categories

Resources