如何转发端口以进行App测试。测试Droid Cloud

时间:2018-12-27 18:51:29

标签: android adb portforwarding bitbar

我正在尝试在https://cloud.testdroid.com上使用Appium运行自动化测试。 这款Android应用是由Unity3d游戏引擎制作的,并且为此使用了AltUnityTester(https://gitlab.com/altom/altunitytester/tree/master)。

在安装应用程序之前,我必须从连接的android设备转发端口,以便我可以获取事件。但是我无法这样做。.

我尝试将以下adb转发代码添加到run-tests.sh脚本中。但是,这根本不起作用。

下面是run-tests.sh脚本代码:

#!/bin/bash

##
## Work in progress! The dependency installations need to be done to the
## container so that we don't need to install them here.
##
TEST=${TEST:="TestdroidAppiumTest.py"} #Name of the test file

##### Cloud testrun dependencies start

echo "adb forward code is here 0"

adb forward tcp:13001 tcp:13000

echo "adb forward code ends here 0"

echo "Extracting tests.zip..."
unzip tests.zip

echo "Installing pip for python"
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py

echo "Installing Appium Python Client 0.24 and xmlrunner 1.7.7"
chmod 0755 requirements.txt
sudo pip install -r requirements.txt

echo "adb forward code is here 1"

adb forward tcp:13001 tcp:13000

echo "adb forward code ends here 1"

echo "Starting Appium ..."

appium --log-no-colors --log-timestamp

ps -ef|grep appium
##### Cloud testrun dependencies end.

export APPIUM_APPFILE=$PWD/application.apk #App file is at current working folder

## Desired capabilities:

export APPIUM_URL="http://localhost:4723/wd/hub" # Local & Cloud
export APPIUM_DEVICE="Local Device"
export APPIUM_PLATFORM="android"

APILEVEL=$(adb shell getprop ro.build.version.sdk)
APILEVEL="${APILEVEL//[$'\t\r\n']}"
echo "API level is: ${APILEVEL}"

## APPIUM_AUTOMATION 
if [ "$APILEVEL" -gt "16" ]; then
  echo "Setting APPIUM_AUTOMATION=Appium"
  export APPIUM_AUTOMATION="Appium"
else
  echo "Setting APPIUM_AUTOMATION=selendroid"
  export APPIUM_AUTOMATION="Selendroid"
fi

## Run the test:
echo "Running test ${TEST}"
rm -rf screenshots

python ${TEST}

