Wednesday, March 26, 2014

Fiddler简介与Firebug

Fiddler contains web sessions (left), request (right top) and response windows (right bottom).
Sometimes, it can only capture traffic in IE
   

           1. Build a POST request

HTTP method: POST
URL: http://www.choicehotels.com/ires/en-US/html/Availability
Request Header (Required for POST): Content-Type: application/x-www-form-urlencoded
Request Body (Post data):
month=3&day=28&depart_month=3&depart_day=30&srp=RACK&hotel=NY618&sid=&nadult=1&nchild=0&xtrabed=none&count=1&dates_rqd=true&createarrivalcookie=yes


/*Booking data range: 3/28-3/30*/

Then Click Execute and the result will show up in the web session


  2. Analyze a POST request

Click the web session (left in Fiddler)

Request (right top):
I.                    Check the request headers here:

II.                  Check the request body here:



Response (right bottom):



3. How to find out the HTTP request to get the info we want

Take choice hotels for example: http://www.choicehotels.com/. The target is to get the rates for specific hotels given a data range.
a)      Search the hotels by zipcode (07302) at homepage
b)      Click one hotel in the result page
c)       In the detail page for that hotel, click Rates tab
d)      Update the check-in & check-out dates

You will see the http://www.choicehotels.com/ires/en-US/html/Availability with POST data by Fiddler.

Fiddler还可以用于捕捉http request,具体参见Fiddler捕捉手机app的http request

Firebug

与Fiddler很类似的工具就是Firefox,步骤是
1. 安装插件Firebug
2. 按firebug钮
,出现firebug窗口





3. 按Net tab并且enable
4. 最后可以在搜索可能出现在para或者response中的关键字

Thursday, March 13, 2014

Fiddler捕捉手机app的http request

熟悉Fiddler的朋友都知道可以用Fiddler来捕捉电脑中的Http request. 但是Fiddler还可以用于捕捉手机上的request,而且还可以捕捉多台手机。原理其实很简单,只要设置proxy server并且与Fiddler配合就可,具体如下:

1. 打开cmd, type ipconfig得到电脑上的IP address,比如192.168.1.4
2. 然后在手机上设置proxy,IP与电脑一致,端口是8888(跟Fiddler默认的一致)
























可以在手机地址栏输入192.168.1.4(电脑IP地址)见到Fidder Echo service表示连接成功。

3. 打开Fiddler, Tools->Fiddler options->connections->allow remote computers to connect












有些路由器不支持此功能,可能需要打开bridge,即允许设备之间互通。如Motorala在advanced router->Options->Primary Network Bridged

关于Fiddler的简介,可以参见Fiddler简介

另一个Post:


Monday, March 10, 2014

PhotoGap简介

Advantage & disadvantages:
http://www.cnblogs.com/ever4ever/archive/2012/07/09/2583652.html


在Eclipse下安装PhotoGap:
1. In eclipse, 安装by add link: http://svn.codespot.com/a/eclipselabs.org/mobile-web-development-with-phonegap/tags/r1.2.91/download/
2. In Eclipse, 创建一个PhotoGap project (set jQuery Mobile UI demo)


After the project is created, you will see the cordova-1.9.0.jar will be automatically added and index.html will be created under ./assets/www folder.

PHP session:
This is not working in PhotoGap. So need to use local storage:
http://docs.phonegap.com/en/1.7.0/cordova_storage_storage.md.html#localStorage

Set icon:
In adroidManifest.xml:
<application android:icon="@drawable/icon_name" android:label="@string/app_name" >
.... 
</application> 
http://stackoverflow.com/questions/5350624/set-icon-for-android-application

Change app name:
Make sure the project name is same as app name or change label in Androidmanifest.xml:
android:label="vTasters"


1. Test local storage
2. use android camera

Saturday, March 8, 2014

Ant打包简介

Ant详细介绍: http://www.cnblogs.com/hoojo/archive/2013/06/14/java_ant_project_target_task_run.html


Download the zip file:
http://www.apache.org/dist/ant/binaries/


http://www.cnblogs.com/hoojo/archive/2013/06/14/java_ant_project_target_task_run.html

Wednesday, March 5, 2014

MonkeyRunner简介(2)

如果是第三方app, Monkeyruuner 不能install这个package,所以必须用actual device进行测试


Decryption:
Now we decrypt the AndroidManifest.xml to get the package and main activity name
In CMD, execute:
apktool.jar d Pandora_apkfiles.com.apk ./Pandora

after decrypted, open the xml and search keyword: package and LAUNCHER and find the activity name=android:name
package: com.pandora.android
entry activity: .Main

Jython code:
Now we can put this into the Jython code
device.startActivity(component="com.pandora.android/.Main")


If the installation can't be done, you can ignore this statement:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
device = MonkeyRunner.waitForConnection()
device.startActivity(component="com.pandora.android/.Main")

