2016-01-11 57 views
0


我知道MonkeyRunner是一种弃用,但我仍然有一个奇怪的问题。 如果我通过Monkeyrunner的触摸事件打开设置用户选项不存在,
如果我按照以下方法做同样的事情。Monkeyrunner以编程方式打开设置

FLAG_ACTIVITY_NEW_TASK = 0x10000000 
package = 'com.android.settings' 
activity='.Settings' 
runComponent = package + '/' + activity 
device.startActivity(component=runComponent, flags=FLAG_ACTIVITY_NEW_TASK) 

有谁知道为什么,或者如何让用户显示或打开使用MonkeyRunner? 运行Android v6.0.1。
谢谢,
尤金

回答

0

您可以使用AndroidViewClient/culebra来做到这一点。 这是一个culebra脚本稍加修改,以检查用户在滚动,但大部分是用Culebra GUI生成:此

#! /usr/bin/env python 
# -*- coding: utf-8 -*- 
''' 
Copyright (C) 2013-2014 Diego Torres Milano 
Created on 2016-01-11 by Culebra v11.0.8 
         __ __ __ __ 
        /\/\/\/\ 
____________________/ __\/ __\/ __\/ __\_____________________________ 
___________________/ /__/ /__/ /__/ /________________________________ 
        |/\ /\ /\ /\ \___ 
        |/ \_/ \_/ \_/ \ o \ 
              \_____/--< 
@author: Diego Torres Milano 
@author: Jennifer E. Swofford (ascii art snake) 
''' 


import re 
import sys 
import os 


import unittest 

from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase 

TAG = 'CULEBRA' 


class CulebraTests(CulebraTestCase): 

    @classmethod 
    def setUpClass(cls): 
     cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False} 
     cls.kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True} 
     cls.options = {'start-activity': None, 'concertina': False, 'device-art': None, 'use-jar': False, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'glare': False, 'dictionary-keys-from': 'id', 'scale': 0.5, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'log-actions': False, 'use-regexps': False, 'null-back-end': False, 'auto-regexps': None, 'do-not-verify-screen-dump': True, 'verbose-comments': False, 'gui': True, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': None, 'unit-test-method': None, 'interactive': False} 
     cls.sleep = 5 

    def setUp(self): 
     super(CulebraTests, self).setUp() 

    def tearDown(self): 
     super(CulebraTests, self).tearDown() 

    def preconditions(self): 
     if not super(CulebraTests, self).preconditions(): 
      return False 
     return True 

    def testSomething(self): 
     if not self.preconditions(): 
      self.fail('Preconditions failed') 

     _s = CulebraTests.sleep 
     _v = CulebraTests.verbose 

     self.vc.dump(window=-1) 
     self.vc.uiDevice.openQuickSettings() 
     self.vc.sleep(_s) 
     self.vc.dump(window=-1) 
     self.vc.findViewWithContentDescriptionOrRaise(u'''Settings''').touch() 
     self.vc.sleep(_s) 
     self.vc.dump(window=-1) 
     users = None 
     com_android_settings___id_dashboard = self.vc.findViewByIdOrRaise("com.android.settings:id/dashboard") 
     com_android_settings___id_dashboard.uiScrollable.flingToBeginning() 
     attempts = 10 
     while attempts > 0: 
      users = self.vc.findViewWithText(u'Users') 
      if users: 
       break 
      com_android_settings___id_dashboard.uiScrollable.flingForward() 
      self.vc.dump(window=-1) 
      self.vc.sleep(_s) 
      com_android_settings___id_dashboard = self.vc.findViewByIdOrRaise("com.android.settings:id/dashboard") 
      attempts -= 1 
     if not users: 
      self.fail("Users not found") 


if __name__ == '__main__': 
    CulebraTests.main() 
+0

你好,谢谢,但它好像通过monkeyrunner打开设置是hidding的用户菜单项,即使使用下拉菜单并单击配置文件图标,然后选择更多设置,使其显示空白用户设置页面。如果我手动转到任何设置项并返回,则会显示用户。我真的很想知道为什么或仅仅是我的设置? – Eugene