I use couple of Android apps on daily bases, and it's very time consuming.
I want to somehow automatize the process.
The idea is to install some sort of emulator on the server, and program that emulator through some programming language to run the apps on the server when its needed.
I'm a web developer, I work with PHP, nodejs, python,
not really familiar with mobile space.
Is there any solution out there to do what I want?
I search around and found Appium but I'm not sure if it would do what I want.
Please note these apps don't have a public 'api' for me to use.
Also I only have remote access to server via 'ssh terminal', so solutions with 'GUI' dependency wont work for me.
You can use some emulator, like Bluestacks and then run a script to run apps and then use macro tool to emulate clicks in the games or apps
check this link for the macro tool in bluestacks : https://www.bluestacks.com/blog/bluestacks-exclusives/combo-key-bluestacks-record-replay-action-single-key-en.html
Or you can write a script which uses adb commands to run and control the app.
For example.
to run apps. adb shell am start -n com.android.settings/.Settings
this command will open the settings app in the emulator.
to send touch events you can use : adb shell input touch <x> <Y>
adb shell input keyevent <keycode> to send keycodes
I'm assuming that you want to automate native Android apps.
Short answer: Appium will be good solution for you.
On your remote server you will need:
Android SDK and Simulator
Python 2.7 installed
Appium server/node (install using node.js npm )
With everything installed you will be able to start Appium Nodes on your server and run Appium scripts against them.
I suggest using CI server of choise for automating this process. It should make starting your test trough ssh terminal easier / 100% automated.
I never used Selenium/Appium in python, so I can't really help you with Appium tests code examples, but I'm sure there are a lot of basic tutorials for python.
You must install AppiumServer and android sdk/simulator in the remote server. I am going to show how it can be done in java. Hope you can convert it into javascript code.
Check the ip Address of your remote server using ipconfig
Start your appium server in the remote server
>appium -a "ip address of remote server" -p 4732 --session-override
Start the emulator in the remote server.
Define and initialize DesiredCapabilities and AppiumDriver in your code like following.
AppiumDriver<MobileElement> driver;
DesiredCapabilities caps= new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "android device");
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
caps.setCapability("appPackage", "enter your appPackage");
caps.setCapability("appActivity", "enter your appActivity");
driver= new AndroidDriver<MobileElement>(new URL("remote server ip address" + ":4732/wd/hub"), caps);
Make sure both device are in the same network. you must get response while pinging to the remote server ip address
Related
My goal is a setup where I keep Appium and Android emulator running on a remote Ubuntu Virtual Private Server and the test code running Selenium on a local machine.
In theory it should not be a problem with this setup:
appium_capabilities = {
'automationName': 'Appium',
'platformName': 'Android',
'deviceName': 'Android',
'app': 'APK_PATH'
}
vps_url = "THIS IS MY VPS IP"
appium_driver =
AppiumDriver(command_executor=vps_url+'/wd/hub',
desired_capabilities=appium_capabilities)
appium_driver.find_element(...)
appium_driver.quit()
Will it work or do I waste my time trying? I am asking because I cannot find any tutorials about it. If yes, how will the configuration need to be?
It actually will work (Appium server + emulator on remote server, tests code on other machine) but you need to make sure your apk is on remote server and the path to apk is the valid absolute path on that remote machine.
If you feel in this requirement, it will works smoothly - I'm doing the same :)
While creating session you need to provide remote server URL and correct port server is listening to.
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.
I'm developing a mobile web app where the content server is remote. I can do some basic testing on desktop Chrome with --disable-web-security option.
Is there a similar feature available on chrome on android? Or, any other browser on android?
UPDATE
I'm including these headers, Authorization, Access-Control-Allow-Origin, Access-Control-Allow-Credentials; but it seems to have no impact on the data server.
Am I missing any other settings?
The web app code resides on a local PC. Data on the remote hosts and the browser is on mobile in local LAN.
Actually, there is a way but it is a little hard, first, you should install adb on your system (Linux, Windows, macOS and etc) then restart adb server and at last plugin your Android device. check the adb connection with below command on your terminal/cmd:
$ adb list
When you see your device on the result of the above command, it is time to run the main command:
$ adb shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
If the above command opens a Google Chrome tab or window, its time to disable security by your command order
I am trying to reverse-forward port through ADB, but it just returns cryptic error of error: closed. Normal forwarding works. Session snippet:
$ adb forward tcp:59778 tcp:59778
$ adb forward --list
015d2109ce0c1a0f tcp:59778 tcp:59778
$ adb forward --remove-all
$ adb forward --list
$ adb reverse --list
error: closed
error: closed
$ adb reverse tcp:59778 tcp:59778
error: closed
error: closed
I am connecting via USB to non-rooted Nexus 7 2012 Android 4.4.4 from Windows 7 Pro x64 on Boot Camp.
adb reverse was introduced in Android 5.0
Since adb reverse is not supported in Android versions lower than 5.0, you need to use an alternative method, for example connecting via Wi-Fi instead. If you are using React Native, Facebook has added official documentation to connect to the development server via Wi-Fi. Quoting the instructions for MacOS, but they also have them for Linux and Windows:
Method 2: Connect via Wi-Fi
You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.
You can find the IP address in System Preferences → Network.
Make sure your laptop and your phone are on the same Wi-Fi network.
Open your React Native app on your device.
You'll see a red screen with an error. This is OK. The following steps will fix that.
Open the in-app Developer menu.
Go to Dev Settings → Debug server host for device.
Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
Go back to the Developer menu and select Reload JS.
Follow these steps carefully.
Note: All commands need to run inside a project only.
Run this command first:
npm react-native start
Open another window in the same project and run:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
This will create index.android.bundle in the assets folder
Run:
npm react-native run-android
Now you can get apk in the build folder which will work fine.
adb reverse requires Android 5.0+. For devices previous to that, you'll need to use a workaround like so.
If you have busybox installed on your Android device (most Genymotion images do), you can emulate adb reverse using this incantation:
adb shell busybox nc -ll -p {guest port} -e busybox nc {host IP} {host port}
In this case, "guest" is the Android OS running in the emulator and "host" is the computer running the emulator.
cause of adb reverse isnt working on android prior 5 you could propably use adb forward with a service listening on android and tunneling other connections through this inbound connection. I am doing this mostly with ssh, but you would need an ssh server on android. you than can connect using ssh -R incommingreverseportonandroid:hostyouwanttoforwardto:portyouwanttoforwardto sshuseronandroid#localhost -p portyouhaveusedforadbforwaqrdtoaccessandroidssshserver
but i dont know how to enable an ssh server on android and maybe there is a better way cause ssh uses encryption which isnt needed over usb and using up cpu.
i am using this way with my server to share a service when i am forced behind a nat...
hope someone will find a way to bring this teoretical way into practical possibility
Just use 10.0.2.2 instead of localhost/127.0.0.1 for your hostname. It will directly try to connect to the port on the host machine (same affect as reverse).
So I did a research before posting this and the solutions I found didn't work, more precisely:
-Connecting to my laptop's IPv4 192.168.XXX.XXX - didn't work
-Conecting to 10.0.2.2 (plus the port) - didn't work
I need to test an API i built using Django Rest framework so I can get the json it returns, but i cant access through an Android app i'm building (I'm testing with a real device, not an emulator). Internet permissions are set on Manifest and i can access remote websites normally. Just can't reach my laptop's localhost(they are in the same network)
I'm pretty new to Android and Python and Django as well (used to built Django's Rest Framework API).
EDIT: I use localhost:8000/snippets.json or smth like this to connect on my laptop.
PS: I read something about XAMP server... do I need it in this case?
Thanks in advance
Have you started the server like this?
python manage.py runserver 0.0.0.0:8000
Then, try to connect to 192.168.XXX.XXX:8000
I tried the above, but failed to work in my case. Then with running
python manage.py runserver 0.0.0.0:8000 I also had to add my IP to ALLOWED_HOSTS in settings.py, which solved this issue.
eg.
Add your ip to allowed hosts in settings.py
ALLOWED_HOSTS = ['192.168.XXX.XXX']
Then run the server
python manage.py runserver 0.0.0.0:8000
Others have already given the answer but those solutions didn't work for me when I was running Django server on Ubuntu and was trying to access it from my Mobile app.
Following is what worked for me:
Step 1: Run server to access it from your IP
python manage.py runserver 0.0.0.0:8000
Step 2: Open port in firewall (Missing step in above given answers - Needed for Ubuntu)
$ sudo ufw enable
$ sudo ufw allow 8000