Share
Go down
JeffNigl
Posts : 2
Join date : 2012-02-16

Script Execution using AndroidDriver

on Thu Feb 16, 2012 5:25 am
Hey Everyone,

I'm trying to setup a java-based mobile web driver using AndroidDriver, but I'm having trouble executing scripts against the Android SDK emulator. I've installed the android-server-2.13.0.apk on to the device and I'm using Selenium 2.13.0 (I'm not sure if the versions have to match or not, but they do). I'm able to navigate to any web page, but am not able to run javascript scripts using the JavascriptExecutor. When it gets to the line that attempts to run the script, WebDriver on the emulator closes (or dies) and an exception is thrown. You can see the code (yes, the url in the code looks funny, but it wouldn't let me add this post without it since I'm new) and exception below. When I switch the web driver to FirefoxDriver, or InternetExplorerDriver, it works just fine.

Thanks in advance,

public class Testing {
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
WebDriver driver = new AndroidDriver(caps);
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
driver.manage().timeouts().setScriptTimeout(10000, TimeUnit.MILLISECONDS);
driver.navigate().to("http" + "://" + "google.com");
Thread.sleep(15000);
Object result = ((JavascriptExecutor) driver).executeScript("return window.location.href;");
System.out.println("result: " + result.toString());
driver.quit();
}
}


Exception in thread "main" org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died.
Build info: version: '2.13.0', revision: '14793', time: '2011-11-18 13:17:03'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_26'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:332)
at Testing.main(Testing.java:25)
Caused by: org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:101)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:298)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:410)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:371)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:398)
... 2 more
JeffNigl
Posts : 2
Join date : 2012-02-16

Re: Script Execution using AndroidDriver

on Fri Feb 17, 2012 4:11 am
Apparently, this is a known bug for android 2. Everything works fine when I switched to android 4.

Thanks
Back to top
Permissions in this forum:
You cannot reply to topics in this forum