How to make generic Appium find_element_by_xpath method? - android

I am writing test cases for my application but i have a problem. When i use Genymotion for emulator. I got this path on Appium inspector and create my script for this path:
"//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.RelativeLayout[1]/android.widget.Button[1]"
But if i use device "HTC One E8". I got this path on Appium inspector:
"//android.support.v4.view.ViewPager[1]/android.widget.Button[1]"
my script will fail? if i use different devices and emulators.
How can it be generic?.
PS: I used self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("welcome_button_meet_hopi")').click() before but it works on Appium on Ubuntu and it didnt work on Appium on OSX

Related

Appium selector methods: Appium Inspector and UIAutomatorViewer throwing errors

I am trying to use Appium together with robot framework to automate some tests for android-bluetooth connectivity. Currently, I am following a similar thought-architecture to something I've worked on previously: write bluetooth commands in python scripts which can then be connected to some http endpoints and called from robot framework. (Note: I am therefore not trying to automate tests for apps I've developed, but rather just use appium to automate behaviour on an adb device via some server.)
So far with appium, I've only been able to find limited non-UI-dependent bluetooth commands like
self.driver.execute_script('mobile: shell', {
'command': 'am start -a android.bluetooth.adapter.action.REQUEST_ENABLE',})
this works, but for example to connect to a specific device, I guess I am going to need some actual selector method to navigate the screen.
As I understand it, Appium Inspector and UIAutomatorViewer are the two most common methods for this with android. Here are the problems I am facing with each:
Appium Inspector: Error
Failed to create session. Unexpected token < in JSON at position 0
See image below
Doesn't matter how I format the JSON representation.
The way I have configured Appium Inspector is by being navigated to releases and downloading everything linux related and making the
AppImage executable as is specified here
With UIAutomatorViewer, I think I might have my environment set up wrongly:
~$ uiautomatorviewer
-Djava.ext.dirs=/usr/lib/android-sdk/tools is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Here is my uiautomatorviewer path:
$ whereis uiautomatorviewer
uiautomatorviewer: /usr/bin/uiautomatorviewer /usr/share/uiautomatorviewer /home/Username/Android/Sdk/tools/uiautomatorviewer
But I've been unable to find anything on SO or google on this issue.
Appreciate any help!

how to get tkinter GUI features in Code-server on Android

I installed code-server in ubuntu in termux on android device. It is ok for CUI. Tkinter has problem - 'couldn't connect to display :1'. I've tried some ways I found in googling but not solved the problem. Is there any way to run GUI in code-server in termux linux using tkinter. I'm beginner in linux.

Nativescript emulator installation headaches

I've been trying to get emulators to work for NativeScript on my brand new clean Windows 10 laptop for three days and nothing is working.
To be more accurate, I think I was able to get the 'emulator-5554' to launch, but it doesn't not load the Groceries app.
I have all the Angular requirements installed since I also build Angular SPAs and they work fine. I read and followed all these articles, and I still can't get emulators to work.
I even installed GenyMotion, but it is not detected. I have not installed Android Studio since I'll be developing with Visual Studio Code, so I used the Android CLI to install the SDK.
https://docs.nativescript.org/start/general-requirements
https://docs.nativescript.org/start/introduction
https://docs.nativescript.org/start/cli-basics
https://docs.nativescript.org/tooling/android-virtual-devices?_ga=2.188319272.1221867054.1547512018-618552819.1547075699
https://docs.nativescript.org/start/quick-setup
https://docs.nativescript.org/start/ns-setup-win - this was my primary emulator setup
I have also read many SO posts and none have solved my problem.
Is there some documentation somewhere that is simple and clear, with step by step instructions on how to get emulators installed that will work with Nativescript? What am I missing?
BTW, when I connect my Samsung Galaxy S8 Active phone to my laptop, it's not recognized by the tns device command either.
I can't believe it's this difficult to get emulators to work. I also can't believe that the Nativescript documentation has left this information out of their instructions.
This might not be the answer most are looking for, but this is what was wrong with my installation and this is how I fixed it:
I noticed that the docs all had $./advmanager [someArg] and I had to be sudo for commands to execute. So I ran sudo chown -R myUser:myUser /usr/local/android thus changing all owner:group permissions from root to myUser.
then I could run ./avdmanager create.... (full command below) without having to be superuser
restarted Nativescript Sidekick
I know this is kinda stupid, but I worked out that if the AVD was created as root, the Sidekick program running as myUser could not see and access it. This was confirmed when I ran avdmanager list avd as sudo and got a result, but after changing my files' ownership from root to myUser, nothing was listed from the same command.
I recreated my virtual devices (AVDs) as a normal user and Sidekick was able to see them.
edit: the actual line I ran to create the AVD (because I see a lot of variation in these):
$ ./avdmanager create avd --name Pixel -k "system-images;android-28;google_apis;x86" --device "pixel"?
The uppercase and lowercase "pixel"s come from one entry from the output of
$./avdmanager list
id: 17 or "pixel"
Name: Pixel
OEM : Google
---------
Do this "create" step for each device you want to emulate.
Install Android Studio and open it. Then (without starting a new project) click on:
Configure --> AVD Manager.
There you can create virtual devices, which will be recodnized by NativeScript Sidekick and its virtual device launcher.

