Monkey runner

Chuyên đề thảo luận về các công cụ hỗ trợ kiểm thử tự động.
Forum rules
Chuyên đề này chỉ thảo luận về Automation Testing Tool.
Để có kết quả nhanh, bạn nên search trước khi viết bài mới.
Post Reply
pichu
Hoc Tester
Posts: 2
Joined: Thu 21 Apr, 2016 9:31 am
Contact:

Monkey runner

Post by pichu » Mon 31 Oct, 2016 10:36 am

em chao anh/chi
em đang tìm hiểu về monkey runner, anh/chi có tài liệu gì về tool này ko share cho em mí
em cảm ơn



tvn
Admin
Posts: 4739
Joined: Tue 10 Aug, 2010 10:11 am
Location: HCM
Contact:

Re: Monkey runner

Post by tvn » Mon 31 Oct, 2016 8:35 pm

pichu wrote:em chao anh/chi
em đang tìm hiểu về monkey runner, anh/chi có tài liệu gì về tool này ko share cho em mí
em cảm ơn
Anh mới nghe về tool này luôn, anh tìm thấy một số thông tin có vẻ hữu ích cho em ở đây

http://androidtesting.blogspot.com/2012 ... ts-on.html

It looks like a big ask. But that is as simple as drinking a Sri Lankan Tea …
By following my previous posts

http://chanakaudaya.wordpress.com/2012/ ... -tutorial/
http://chanakaudaya.wordpress.com/2012/ ... l-part-ii/

Now you are running some scripts with monkeyrunner. Let’s add some little bit of information to that script.
#First you need to import the modules which you are using in this script
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

#Then you have to connect to the device which you are running your test
device = MonkeyRunner.waitForConnection()

Wait here !!!!!!

In this script you are waiting for a connection to a running android device or emulator implicitly. Rather than doing like that, you can explicitly tell what emulator or device you may need to connect. You can do that like this.

# Timeout value for waiting for connection 10 seconds

timeout = 10000# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection(timeout, “emulator-5554″)

here you specify which device you need to connect by the id of the emulator or device.
If you want to connect to another device within the same script, you can do like this

device2 = MonkeyRunner.waitForConnection(timeout, “emulator-5556″)

Then you can do all the operations you have done with device parameter to device2 parameter.
With this kind of scripting, you can run commands on as many devices you have with you. I believe in sample scripts in tutorials. Here is a sample script in action.

# Imports the monkeyrunner modules used by this program

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Timeout value for waiting for connection

timeout = 10000# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection(timeout, “emulator-5554″)

# Installs the Android package. Notice that this method returns a boolean, so
# you can test to see if the installation worked.
device.installPackage(‘/home/chanaka/workspace/SimpleIntentPreference/bin/SimpleIntentPreference.apk’)
# sets a variable with the package’s internal name
package = ‘com.chanaka.android.sip’
# sets a variable with the name of an Activity in the package
activity = ‘.SimpleIntentPreferenceActivity’
# sets the name of the component to start
runComponent = package + ‘/’ + activity
# Runs the component
device.startActivity(component=runComponent)
# Wait for few seconds
MonkeyRunner.sleep(2)
# Presses the Menu button
device.press(‘KEYCODE_MENU’, MonkeyDevice.DOWN_AND_UP)
# Wait for few seconds
MonkeyRunner.sleep(2)
#Touch the new status button
device.touch(160, 460, ‘DOWN_AND_UP’)
# Wait for few seconds
MonkeyRunner.sleep(2)
# Connects to the current device, returning a MonkeyDevice object
device2 = MonkeyRunner.waitForConnection(timeout, “emulator-5556″)
# Installs the Android package. Notice that this method returns a boolean, so
# you can test to see if the installation worked.
device2.installPackage(‘/home/chanaka/workspace/SimpleIntentPreference/bin/SimpleIntentPreference.apk’)
# sets a variable with the package’s internal name
package = ‘com.chanaka.android.sip’
# sets a variable with the name of an Activity in the package
activity = ‘.SimpleIntentPreferenceActivity’
# sets the name of the component to start
runComponent = package + ‘/’ + activity
# Runs the component
device2.startActivity(component=runComponent)
# Wait for few seconds
MonkeyRunner.sleep(2)
# Presses the Menu button
device2.press(‘KEYCODE_MENU’, MonkeyDevice.DOWN_AND_UP)
# Wait for few seconds
MonkeyRunner.sleep(2)
#Touch the new status button
device2.touch(160, 460, ‘DOWN_AND_UP’)
# Takes a screenshot
result = device.takeSnapshot()
# Wait for few seconds
MonkeyRunner.sleep(2)
# Writes the screenshot to a file
result.writeToFile(‘/home/chanaka/status_update.png’,'png’)
#Touch the first preference
device2.touch(160, 30, ‘DOWN_AND_UP’)
#Touch the entre button
device2.press(‘KEYCODE_DPAD_CENTER’, MonkeyDevice.DOWN_AND_UP)
# Takes a screenshot
result2 = device2.takeSnapshot()
# Writes the screenshot to a file
result2.writeToFile(‘/home/chanaka/shot1.png’,'png’)



pichu
Hoc Tester
Posts: 2
Joined: Thu 21 Apr, 2016 9:31 am
Contact:

Re: Monkey runner

Post by pichu » Tue 08 Nov, 2016 3:36 pm

em cảm ơn ạ



Post Reply

Return to “Automation Testing - Kiểm thử tự động”