4

I'm very new to Selenium. Below given is my first test script.

Question: Does it require selenium server to test a local website (which is hosted in the same machine as the test scripts being run).

Also tried executing the same script from Internet Explorer also, still getting the same. It just opens the browser and closes(because of finally block) it.

import org.openqa.selenium.chrome.ChromeDriver;
public class TestScript {
    /**
     * @param args
     * @throws InterruptedException 
     */
    public static void main(String[] args) {
        ChromeDriver driver = null;
        try 
        { 
            System.setProperty("webdriver.chrome.driver", "C:\\Users\\user1\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
            driver = new ChromeDriver();
            System.out.println("Opening the Browser");
            driver.get("http://localhsot:5080/myWebSite/8450191#");
            System.out.println("Open the Browser");
            System.out.println("");
            System.out.println("Title" +driver.getTitle());

        }
        catch (Exception ie)
        {
            ie.printStackTrace();
        }
        finally
        {
            System.out.println("Quitting the Browser");
            driver.close();
            driver.quit();
        }
    }

}

Exception: Below is the exception I am getting while executing from the Eclipse:

[2820:6204:36503609:ERROR:gpu_info_collector_win.cc(93)] Can't retrieve a valid WinSAT assessment.
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: '01hw535163', ip: '10.72.15.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_17'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:112)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:116)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:162)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:108)
    at com.seic.scripts.TestScript.main(TestScript.java:16)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: '01hw535163', ip: '10.72.15.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_17'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
    ... 6 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:37571/status] to be available after 20009 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
    ... 8 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
    ... 9 more
Caused by: java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:228)
    at java.util.concurrent.FutureTask.get(FutureTask.java:91)
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
    ... 10 more
Quitting the Browser
Exception in thread "Main Thread" java.lang.NullPointerException
    at com.scripts.TestScript.main(TestScript.java:31)

Chrome Version: 21.0.1171.0

OS: Windows 7 64 bit.

Selenium Web Driver version:2.39.0

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Naresh
  • 313
  • 1
  • 4
  • 8
  • have you tried the code using firefox? You can remove the System.setProperty() and call driver = new FirefoxDriver() directly. I also see that the spelling of local host is wrong in your code. – StrikerVillain Feb 10 '14 at 14:53

2 Answers2

3

You are getting a little confused about what you need to point Selenium to.

Here:

System.setProperty("webdriver.chrome.driver", "C:\\Users\\user1\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");

This setting, webdriver.chrome.driver is a setting that Selenium will read to find out where the ChromeDriver is located, not the actual Chrome installation.

https://code.google.com/p/selenium/wiki/ChromeDriver

You must download the ChromeDriver and where it is located should be what you pass in for the webdriver.chrome.driver property.

I imagine it's the same reason when you try with IE, it also requires a driver which I guess you don't have:

https://code.google.com/p/selenium/wiki/InternetExplorerDriver

In terms of whether you need a "server" -> for your tests, no, you are not running them remotely. Once you decide to run them remotely (i.e use the RemoteWebDriver instead of ChromeDriver) then you will need the Selenium server.

Arran
  • 24,648
  • 6
  • 68
  • 78
  • Thank you so much for your answer. I have dowloaded the ChromeDriver. Now i'm getting below exception. Please help.. – Naresh Feb 14 '14 at 06:21
  • Started ChromeDriver port=2275 version=14.0.836.0 .\test\automation\proxy_launcher.cc(89): error: Value of: app_launched Actual: 1 Expected: AUTOMATION_SUCCESS Which is: 0 Error while awaiting automation ping from browser process .\test\automation\proxy_launcher.cc(223): error: Value of: automation()->GetBrowserWindowCount(&window_count) Actual: false Expected: true .\test\automation\proxy_launcher.cc(244): error: Value of: browser_proxy.get() Actual: false Expected: true – Naresh Feb 14 '14 at 06:22
  • .\test\automation\proxy_launcher.cc(269): error: Value of: WaitForBrowserProcessToQuit( TestTimeouts::action_max_timeout_ms(), &exit_code) Actual: false Expected: true .\test\automation\proxy_launcher.cc(270): error: Value of: exit_code Actual: -1 Expected: 0 org.openqa.selenium.WebDriverException: Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using Chrome binary at: C:\Users\Bnaresh\AppData\Local\Google\Chrome\Application\chrome.exe (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 51.73 seconds – Naresh Feb 14 '14 at 06:23
  • Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12' System info: host: '01hw535163', ip: '10.72.15.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_17' Driver info: org.openqa.selenium.chrome.ChromeDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance – Naresh Feb 14 '14 at 06:23
  • Few things, a) what version of Chrome are you using? Re-download the ChromeDriver from here: http://chromedriver.storage.googleapis.com/index.html?path=2.9/ ...and edit your original post with the full stack trace details you are getting. – Arran Feb 14 '14 at 15:09
0

I would recommend instead of using System.setProperty() to put your drivers in the same folder and point to that folder in System Variables Path. Then you don't need to point to it at all in code and updating your driver won't require a code rewrite.

NaviSaysListen
  • 421
  • 4
  • 7