With the purpose to make test-automation for my Ionic App, I am trying to do the following but the main problem is that I cannot find any element in the webview.
I am trying to follow the steps listed here in the official Appium documentation.
Here’s the basic Ionic setup I am using for this test:
- Ionic 4
- A sample test project available on GitHub
- Python 2.7.15
- robotframework-3.1.1 installed via pip
- appium 1.11.1 installed via npm (I also have Appium Client for Windows 1.11.0)
These are the steps to reproduce the issue.
git clone https://github.com/fbcyborg/simple-app.git
cd simple-app
npm install
One important thing we must notice, is the cordova-plugin-debuggable-webview plugin available here. This does exactly what is mentioned below from the Appium guide:
There is an additional step necessary within your app build, unfortunately. As described in the Android remote debugging docs it is necessary to set to
true
the setWebContentsDebuggingEnabled property on the android.webkit.WebView element.
As you can see, the plugin is enabled and the result is a fully debuggable ionic application via Chrome Inspector.
To test the application, just perform the following commands:
ionic cordova build android
adb install app-debug.apk
Once the application is installed on the device, we start the application and the uiautomtorviewer as well.
Here’s the screenshoot:
After that, I start Appium:
[Appium] Welcome to Appium v1.11.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
Here’s the RobotFramework .robot file I prepared for a simple test: clicking a button:
*** Settings ***
Library C:/Python27/Lib/site-packages/AppiumLibrary/
*** Test Cases ***
Simple Test
Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=8.0.0 deviceName=emulator-5554 appPackage=io.ionic.starter appActivity=io.ionic.starter.MainActivity appWaitActivity=io.ionic.starter.MainActivity udid=emulator-5554
Wait Activity .MainActivity 15
Click Element class=android.widget.Button[@text='RUN TEST']
Close All Applications
If I try to launch this robot file, I cannot find any element in the WebView:
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'android.widget.Button[@text='RUN TEST']' using 'CLASS_NAME' with the contextId: '' multiple: true
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.Button[@text='RUN TEST']]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.Button[@text='RUN TEST']]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[CLASS=android.widget.Button[@text='RUN TEST'], INSTANCE=0]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'android.widget.Button[@text='RUN TEST']' using 'CLASS_NAME' with the contextId: '' multiple: true
I tried the same thing in Java, but there is no way to find any element.
What am I doing wrong?