Not able to open the chrome browser in android emulator

Hi ,

I am new to Appium, I am trying to launch the chrome browser in emulator. I am getting the below error in eclipse trace.
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.

Can you please help me out from this problem.?

Here my code,

package com.Appium;

import io.appium.java_client.AppiumDriver;

import java.net.MalformedURLException;
import java.net.URL;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;

public class AppiumBrowser {

private AppiumDriver driver;
public static String baseurl;

@BeforeTest
public void setup() throws MalformedURLException
{
	System.out.println("Hello");

// File appDir = new File (“C:\Users\E595016\Downloads\”);
// File app = new File (appDir,“com.android.chrome-39.0.2171.59-2171059-minAPI14.apk”);
// DesiredCapabilities capabilities = new DesiredCapabilities ();
// capabilities.setCapability(“browsername”,“chrome”);
// capabilities.setCapability(“device”,“android”);
// capabilities.setCapability(“devicename”,“10.0.0.3:5554”);
// capabilities.setCapability(“platformversion”,“4.2.2”);
// capabilities.setCapability(“platformname”,“Android”);
//// capabilities.setCapability(“app”,app.getAbsolutePath());
// capabilities.setCapability(“appPackage”,“com.android.chrome”);
// capabilities.setCapability(“appActivity”,“com.google.android.apps.chrome.document.ChromeLauncherActivity”);

}
@Test
public void LaunchWebsite () throws Exception {
	
	DesiredCapabilities cap = DesiredCapabilities.android();
	//Capabilities = DesiredCapabilities.android();
	//System.setProperty("webdriver.chrome.driver", "C:\\CloudATFTools\\selenium\\2.45\\drivers\\chromedriver_win32\\chromedriver.exe");
	System.setProperty("webdriver.chrome.driver", "C:\\Appium\\AppiumForWindows-1.3.4.1\\Appium\\node_modules\\appium\\build\\chromedriver\\windows\\chromedriver.exe");
	cap.setPlatform(Platform.WINDOWS);
	cap.setCapability("deviceName", "Android Emulator");
	cap.setCapability("platformName", "Android");
	cap.setCapability("browserName", "Chrome");
	
	AppiumDriver driver=new AppiumDriver(new URL("http://127.0.0.1:4725/wd/hub"), cap);
	Thread.sleep(10000);
	baseurl = "www.google.com";
	driver.get(baseurl+"/");
	//driver.findElement(By.className("android.widget.EditText")).click();
	// Wait for the search text box to be visible, then 
      // enter the search term "Kangaroo"
	driver.findElement(By.id("lst-ib")).sendKeys("Kangaroo");
    driver.findElement(By.className("lsb")).click();
      
      // Find the first entry for Kangaroo from WikiPedia
      // Look for the element that has "ikipedia" in the link text and click it
    driver.findElement(By.partialLinkText("ikipedia")).click();
      
      // The click should load the Wikipedia entry.  Wait for it to load
    driver.findElement(By.className("mw-wiki-logo"));
      // Verify that the page title contains Wikipedia
    //  verify.assertTrue(driver.getTitle().contains("Wikipedia"), "Check title of Wikipedia page");
	
	
}

}

Thanks,
Vital

Hi…

I have made changes to your piece of code try this it should run as expected.

private AndroidDriver driver;
public static String baseurl;

@BeforeTest
public void setup() throws MalformedURLException
{
System.out.println(“Hello”);
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setCapability(“browsername”,“chrome”);
capabilities.setCapability(“device”,“android”);
capabilities.setCapability(“devicename”,“10.0.0.3:5554”);
capabilities.setCapability(“platformversion”,“4.2.2”);
capabilities.setCapability(“platformname”,“Android”);
capabilities.setCapability(“appPackage”,“com.android.chrome”);
capabilities.setCapability(“appActivity”,“com.google.android.apps.chrome.Main”);
driver=new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
Thread.sleep(10000);
baseurl = “https://www.google.com”;
driver.get(baseurl);
}

Please correct the devicename and version as per the device you are using

1 Like

Hi,

Thanks it is working fine. but I am not able to find the web elements from chrome browser can you please help me how can we find the elements ?

You can use desktop chrome application and run chrome://inspect on it to inspect the mobile chrome elements

Using the same code, I am still not able to open Chrome.
When the code hits :

driver1=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
baseurl = "https://www.google.com";
driver1.get(baseurl); 

Error :

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. Details: The desiredCapabilities object was not valid for the following reason(s): deviceName can’t be blank. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 257 milliseconds
Build info: version: ‘2.48.2’, revision: ‘41bccdd10cf2c0560f637404c2d96164b67d9d67’, time: ‘2015-10-09 13:08:06’
System info: host: ‘Amits-MacBook-Pro.local’, ip: ‘192.168.1.136’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.12.1’, java.version: ‘1.8.0_101’
Driver info: io.appium.java_client.android.AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:161)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:170)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:82)
at com.gwynniebee.test.DynamicLinksTest.setup(DynamicLinksTest.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

@aamitarya

As per your error log your deviceName capability is blank please provide a valid deviceName and most probably it will work

:slight_smile:

@NishantSingh

Hi,

I’m just begnier for appium.
Below is my code to invoke chrome browser and launch a website. When i run this from robot framework, chrome browser launched with data:, as in the address bar and the browser gets closed and relaunced again and again. Can you please help me to overcome this issue

Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.0 deviceName=192.168.188.101:5555 appPackage=com.android.chrome appActivity=org.chromium.chrome.browser.ChromeTabbedActivity
Close All Applications

Video Recording - Chrome Error

Thanks,
Siva

Hi ,
I have same problem before .

I find that Appium chromedriver is too old , you can update your chromedriver in appium root dir /node_module/appium-chromedriver/chromedriver/… floder , and replace the chromedriver.exe files(windows) to lastest , https://chromedriver.storage.googleapis.com/index.html?path=2.29/

You can watch this video : https://youtu.be/sGuEgo2HIXw

Hi,

when i run my code everything opens fine but i cannot navigate to a url. I just get data:,

Any help would be great. I dont get any errors either when running this it just seems to do nothing when it cant navigate to the URL.

Running:
Eclipse
Windows 7
Using TestNG/Java

Thanks