mv test-reports/*.xml TEST-all.xml

我试图回显一些日志,以检查脚本的那部分是否正在运行。我得到了回声,但是端口转发似乎不起作用。

下面是TestDroid的控制台日志

Device tools path: /opt/testdroid/device-tools.jar
Video recording enabled: true
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.16.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
List of devices attached
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
HT67R0300011    device

18/12/27 18:32:23 INFO helpers.ADBHelper: Initializing Android Debug Bridge
18/12/27 18:32:23 INFO manager.AndroidDeviceScanner: Adding Android Debug Bridge listeners
18/12/27 18:32:23 INFO manager.AndroidDeviceScanner: AndroidDebugBridge connected
18/12/27 18:32:23 INFO config.Log4jConfigurator: Changing logging configuration: /test/log4j.config
**adb forward code is here 0
adb forward code ends here 0**
Extracting tests.zip...
Archive:  tests.zip
  inflating: requirements.txt        
replace run-tests.sh? [y]es, [n]o, [A]ll, [N]one, [r]ename:  NULL
(EOF or read error, treating as "[N]one" ...)
  inflating: TestdroidAppiumTest.py  
Installing pip for python
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0package:/data/app/jp.co.cyberagent.stf-eUP8iBNgy3ctJtCiOl-TjA==/base.apk=jp.co.cyberagent.stf
package:/data/app/com.android2.calculator3-LnsOmj08opYztmL1of76jw==/base.apk=com.android2.calculator3
package:/data/app/com.domobile.applock-4XdAy6GIocFxhYTg4fBYbA==/base.apk=com.domobile.applock
package:/data/app/com.android.myownvirtualwallet-hN7pFQybBxGv5BbjgTklwg==/base.apk=com.android.myownvirtualwallet
package:/data/app/com.domobile.applockwatcher--dFKyUndpFW1F7hmLG3Jag==/base.apk=com.domobile.applockwatcher
package:/data/app/com.google.android.apps.inbox-FvEgcQTK2pPJS9tkYu4zRg==/base.apk=com.google.android.apps.inbox
package:/data/app/com.google.android.youtube.tv-W7RuG1N2wU4yiq8Xl0UYQw==/base.apk=com.google.android.youtube.tv
package:/data/app/com.bitbar.testdroid.monitor-3mKS6ncPs-I2ooV5QkH_Qg==/base.apk=com.bitbar.testdroid.monitor
package:/data/app/com.android.azula-bP_gShKQzKyzte7FwCeO7Q==/base.apk=com.android.azula
package:/data/app/com.google.android.gms.setup-MqZL6LKHen2PFwEY1Kam3A==/base.apk=com.google.android.gms.setup
package:/data/app/com.google.android.play.games-p-UOF5_zsEzcCEuJjhQ7GQ==/base.apk=com.google.android.play.games

100 1622k  100 1622k    0     0  4824k      0 --:--:-- --:--:-- --:--:-- 4829k
package:/data/app/jp.co.cyberagent.stf-eUP8iBNgy3ctJtCiOl-TjA==/base.apk=jp.co.cyberagent.stf
package:/data/app/com.android2.calculator3-LnsOmj08opYztmL1of76jw==/base.apk=com.android2.calculator3
package:/data/app/com.domobile.applock-4XdAy6GIocFxhYTg4fBYbA==/base.apk=com.domobile.applock
package:/data/app/com.android.myownvirtualwallet-hN7pFQybBxGv5BbjgTklwg==/base.apk=com.android.myownvirtualwallet
package:/data/app/com.domobile.applockwatcher--dFKyUndpFW1F7hmLG3Jag==/base.apk=com.domobile.applockwatcher
package:/data/app/com.google.android.apps.inbox-FvEgcQTK2pPJS9tkYu4zRg==/base.apk=com.google.android.apps.inbox
package:/data/app/com.google.android.youtube.tv-W7RuG1N2wU4yiq8Xl0UYQw==/base.apk=com.google.android.youtube.tv
package:/data/app/com.bitbar.testdroid.monitor-3mKS6ncPs-I2ooV5QkH_Qg==/base.apk=com.bitbar.testdroid.monitor
package:/data/app/com.android.azula-bP_gShKQzKyzte7FwCeO7Q==/base.apk=com.android.azula
package:/data/app/com.google.android.gms.setup-MqZL6LKHen2PFwEY1Kam3A==/base.apk=com.google.android.gms.setup
package:/data/app/com.google.android.play.games-p-UOF5_zsEzcCEuJjhQ7GQ==/base.apk=com.google.android.play.games
Note: device /dev/input/mice is not supported by libevdev
Type B touch device synaptics_dsxv26 (1079x1919 with 10 contacts) detected on /dev/input/event2 (score 22447)
Collecting pip
  Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
Collecting setuptools
  Downloading https://files.pythonhosted.org/packages/37/06/754589caf971b0d2d48f151c2586f62902d93dc908e2fd9b9b9f6aa3c9dd/setuptools-40.6.3-py2.py3-none-any.whl (573kB)
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
Connection established
Successfully installed pip-18.1 setuptools-40.6.3 wheel-0.32.3
Installing Appium Python Client 0.24 and xmlrunner 1.7.7
Collecting Appium-Python-Client==0.24 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/c6/aa/51ceffc104a462c689241cb3fe83c9bb7a7e24f9238bd3a892b28bd50737/Appium-Python-Client-0.24.tar.gz
Collecting selenium==3.0.2 (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/d2/20/86e729322e3cb42e1b134900e4e4735c83380b08fb4decaa925294f09bf0/selenium-3.0.2-py2.py3-none-any.whl (915kB)
Collecting xmlrunner==1.7.7 (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/57/c0/a19e29bc6038a56bb690549573af6ea11a9d2a5c07aff2e27ed308c2cab9/xmlrunner-1.7.7.tar.gz
Collecting altunityrunner==0.1.3 (from -r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/fb/84/38d2add21bf701d9697a99df709dd6e73ec9902af8ed3cf435fbe64e7864/altunityrunner-0.1.3.tar.gz
PID: 7091
INFO: Using projection 1080x1920@450x800/0
INFO: (external/MY_minicap/src/minicap_28.cpp:241) Creating SurfaceComposerClient
INFO: (external/MY_minicap/src/minicap_28.cpp:244) Performing SurfaceComposerClient init check
INFO: (external/MY_minicap/src/minicap_28.cpp:255) Creating virtual display
INFO: (external/MY_minicap/src/minicap_28.cpp:261) Creating buffer queue
INFO: (external/MY_minicap/src/minicap_28.cpp:264) Setting buffer options
INFO: (external/MY_minicap/src/minicap_28.cpp:268) Creating CPU consumer
INFO: (external/MY_minicap/src/minicap_28.cpp:272) Creating frame waiter
INFO: (external/MY_minicap/src/minicap_28.cpp:276) Publishing virtual display
Building wheels for collected packages: Appium-Python-Client, xmlrunner, altunityrunner
INFO: (jni/minicap/JpgEncoder.cpp:64) Allocating 6268932 bytes for JPG encoder
  Running setup.py bdist_wheel for Appium-Python-Client: started
INFO: (jni/minicap/minicap.cpp:448) New client connection
  Running setup.py bdist_wheel for Appium-Python-Client: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/15/f2/b6/63b95c52ded134dfd5c3418c5902aae73f9e1bfc2d97221ffb
  Running setup.py bdist_wheel for xmlrunner: started
  Running setup.py bdist_wheel for xmlrunner: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/c8/0e/05/28e4ff5b683c7a319756b412c7f4dc508a7ffa654e12c54ef5
  Running setup.py bdist_wheel for altunityrunner: started
  Running setup.py bdist_wheel for altunityrunner: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/9f/fc/af/9fe0e1aeb44e065bc4dcf62009eb539a5ae90e66dbe87819b9
Successfully built Appium-Python-Client xmlrunner altunityrunner
Installing collected packages: selenium, Appium-Python-Client, xmlrunner, altunityrunner
Successfully installed Appium-Python-Client-0.24 altunityrunner-0.1.3 selenium-3.0.2 xmlrunner-1.7.7
**adb forward code is here 1
adb forward code ends here 1**
Starting Appium ...
Appium version 1.9 (default)
Waiting service to fully launch on 4723...
localhost [127.0.0.1] 4723 (?) : Connection refused
localhost [127.0.0.1] 4723 (?) : Connection refused
localhost [127.0.0.1] 4723 (?) open
root       305     1 85 18:32 ?        00:00:01 node /opt/testdroid/appium-1.9.1/node_modules/appium/build/lib/main.js --log-no-colors --log-timestamp
root       334   198  0 18:32 ?        00:00:00 grep appium
API level is: 28
Setting APPIUM_AUTOMATION=Appium
Running test TestdroidAppiumTest.py

Running tests...
----------------------------------------------------------------------

1 个答案:

答案 0 :(得分:0)

您可以使用以下命令确认端口转发成功:
adb forward --list
如果转发正常,则应确认端口(13000)上的远程服务已启动。

类似的项目可能会帮助您:CXTouch