Selenium WebDriver - Manual installation of Java client driver (without Maven/IDE)

541 views
Skip to first unread message

SmashManiac

unread,
May 22, 2012, 5:05:43 PM5/22/12
to seleniu...@googlegroups.com
Hello everyone, I'm new to Selenium and I'm trying to set up the Selenium WebDriver for Java. Right now I'm trying to make this example compile:

The problem is that javac can't find the libraries the example is trying to import because my current setup is incorrect, but I don't know how to fix it. The only reference I've seen so far about doing so is explained here:

However, I've never used Maven before and I don't like using IDEs either. Also, it's possible that I might not be able to use those tools on some test environments anyway. Therefore, I was wondering if someone could give me instructions on how to set up the whole thing manually instead and which options I should feed javac with.

Thanks a lot!

Lukus

unread,
May 23, 2012, 7:17:57 PM5/23/12
to seleniu...@googlegroups.com
I also do not use maven nor and IDE and run all tests on command line using the standalone jar.  Class paths are probably the biggest hurdle, as you will think it's right, but then it fails.  Here's my approach:

- Download selenium-server-standalone-2.21.0.jar to folder, let's say it is on the path c:\selenium.
- Open command prompt and cd to the selenium directory.
- Be sure your test file with main class is in this directory as well, let's say it's called Selenium2Example.java like the one in the link you pointed to.
- Compile like so: javac -classpath .;selenium-server-standalone-2.21.0.jar Selenium2Example.java  (notice the '.' before the semi-colon, it's necessary, use colons if on linux or mac)
- If no compile errors, then run like so: javac -classpath .;selenium-server-standalone-2.21.0.jar Selenium2Example

Based on the test file you referred, you'll be testing FirefoxDriver.  That sample doesn't include the fact that it will check a default location for the FF binary.  If it can't find it, it will fail on run.  You may need to set your path to the binary in the file first like so System.setProperty("webdriver.firefox.bin","c:\\progra~2\\mozilla\\firefox\\firefox.exe");  

Also, I would comment out the findElement and related until you could at least compile, start the WebDriver, get() the url, and quit().  Once you know you can do those, then move to the others.

Hope that helps.

Lukus

unread,
May 23, 2012, 7:20:33 PM5/23/12
to seleniu...@googlegroups.com
Correction, change 'javac' to 'java' on the line where you are running it.  copied and pasted and forgot to remove that. 

Krishnan Mahadevan

unread,
May 24, 2012, 1:23:03 AM5/24/12
to seleniu...@googlegroups.com
I understand the reason why people may not want to make use of build tools such as "maven", but not wanting to use an IDE ? Beats me..!

I thought that with IDEs one needn't memorize the class names and their packages etc., and can just concentrate on writing the code that is needed ! perhaps am too lazy which is why I rely on the intellisense of the IDE all the time :)


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


On Thu, May 24, 2012 at 4:50 AM, Lukus <luke....@gmail.com> wrote:
Correction, change 'javac' to 'java' on the line where you are running it.  copied and pasted and forgot to remove that. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/mchL_gd6xAkJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

SmashManiac

unread,
May 25, 2012, 2:03:19 PM5/25/12
to seleniu...@googlegroups.com
Thank you very much Lukus, I got the example to work perfectly! I didn't realize that all the necessary classes were in the JAR server file!

Only change I had to do was to comment out the "package" line from the example, otherwise I was forced to move the CLASS files into the org/openqa/selenium/example subdirectory and launch org.openqa.selenium.example.Selenium2Example instead.

@Krishnan: Personally I find that managing projects with IDEs way too complex compared to their advantages, even on large-scale projects. As for autocompletion, it is indeed pretty useful when it works, but I usually prefer to access the full API documentation directly anyway.

David

unread,
May 25, 2012, 3:03:33 PM5/25/12
to Selenium Users
Also, regarding the IDEs approach:

for simple quick tests and trials (exploratory stuff), an IDE + usual
right code, compile, run, set breakpoints to debug, and/or watch
exceptions occur, is too repetitive.

much easier to do that with something like Beanshell for a Java(like)
interpreter shell. then switch back to IDE once you need to do full
blown programming again and formalize your tests.

On May 23, 10:23 pm, Krishnan Mahadevan
Reply all
Reply to author
Forward
0 new messages