If the connection is wrong or it might connects to emulator:
Run your custom android app and see where it launches

MonkeyRunner operations:
http://developer.android.com/tools/help/MonkeyDevice.html

Android key events:
http://developer.android.com/reference/android/view/KeyEvent.html

Final test:
This is to launch the installed Pandora and sign in with an existing user
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
device = MonkeyRunner.waitForConnection()
device.startActivity(component="com.pandora.android/.Main")
MonkeyRunner.sleep(10)
device.type('aaa413@gmail.com')
MonkeyRunner.sleep(2)
device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP')
MonkeyRunner.sleep(2)
device.type('111111')
MonkeyRunner.sleep(2)
device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP')
MonkeyRunner.sleep(2)
device.press("DPAD_CENTER", MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(2)
result=device.takeSnapshot()
result.writeToFile('C:/Users/KK/Documents/Coding/Python/Test1_001.png','png')

关于MonkeyRunner的基本设置请参见MonkeyRunner简介(1)

Tuesday, March 4, 2014

MonkeyRunner简介(1)

MonkeyRunner是Android app的测试框架,可提供自动和app交互的功能,既然是测试框架,我们就可以用于收集数据。


安装:
1. PyDev Project (check updates to install it) [http://pydev.org/updates]. This is for python projects.
2. New a PyDev project->Project Type is JyPhon->Config interpreter->Download Jython lib (http://www.jython.org/downloads.html) [jython-standalone-2.5.3.jar]
3. Add monkeyRunner.jar to project: right click the proj->property->PyDev - PYTHONPATH->External libraries->add monkeyrunner.jar located in Android SDK path (open Android SDK manager[in window menu in eclipse] and SDK path and search it in this path)

Start to write your python code:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
in a .py file
or open PyDev Console [in the Console window] and put the code there






There is an error while you run "device = MonkeyRunner.waitForConnection()". It throws up NULL pointer error.
So I run it in MoneyRunner.bat with the python file
1. The batch file is in Android SDK path: C:\Users\KK\AppData\Local\Android\android-sdk\tools and you put your a.py file there.
2.  In cmd, run monkeyrunner a.py

a.py:
Snake:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
device = MonkeyRunner.waitForConnection()
device.installPackage('C:/Users/KK/Documents/Hard-Disk_bk/Backup/Study/coding/Java/Snake/bin/Snake.apk')
device.startActivity(component="com.example.android.snake/.Snake")
MonkeyRunner.sleep(5)
result=device.takeSnapshot()
result.writeToFile('C:\\Users\\KK\\Documents\\Coding\\Python\\Test1_001.png','png')
device.removePackage('com.example.android.snake') 

vTasters:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
device = MonkeyRunner.waitForConnection()
device.installPackage('C:/Users/KK/Documents/Hard-Disk_bk/Backup/Study/coding/Java/Snake/bin/vTasters-android.apk')
device.startActivity(component="com.vtasters/.ViewsMenu")
MonkeyRunner.sleep(5)
result=device.takeSnapshot()

result.writeToFile('C:\\Users\\KK\\Documents\\Coding\\Python\\Test1_001.png','png')



To fill out the package/activity name, you need to open the AndroidManifest.xml to check them out.
It will generate a snapshot for your device. Snake is an example app from Android.

Interact with your app:

device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP')
MonkeyRunner.sleep(2)
device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP')
MonkeyRunner.sleep(2)
device.press("DPAD_CENTER", MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(2)





It will select the second item in the menu and click it.
References:
http://www.cnblogs.com/yyangblog/archive/2011/03/10/1980086.html
http://www.cnblogs.com/findyou/p/3420936.html

Download the apk

http://www.apkfiles.com/apk-46/pandora-internet-radio

To decode the AndroidManifest.xml

From http://stackoverflow.com/questions/4191762/how-to-view-androidmanifest-xml-from-apk-file, download the apktool.jar

Execute in CMD: >apktool.jar d Pandora_apkfiles.com.apk ./Pandora
The AndroidManifest.xml will be decrypted.

下一篇将会介绍实际App的完整测试:MonkeyRunner简介(2)

Monday, March 3, 2014

怎么在actual device上Debug android app

条件:
1. 打开手机,打开它的USB debugging选项
2. 下载对应手机的driver

ADB: Android debug bridge
需要安装这个才行

For google device (i.e. Nexus 5):
1. Download Google USB driver here:   http://developer.android.com/sdk/win-usb.html
2. check device manager->find a device with question mark under Android phone->update driver by the downloaded file

For Samsung device (i.e. Galaxy Tab 2.0):
1. Download OEM driver for Samsung: http://developer.android.com/tools/extras/oem-usb.html
2. Install it
3. You will find ADB is installed under Android phone in device manager


After the installation, debug it now!
In eclipse, right click project->run as Android application/Run configurations