Chrome Remote Debugging - how to inspect elements in hybrid app (webview) - android

I am trying to automate Gmail app for Android. In the "Compose" page, the part of the body of the message is a webview context. Using uiautomatorviewer i managed to retrieve the locator of the "body" element, but sending text to it - fails. Trying to switch context to "WEBVIEW" (i am using Appium) also fails. I wish to inspect elements in this page using chrome remote debugging. On my computer, i navigated to chrome://inspect/#devices and i launched the application on the android emulator. It looks alright.
But when i try to inspect elements, i see none.
What am i missing? (i made sure the to enable debugging and become a developer...)

To enable WebView debugging setWebContentsDebuggingEnabled should be set on the WebView class. You need to make this change in your app code and rebuild it.
Following these instructions was good enough for me

Related

How to change Flutter DevTools default browser?

Can I change the default browser that is used for Flutter DevTools? Is it compatible with Firefox or other browser? In my case, I don't like Chrome very much, i's a little slow and heavy compared to firefox and others. I haven't found any solution so far, even changing the settings through VS Code. Thanks!
Use flutter run -d web-server
open app with browser other than Chrome
I don't think that anyone has properly answers this question yet so I'll give it a go.
In my case, my computers default browser is set to Safari but Safari doesn't work well with Flutters Dev Tools at the moment. So.. how can you keep your computers default browser and specify a browser you want to use when starting dev tools?
In Android Studio open up your Preferences and in the top left there is a search bar.
Type in "Web Browsers".
You will see a list of web browsers and you can click and drag.
Place the one you want to use by default on top. For example I have chrome on the top of my list.
Now just set this from "System default" to "First listed" and apply your changes
When you press this button to open dev tools it will now, in my case, open chrome instead of safari even though Safari is my computers default browser.
The other answers here pointed out solutions in Android Studio and starting a local server separately. But I wanted to start the whole debugging session in one command. So this is what I came up with in Linux:
I wanted to use Brave as the default browser. First run which brave-browser. Copy the outputted path (in my case, it was /usr/bin/brave-browser). Then open your bashrc or zshrc and paste the following line:
export CHROME_EXECUTABLE=THE_COPIED_PATH_FROM_PREVIOUS_STEP
# for me it became, CHROME_EXECUTABLE=/usr/bin/brave-browser
Lastly restart the shell:
source ~/.zshrc
# or source ~/.bashrc
Now, simply running flutter run -d chrome would open up the debugging session in Brave instead of Chrome(though in the console output, the messages will still be referring to Chrome).
its actually depends on code editor / ide
for vs-code
open setting
search dart.devToolsBrowser
change to default or any other browser

UiAutomator bug while inspecting WebView elements

I have recently started automation testing in android and was using UiAutomator tool for inspecting UI elements. Surprisingly, I came across two different responses for Webview elements for the same screen and same device [Genymotion MotoX 4.4.4]. Attached are the screenshots for the same. We all know that appium has an issue with inspecting webview elements who do not carry "setWebContentsDebuggingEnabled" to true. Is this a bug in UiAutomator?
We all know that appium has an issue with inspecting webview elements
who do not carry "setWebContentsDebuggingEnabled" to true. Is this a
bug in UiAutomator?
NO, its not a bug. Its an IMPLEMENTATION as is. Unless the setWebContentsDebuggingEnabled is set to true, you cannot debug or access any elements inside a webview.
To quote from developers.android.com
void setWebContentsDebuggingEnabled (boolean enabled)
Enables
debugging of web contents (HTML / CSS / JavaScript) loaded into any
WebViews of this application. This flag can be enabled in order to
facilitate debugging of web layouts and JavaScript code running inside
WebViews. Please refer to WebView documentation for the debugging
guide. The default is false.
You might be interested into these as well :
Migrating to WebView in Android 4.4

Android WebView accessibility in KitKat

