driver.switchTo().window("WEBVIEW") not yet implemented when test switch to web app test

5,520 views
Skip to first unread message

xlzde...@gmail.com

unread,
May 19, 2014, 9:52:36 PM5/19/14
to appium-...@googlegroups.com
Hi All,
I tried to do the hybrid app automation in android 4.4.2 by using Appium. it works fine with native app, but could not work in hybrid one. I saw it supports the hybrid testing in Appium official website. But I created the java test case for hybrid app as below, it tell me the driver.switchTo().window("WEBVIEW") not yet implemented . 
Is there any mistake in my configuration or scripts? could someone help me figure it out? 


Thanks in advance.


---------------------
1. start the appium server in source 
>node . --no-reset

info: Welcome to Appium v1.0.0 (REV a0c777d96116a95007f2c3ea4ef332793b17153f)

info: Appium REST http interface listener started on 0.0.0.0:4723

info: socket.io started

info: Non-default server args: {"noReset":true}



2. run the following test case: 

....

caps.setCapability("browserName", "");

//caps.setCapability("device", "Android");

caps.setCapability("device", "selendroid");

caps.setCapability("app-activity", "com.alibaba.icbu.app.seller.activity.AppStart");

caps.setCapability("takesScreenshot", true);

caps.setCapability("version", "4.4.2");

caps.setCapability("device ID", "xxxxxx");

caps.setCapability("app", "/Users/test/mytest.apk");

WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), caps);

driver.switchTo().window("WEBVIEW");


------------

It returns following error:

org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 6 milliseconds

Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:08:38'

System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9', java.version: '1.7.0_51'

Driver info: driver.version: RemoteWebDriver

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:175)

at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:128)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:459)

at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:706)

at tests.selenium.AndroidTouch.test01(AndroidTouch.java:93)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)

at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)

at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)

at org.testng.TestRunner.privateRun(TestRunner.java:767)

at org.testng.TestRunner.run(TestRunner.java:617)

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:1224)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)

at org.testng.TestNG.run(TestNG.java:1057)

at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


xlzde...@gmail.com

unread,
May 19, 2014, 10:21:57 PM5/19/14
to appium-...@googlegroups.com
I saw there are many topics here which got the same issue ,I tried a lot of way which posts in other topics, such as run the Appium from source, config the "device" as selendroid. But none of them can figure out my issue. I am confused and a little hurry about it. 

Isaac Murchie

unread,
May 19, 2014, 10:29:41 PM5/19/14
to xlzde...@gmail.com, appium-...@googlegroups.com


On Mon, May 19, 2014 at 7:21 PM, <xlzde...@gmail.com> wrote:
I saw there are many topics here which got the same issue ,I tried a lot of way which posts in other topics, such as run the Appium from source, config the "device" as selendroid. But none of them can figure out my issue. I am confused and a little hurry about it. 

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

xlzde...@gmail.com

unread,
May 20, 2014, 12:16:14 AM5/20/14
to appium-...@googlegroups.com, xlzde...@gmail.com
thanks for quick reply.
I tried context, but it tell me there is no context method in webdriver. 
I use :
driver.switchTo().context("WEBVIEW");

------
also , I tried to use the AppiumDriver driver with following scripts with appium java client. It has driver.context() method(do not hava driver.switchTo().context() either ) . But when I run the test case , the return error: java.lang.NoClassDefFoundError: org/openqa/selenium/ContextAware




DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability("app-package", "com.test.tester");

caps.setCapability("platformVersion", "4.4.2");

caps.setCapability("device", "selendroid");

caps.setCapability("app-activity", "com.test.tester.activity");

caps.setCapability("takesScreenshot", true);

//caps.setCapability("version", "4.4.2");

caps.setCapability("device ID", "066e28a70b1e5a3b");

caps.setCapability("app", "/Users/test/tester.apk");

//driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), caps);

AppiumDriver driver = new AppiumDriver(new URL("http://localhost:4723/wd/hub"), caps);


xlzde...@gmail.com

unread,
May 20, 2014, 12:22:34 AM5/20/14
to appium-...@googlegroups.com, xlzde...@gmail.com
here is the context method that I used in AppiumDriver

driver.context("WEBVIEW");

I only can find this method in AppiumDriver , do not find the driver.switchTo().context(). 

Does driver.switchTo().context() method really exist in the WebDriver or AppiumDriver? why I could not find it? Is there any configuration issue from me?

I used Appium 1.0.0 , selenium server standalone 2.21.0 , OS: MAC IOS 10.9 , device: android 4.4.2

Isaac Murchie