Appium Android bootstrap socket crashed: Error: connect ECONNREFUSED

The problem
I have an already working appium tests suite on my MacOS desktop, but when i try to run the same tests on an Ubuntu 16.04 desktop, I get the following error and appium gets closed automatically.
Android bootstrap socket crashed: Error: connect ECONNREFUSED
Also, just to be clear, i'm not trying to run simultaneous tests, just a single emulated android device.
Environment
Appium version: 1.6.3-Beta. Also tried with 1.5.3 and got the same error.
Last Appium version that did not exhibit the issue (if applicable): Not applicable.
Desktop OS/version used to run Appium: Ubuntu 16.04
Node.js version (unless using Appium.app|exe): 7.6.0. But got the same error with v6.
Mobile platform/version under test: Andorid 6 (Marshmallow)
Real device or emulator/simulator: Simulator
Appium CLI or Appium.app|exe: Appium CLI
Details
Been stuck on this for a few days. Saw some question referring to simultaneous tests on the internet, but its not my case. I'm trying to run my tests on a single emulated android device.
Also tried to change the bootstrap port using the -bp option, and set the localhost address using -a 127.0.0.1, but no success.
Link to Appium logs
https://gist.github.com/BernalCarlos/752efe621a55a2b2b0d07b966c8b5354
Thank you on advance.
Solved the problem by making a fresh install of linux mint 18.1.
Still don't know why this showed up in ubuntu 16.04.
I had the similar problem. Set ADB path in system variable as C:\Users\<username>\AppData\Local\Android\Sdk\platform-tools
This will fix the issue.
I solved the problem adding the appium server argument --suppress-adb-kill-server, it prevents killing the adb server socket

Jenkins cannot connect to android emulator

I'm using Jenkins for continous integration on an android emulator to run instrumentation tests with the espresso framework. Unfortunately the server is not able to connect to the emulator. I have a master instance which delegates the push events from GitHub to the slave instance where the android sdk is installed. I installed the android-emulator-plugin and configured it like described. At first the Jenkins starts the emulator, but it cannot connect to it afterwards. This is the result:
I also cannot connect to the emulator when I'm on the slave machine. But if I use 127.0.0.1 instead of localhost the adb tool can connect to the emulator:
Is it possible to use 127.0.0.1 instead of localhost with the android-emulator-plugin? I already specified the enviorment variables $ANDROID_AVD_DEVICE and $ANDROID_SERIAL with no result. Any ideas?
I was fighting with it whole day. Just try to comment ipv6 in your /etc/hosts.
I fixed the problem by myself. I have checked out a fork on GitHub, which uses 127.0.0.1 instead of localhost. This did work for connecting to the emulator but not for running the instrumentation tests. I do not use Jenkins plugins for the connection anymore. I make the build with a shell script which contains all commands to start the AVD and the gradle tasks. Works fine for me. But thank you for the advice. Maybe I will try to comment ipv6 aswell, if I have the time to work on the Jenkins.

Categories

Resources