Pages

Search This Blog

Tuesday, August 24, 2010

How to handle Selenium is already running on port 4444

When we run selenium RC test cases sometimes we faces this issue saying "java.net.BindException: Selenium is already running on port 4444. Or some other service is." When you check the port 4444 no service is running. We change the port and run the program even that too is not working.
In these cases we need to shutdown the selenium server on this port.
Use below command to shut down the server.

http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer

If selenium server is already running on port 4444 then it will shut down the server and says
OKOK
if selenium is not running on this port 4444 then by hitting above url will give you
"Unable to connect"
Now you can run your test cases i am sure will run smoothing.

How to get browser name, version and operating system detail in selenium

We can get the browser name, version and operating system name and version with the following commands in selenium RC.
Below code is tested in Mozilla Firefox
Browser Name

System.out.println(selenium.getEval("navigator.appCodeName;"));

Mozilla

Browser version

System.out.println(selenium.getEval("navigator.appVersion;"));

5.0 (Windows; en-US)

Browser and Operating system detail

System.out.println(selenium.getEval("navigator.userAgent;"));

Result.

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)

String browser = selenium.getEval("navigator.userAgent");
if (browser.contains("Firefox")  || browser.contains("Chrome")) {