unread,
May 20, 2014, 12:22:47 AM5/20/14
to xlzde...@gmail.com, appium-...@googlegroups.com
You need the Selenium driver as a dependency of the Appium one. However it deals with contexts, check the docs.


There is sample code here, too:



xlzde...@gmail.com

unread,
May 20, 2014, 1:59:59 AM5/20/14
to appium-...@googlegroups.com, xlzde...@gmail.com


import io.appium.java_client.AppiumDriver;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import org.openqa.selenium.By;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;

...

    public void setUp() throws Exception {

        DesiredCapabilities caps = new DesiredCapabilities();

        caps.setCapability(CapabilityType.BROWSER_NAME, "");

        caps.setCapability("automationName","Selendroid");

        caps.setCapability("platformName", "Android");

        caps.setCapability("app-package", "com.alibaba.icbu.app.seller");

        caps.setCapability("platformVersion", "4.4.2");

        caps.setCapability("app-activity", "com.alibaba.icbu.app.seller.activity.AppStart");

        caps.setCapability("version", "4.4.2");

        caps.setCapability("device ID", "066e28a70b115a3b");

        caps.setCapability("app", "/Users/lingzhixiang/codes/AliSupplier.apk");

xlzde...@gmail.com

unread,
May 20, 2014, 2:01:05 AM5/20/14
to appium-...@googlegroups.com, xlzde...@gmail.com

I following the way in sample-code with appium java client, but it still return  java.lang.NoClassDefFoundError: org/openqa/selenium/ContextAware

even when I do not use the context method. Could you help me take a look?

https://github.com/appium/appium/tree/master/sample-code/examples/java/junit


I have added the appium-client-1.0.jar and selenium-server-standalone-2.21.0.jar in my project library. 

Above are the test scripts

Thanks very much. 

gobi

unread,
May 20, 2014, 7:54:45 AM5/20/14
to appium-...@googlegroups.com, xlzde...@gmail.com
Hi,

Have you fixed the issue for switch to webview?

I am facing the same issue. Met with issue as same as yours, I cant found driver.switchTo().context() instead i get only driver.context() method.

while executing driver.context(driver.getContext()); with webview as frontmost, it fails with following exception

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.

Files used: java-client-driver-1.0.1.jar , selenium-server-standalone-2.41.0.jar, java-client-1.0, 2.0, 3.0.jar

Isaac Murchie

unread,
May 20, 2014, 11:59:22 AM5/20/14
to gobi, appium-...@googlegroups.com, xlzde...@gmail.com
The dependency for the Appium Java Client is not the selenium server but the Java client.



--

xlzde...@gmail.com

unread,
May 20, 2014, 10:19:57 PM5/20/14
to appium-...@googlegroups.com, gobi, xlzde...@gmail.com
Hi,
Thanks very much. T
he java.lang.NoClassDefFoundError has been fixed after I added the
selendroid-standalone-0.10.0-with-dependencies.jar

 I can pass the test case with context() method now. 
But another issue comes. 

I can get the WEBVIEW content name "WEBVIEW_1" with following codes:
        for (String contextName : contextNames) {

           System.out.println(contextName);

           if (contextName.contains("WEBVIEW")){

             driver.context(contextName);

           }

         }


but I could not see the element xpath under WEBVIEW by using android uiautomatorviewer. Is there any other tools can help me check the xpath?
Following are the pagesource of WebView that I got with driver.getPageSource()
...

<android.webkit.WebView index="3" text="" resource-id="" class="android.webkit.WebView" package="com.test.tester" content-desc="网页视图" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="true" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[0,210][1080,1776]"/>

...

</android.widget.FrameLayout></hierarchy>.



Thanks in advances.




  

Isaac Murchie

unread,
May 20, 2014, 10:59:36 PM5/20/14
to xlzde...@gmail.com, appium-...@googlegroups.com, gobi
I've only used the page source to get xpath. There may be other ways. 
--

xlzde...@gmail.com

unread,
May 21, 2014, 1:42:31 AM5/21/14
to appium-...@googlegroups.com, xlzde...@gmail.com, gobi
Thanks Murchie,
I can see the web view html source now in workaround way (by using Charles to capture the url and view the html source in chrome).
But when I run the test case for hybrid one, the action do not perform, and it returns the error in the Appium server as below. Could you help me take a look?

my scripts:

Set<String> contextNames = driver.getContextHandles();

         System.out.println(contextNames.size());

         for (String contextName : contextNames) {

           System.out.println(contextName);

           if (contextName.contains("WEBVIEW")){

             driver.context(contextName);

           }

         }

         Thread.sleep(5000);

         driver.findElement(By.xpath("//div[@class='item item-entrance']/h2[@class='grey-title mb20']")).click();

---------------

The script 

 driver.findElement(By.xpath("//div[@class='item item-entrance']/h2[@class='grey-title mb20']")).click();

do not work.

And here is the error message from Appium server log:

info: Available contexts: NATIVE_APP,WEBVIEW_1

info: Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_1"],"sessionId":"7dd9ea41-f47c-4466-a108-21ce90284ad1"}

GET /wd/hub/session/7dd9ea41-f47c-4466-a108-21ce90284ad1/contexts 200 50ms - 124b

debug: Appium request initiated at /wd/hub/session/7dd9ea41-f47c-4466-a108-21ce90284ad1/context

debug: Request received with params: {"name":"WEBVIEW_1"}

info: Getting a list of available webviews

debug: executing: "/Users/lin/tools/android-sdk-macosx/platform-tools/adb" -s 066e28s70b115a3b shell "cat /proc/net/unix"

info: ["webview_devtools_remote_20051"]

info: Available contexts: NATIVE_APP,WEBVIEW_1

info: Connecting to chrome-backed webview

info: Creating Chrome session

info: Ensuring Chromedriver exists

info: Killing any old chromedrivers, running: ps -e | grep /Users/lin/codes/appiumGit/appium/build/chromedriver/mac/chromedriver | grep -v grep |grep -e '--port=9515$' | awk '{ print $1 }' | xargs kill -15

info: Successfully cleaned up old chromedrivers

info: Spawning chromedriver with: /Users/lin/codes/appiumGit/appium/build/chromedriver/mac/chromedriver

info: [CHROMEDRIVER] Starting ChromeDriver (v2.10.267517) on port 9515

Only local connections are allowed.

info: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.test.tester","androidUseRunningApp":true,"androidDeviceSerial":"066e28s70b115a3b"}}}}

info: Could not connect yet; retrying

info: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage": "com.test.tester","androidUseRunningApp":true,"androidDeviceSerial":"066e28s70b115a3b"}}}}

info: Didn't get a new command in 60 secs, shutting down...

info: Shutting down appium session...

info: [ADB] Pressing the HOME button

debug: executing: "/Users/lingzhixiang/tools/android-sdk-macosx/platform-tools/adb" -s 066e28s70b115a3b shell "input keyevent 3"

info: Stopping logcat capture

debug: Logcat terminated with code null, signal SIGTERM

info: Cleaning up Chromedriver

info: Killing chromedriver

info: Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command. (Original error: socket hang up)","code":"ECONNRESET","origValue":"socket hang up"},"sessionId":"7dd9ea41-f47c-4466-a108-21ce90284ad1"}

POST /wd/hub/session/7dd9ea41-f47c-4466-a108-21ce90284ad1/context 500 60649ms - 270b

info: Chromedriver exited with code null

info: (killed by signal SIGTERM)

info: [BOOTSTRAP] [info] Got data from client: {"cmd":"shutdown"}

info: [BOOTSTRAP] [info] Got command of type SHUTDOWN

info: [BOOTSTRAP] [info] Returning result: {"value":"OK, shutting down","status":0}

info: [BOOTSTRAP] [info] Closed client connection




xlzde...@gmail.com

unread,
May 21, 2014, 3:15:13 AM5/21/14
to appium-...@googlegroups.com, xlzde...@gmail.com, gobi
Hi,
I just run the test case above again, but it is so weird that the script only can find one context right now, the "WEBVIEW" context could not be capture.
I have tried several times, and all of them return one context right now. Does it caused by the context() method not stable enough?

here is the lastest log from scripts.

info: Available contexts: NATIVE_APP

....

info: Responding to client with error: {"status":35,"value":{"message":"No such context found.","origValue":"Context 'WEBVIEW_1' does not exist"},"sessionId":"a94204f6-f217-47f4-a113-6105a9a86185"}


Isaac Murchie

unread,
May 21, 2014, 1:24:55 PM5/21/14
to xlzde...@gmail.com, appium-...@googlegroups.com, gobi
The context(name) method is stable. The first error is a problem with ChromeDriver. I'm concerned by the chromeOptions getting sent into it.

Can you post the desired capabilities you are using to set up the tests?


xlzde...@gmail.com

unread,
May 21, 2014, 9:23:51 PM5/21/14
to appium-...@googlegroups.com, xlzde...@gmail.com, gobi
Thanks Murchie.
Below are the  desired capabilities configuration in my test

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

        capabilities.setCapability("deviceName","066e28s70b115a3b");

        capabilities.setCapability("platformVersion", "4.4.2");

        capabilities.setCapability("platformName","Android");

        capabilities.setCapability("app", "/Users/lin/codes/tester.apk");

        capabilities.setCapability("app-package", "com.test.tester");

        capabilities.setCapability("app-activity", "com.test.tester.myActivity");

        AppiumDriver driver = new AppiumDriver(new URL("http://localhost:4723/wd/hub"), capabilities);


BTW, I started the Appium server from source (>node appium.js --no-reset).


xlzde...@gmail.com

unread,
May 21, 2014, 9:32:38 PM5/21/14
to appium-...@googlegroups.com, xlzde...@gmail.com, gobi
I did not add any additional configuration for chrome driver by myself , is there any configuration required for it either ??

Anson Liao

unread,
May 22, 2014, 1:31:24 AM5/22/14
to appium-...@googlegroups.com, xlzde...@gmail.com, gobi
 I download the Java-Client source code form GitHub,after import the maven project to Eclipse and gets error without nothing done.
I think maybe this cause the failure as this poster.


xlzde...@gmail.com

unread,
May 22, 2014, 1:55:15 AM5/22/14
to appium-...@googlegroups.com, xlzde...@gmail.com, gobi
Do you mean there is a bug in Appium 1.0.0 Java-Client for context() method?
It looks the code driver.context("WEBVIEW"); works for me.
But driver.findElement(By.xpath("//div[@class='item item-entrance']/h2[@class='grey-title mb20']")).click(); under the webview do not work.


naddy095

unread,
May 22, 2014, 2:47:33 AM5/22/14
to appium-...@googlegroups.com, xlzde...@gmail.com, gobi
Hi guys,

Sorry to interrupt.
I am using appium 0.18.2 server and when I use an emulator of Android 4.4.1 it gets the views as WebView and the NativeApp View, However, using the real device running Android 4.4.2 , the script says that only NativeApp view is present. Any suggestions on this?

P.S.- I don't want to upgrade to appium 1.0.0 as if now.

Regards.

Vinu Joseph

unread,
Jun 6, 2014, 11:13:20 AM6/6/14
to appium-...@googlegroups.com, xlzde...@gmail.com, mgobi...@gmail.com

Hi all,
I faced the same issue on Appium 1.1.0 and have found a simple solution to the problem.
It's nothing to do with the capabilities set.

Basically the port on which chromdriver is invoked is already in use and hence a new session is not created.

Solution --> Click on 'Android' Symbol > Advanced > Set 'Chrome Driver Port' on the bottom right corner to a different port. Eg:9123 and launch Appium server .
 The switch to webiew must be succesfull now.

Code for switching to web view :-

Set<String> contextNames = driver.getContextHandles();
   for (String contextName : contextNames) {
     System.out.println(contextName);
     if (contextName.contains("WEBVIEW")){
       driver.context(contextName);
     }
   }


Regards,
Vinu 

SOUVIK DUTTA

unread,
Jul 3, 2014, 6:27:46 AM7/3/14
to appium-...@googlegroups.com, xlzde...@gmail.com, mgobi...@gmail.com

Hi, I am new to appium and struggling to automate hybrid app (Cordova framework). I am able to launch the application with RemoteWenDriver but cant take it forward.

Here is the code snippet

 public static RemoteWebDriver driver =null;

 DesiredCapabilities capabilities = new DesiredCapabilities();
 capabilities.setCapability("deviceName","Android");
 capabilities.setCapability("device","Android");
 capabilities.setCapability("takesScreenshot","true");

 capabilities.setCapability("platformVersion","4.4.2");
 capabilities.setCapability("appPackage","uk.co.ee.myee");
 capabilities.setCapability("appActivity","uk.co.ee.myee.Launcher");
 capabilities.setCapability("udid","989fb005");
 driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

This is launching my application, but after that I am totally stuck. I have tried to use UIAutomator to inspect the elements but everything in the page is displayed as WebView. I am unable to understand how to take it forward, could you please send a sample code snippet.

If I am using AppiumDriver instead of Remote WebDriver, I get NoSuchMethod exception. Please let me know how to crack this.

Thanks
Souvik

Isaac Murchie

unread,
Jul 3, 2014, 1:28:10 PM7/3/14
to SOUVIK DUTTA, appium-...@googlegroups.com, xlzde...@gmail.com, gobi irtt
What is throwing the NoSuchMethod exception? 


--

SOUVIK DUTTA

unread,
Jul 7, 2014, 11:28:50 AM7/7/14
to appium-...@googlegroups.com, souvi...@gmail.com, xlzde...@gmail.com, mgobi...@gmail.com

I am getting NoSuchMethod exception while using AppiumDriver, but not when trying to launch the app with RemoteWebDriver
Reply all
Reply to author
Forward
0 new messages