I'm having some trouble getting TalkBack to work with a web view (testing with a Nexus 5 on Android 4.4.2). I read that TalkBack support was added to web views around the release of Android JellyBean by checking a preference titled "Enhance Web Accessibility." I can't for the life of me find this preference in the system settings.
Focusing on the web view in our application simply reads "WebView" and provides no other options. I've made sure and called getSettings().setJavaScriptEnabled(true); on the web view.
Was TalkBack support for web views removed in KitKat? If not, what am I missing here?
On 4.4, you need to have TalkBack/Explore by Touch enabled on the first run of your application. If you enabled it after that, it never seems to work. I figured this out by trial and error. I suspect scripts are being injected into your app/WebView on first launch to support it.
As an alternative, you could manually inject the ChromeVox scripts into your WebView and enable accessibility that way. Check out how the PhoneGap plugin does it - https://github.com/phonegap/phonegap-mobile-accessibility

Flex mobile 4.6 app works inside flash builder but not in android emulator

I have a basic flex mobile 4.6 app and it works fully fine in the flash builder built-in emulator using an android device profile like aria...
It also launches fine in the android emulator but one particular view shows blank (and this view works fine in flash builder).
Before I get in to many details of the view are there any categorical gotchas that can be causing this?
I can't seem to get the trace statements from the app to show in 'adb logcat'. It seems I need to compile a debug version of the apk but I don't know how to do this. I use the 'Export Release Build' from the Project menu in flash builder and it doesn't seem to have an option for debug=true.
The problematic/blank view basically uses the stagewebview and iotashan's oauth library to call linkedin rest apis... A different (and working) view can make restful web service calls in the emulator fine, so it doesn't seem to be an internet permission.
The source code contained in the problematic/blank view is almost identical to the tutorial found at: http://www.riagora.com/2011/01/air-and-linkedin/
The differences are:
a) The root tag is a View
b) I use StageWebView instead of HtmlContainer
c) I use my own linkedin key and tokens.
I would appreciate it if someone can provide me with some pointers on how to troubleshoot this situation. Perhaps someone can tell me how to debug the app while running in the emulator (I think I need the correct adt command arguments for this which matches the 'Export Release Build' menu but adds the debug param?)
Thanks for your help in advance.
========================================
Comment added after some more debugging:
OK - through some Fiddler profiling I am observing that the http tunnel created to api.linkedin.com:443 when debugging inside of FlashBuilder vs inside of the Android emulator is different. Specifically, the following two lines of code create different HTTP headers:
var request:OAuthRequest = new OAuthRequest("GET", requestTokenUrl, {oauth_callback:'http://www.xyz123.com'} , consumer, null);
loader.load(urlRequest);
While in Flashbuilder the URLLoader seems to create the request with proper headers like Host:api.linkedin.com:443,Content-Length:0,Connection:Keep-Alive, etc..., inside the Android Emulator there is only one header Host: 216.52.242.83:443.
Why on earth would this happen?

Loading URL in WebView for Android 3.1 fails on device but works on emulator

I'm trying to load the following URL into a webview: index.html?name
This works fine on Android 2.2 device and emulator, as well as Android 3.1 emulator. However, when I load the app up on my Android 3.1 galaxy tab, I am met with an error:
Webpage not available
The webpage at file:///android_asset/index.html?name might be temporarily down or it may have moved permanently to a new web address.
Seems like it's not registering that it's a local asset and is trying to access the web for it. Any idea why this is happening, and only on the physical 3.1 device? If I try to load just index.html then it works fine on everything. I doubt it, but could it have something to do with the question mark?
Thanks in advance.
I had the same issue but there's a workaround...
Change ?name to #name instead and it will work, since named anchors are supported by Android. You can then use JavaScript like the following to detect the anchor and act upon it:
if (window.location.href.search('#name') > 0)
{
// Do something
}
I think you've answered your own question. Over HTTP, the '?' in a URL is used to separate URL parameters from the main URL; although it's interesting that this works with file:///android_asset in the emulators, I'd hesitate to call it a bug.
If you need to pass arguments to the HTML page (perhaps for javascript to use), one option would be to use anchor syntax (e.g. file:///android_asset/index.html#name)
As per the standard, file:// URLs don't support query strings, like your ?name. So this is hardly a bug. What are you trying to accomplish in the first place? Which part of your code is supposed to process the name? If JavaScript, then load the page, then invoke some JavaScript on it via another loadUrl() call with a javascript: URL.

Categories

Resources