When your test fails to find element inside webView, may be it is better to show actual item, but atom is null runtime exception is shown.
I too have this error now on webviews. The below sample code might give some better understanding:
// The below webview takes some time to load the element webView { // Error displayed here as there is no webview displayed due to loading withElement(Locator.CSS_SELECTOR, "#username") { clear() click() keys("admin") } }
On further adding Thread.sleep, the tests shows pass but the values are not entered:
webView { Thread.sleep(8000) withElement(Locator.CSS_SELECTOR, "#username") { clear() click() keys("admin") } }
The below is the log for the above code execution:
09 23:19:50.356 7754 8463 W System.err: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
05-09 23:19:50.356 7754 8463 W System.err: at com.segment.analytics.internal.Utils.isEmptyOrBlank(Utils.java:208)
05-09 23:19:50.356 7754 8463 W System.err: at com.segment.analytics.Analytics$Builder.(Analytics.java:1101)
05-09 23:19:50.356 7754 8463 W System.err: at com.segment.analytics.Analytics.with(Analytics.java:178)
05-09 23:19:50.356 7754 8463 W System.err: at com.shop.core.analytics.AnalyticsJavascriptInterface.track(AnalyticsJavascriptInterface.kt:34)
05-09 23:19:50.356 7754 8463 W System.err: at android.os.MessageQueue.nativePollOnce(Native Method)
05-09 23:19:50.356 7754 8463 W System.err: at android.os.MessageQueue.next(MessageQueue.java:339)
05-09 23:19:50.356 7754 8463 W System.err: at android.os.Looper.loop(Looper.java:199)
05-09 23:19:50.356 7754 8463 W System.err: at android.os.HandlerThread.run(HandlerThread.java:67)
05-09 23:19:50.358 7754 7754 I chromium: [INFO:CONSOLE(1)] "Error: Java exception was raised during method invocation", source: https://ct-us-staging.shop.com/_next/static/chunks/dc9f8c066c60aa3b4edddeb280a5b5862d9cff83.b33eca1dee997d28e39f.js (1)
05-09 23:19:50.435 7754 8463 W System.err: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
05-09 23:19:50.435 7754 8463 W System.err: at com.segment.analytics.internal.Utils.isEmptyOrBlank(Utils.java:208)
05-09 23:19:50.435 7754 8463 W System.err: at com.segment.analytics.Analytics$Builder.(Analytics.java:1101)
05-09 23:19:50.435 7754 8463 W System.err: at com.segment.analytics.Analytics.with(Analytics.java:178)
05-09 23:19:50.435 7754 8463 W System.err: at com.shop.core.analytics.AnalyticsJavascriptInterface.track(AnalyticsJavascriptInterface.kt:34)
05-09 23:19:50.435 7754 8463 W System.err: at android.os.MessageQueue.nativePollOnce(Native Method)
05-09 23:19:50.435 7754 8463 W System.err: at android.os.MessageQueue.next(MessageQueue.java:339)
05-09 23:19:50.435 7754 8463 W System.err: at android.os.Looper.loop(Looper.java:199)
05-09 23:19:50.435 7754 8463 W System.err: at android.os.HandlerThread.run(HandlerThread.java:67)
05-09 23:19:50.437 7754 7754 I chromium: [INFO:CONSOLE(1)] "Error: Java exception was raised during method invocation", source: https://ct-us-staging.shop.com/_next/static/chunks/dc9f8c066c60aa3b4edddeb280a5b5862d9cff83.b33eca1dee997d28e39f.js (1)
05-09 23:19:50.596 7754 7754 I KASPRESSO: web action "clear" on webview (view.getId() is <2131362618/com.shop.staging:id/webView>)
05-09 23:19:50.621 7754 7754 I ViewInteraction: Performing 'Evaluate Atom: androidx.test.espresso.web.webdriver.DriverAtoms$FindElementTransformingAtom@eb88bd4 in window: null with element: null' action on view (view.getId() is <2131362618/com.shop.staging:id/webView>)
05-09 23:19:50.644 7754 7754 I ViewInteraction: Performing 'Evaluate Atom: com.kaspersky.kaspresso.proxy.AtomProxy@c2523ca in window: null with element: {"ELEMENT":":wdc:1652131190276"}' action on view (view.getId() is <2131362618/com.shop.staging:id/webView>)
05-09 23:19:50.706 1046 3207 I WifiHAL : event received NL80211_CMD_VENDOR, vendor_id = 0x1374, subcmd = 0xd
05-09 23:19:50.711 7754 7754 I KASPRESSO: web action "click on element" on webview (view.getId() is <2131362618/com.shop.staging:id/webView>)
05-09 23:19:50.728 7754 7754 I ViewInteraction: Performing 'Evaluate Atom: androidx.test.espresso.web.webdriver.DriverAtoms$FindElementTransformingAtom@eb88bd4 in window: null with element: null' action on view (view.getId() is <2131362618/com.shop.staging:id/webView>)
05-09 23:19:50.730 3741 3741 D DeviceStatisticsService: chargerType=1 batteryLevel=75 totalBatteryCapacity=4880000
05-09 23:19:50.730 3741 3741 D DeviceInfoHidlClient: isPowerInfoNeverSent()=true
05-09 23:19:50.745 7754 7754 I ViewInteraction: Performing 'Evaluate Atom: com.kaspersky.kaspresso.proxy.AtomProxy@4f3f93b in window: null with element: {"ELEMENT":":wdc:1652131190276"}' action on view (view.getId() is <2131362618/com.shop.staging:id/webView>)
05-09 23:19:50.799 7754 7754 I KASPRESSO: web action "send keys" with result="{pressed=[], currentPos=19}" on webview (view.getId() is <2131362618/com.shop.staging:id/webView>)
I assume the above error can be relate to enabling Javascript in the webview. For Kaspresso I need some info on how t0 enable javascript also.
Hi @vsgopinath !
Sorry that it took a while to reply!
I believe the best to find a solution is to create your own KwebView based on that one of Kakao.
For enabling Javascript, for example:
open class KWebViewCustom(matcher: (ViewBuilder.() -> Unit)? = null) {
private val web = WebInteractionDelegate(
if (matcher != null) {
Web.onWebView(ViewBuilder().apply(matcher).getViewMatcher())
} else {
Web.onWebView()
}
)
/**
* Operator that allows usage of DSL style
*
* @param function WebElementBuilder which will give you access to match elements
* and perform actions/assertions on it.
*/
operator fun invoke(function: WebElementBuilder.() -> Unit) {
WebElementBuilder(web).apply(function)
}
// till here just a copy paste from Kakao`s KWebView
fun enableJavascript(){
web.forceJavascriptEnabled()
}
// add here other methods you need!
}
Hope you can find a solution by using this approach, if so, do share it with us :)