• 来自Appium Python API 中文版 By-HZJ,在代码里面通过打印测试了,不管是否可见均返回 false

  • #5 楼 @ivy520 1.5.3 有更新些什么没

  • haha 有 debugtalk 的影子

  • #6 楼 @yyswly 恩恩

  • 总算是有杭州的活动啦

  • 解决方法:不能直接 tap 元素,只能 tap 对应的坐标才会有效,所以选择封装一个 tap 的方法

    class CustomDriver(webdriver.Remote):
    
        def hx_tap_element(self, element):
            location = element.location
            el_size = element.size
            return self.tap([(el_size['width'] / 2 + location['x'], el_size['height'] / 2 + location['y'],)])
    
        def hx_tap_element_with_name(self, name):
            el = self.find_element_by_name(name=name)
            return self.hx_tap_element(el)
    
        def hx_tap_element_with_name_sequence(self, sequence):
            return [self.hx_tap_element_with_name(name=name) for name in sequence]
    
        def hx_tap_element_with_name_args(self, *args):
            return [self.hx_tap_element_with_name(name=name) for name in args]
    
    def test_ihexin03(self):
        self.driver.find_element_by_name("交易").click()
        self.driver.find_element_by_name("模拟炒股").click()
        #self.driver.find_element_by_name("买入").click()
        self.driver.find_element_by_xpath(
            " //UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[3]/UIAButton[1]").click()
        sleep(2)
        self.driver.find_element_by_xpath(
            "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAScrollView[1]/UIATextField[1]").click()
        # sleep(2)
        # self.driver.hx_tap_element_with_name_sequence(('全仓', '1',))
        self.driver.hx_tap_element_with_name_sequence('600000')
        self.driver.find_element_by_xpath(
            "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAScrollView[1]/UIATextField[3]").click()
        sleep(2)
        self.driver.hx_tap_element_with_name_args('全仓', '半仓', '2/3仓')
    
    
  • #7 楼 @xuexi123 我做 iOS 这边的自动化,没有遇到什么兼容性问题

  • 原来我们研究的 APP 差不多嘛,都是与股票有关的,可以多一些交流

  • #8 楼 @xinufo 贴个 api 链接

  • #3 楼 @fengliuyishao 恩恩,滑动问题我也打算这么做,能提供下代码参考么

  • #4 楼 @fengliuyishao xpath 也是不行

  • #3 楼 @pacerron 嗯嗯,试了一下 set_value 报出下面的错误
    脚本内容:

    def test_ihexin03(self):
        self.driver.find_element_by_accessibility_id("自选").click()
        self.driver.find_element_by_accessibility_id("搜索").click()
        sleep(2)
    
        # 点击键盘输入股票代码“600004”
        #self.driver.find_element_by_accessibility_id("6").click()
        #self.driver.find_element_by_accessibility_id("0").click()
        #self.driver.find_element_by_accessibility_id("0").click()
        #self.driver.find_element_by_accessibility_id("0").click()
        #self.driver.find_element_by_accessibility_id("0").click()
        #self.driver.find_element_by_accessibility_id("0").click()
        #self.driver.find_element_by_accessibility_id("4").click()
    
        self.driver.set_value(60004)
        #el = self.driver.find_element_by_accessibility_id('6')
        #action = TouchAction(self.driver)
        #action.tap(el).perform()
    
        sleep(5)
    
    

    终端报错:

    HeminWon-Extranet:~ Hm$ python /Users/Hm/Desktop/ITestSwipe0713.py
    test_ihexin03 (__main__.ComplexIOSTests) ... ERROR
    
    ======================================================================
    ERROR: test_ihexin03 (__main__.ComplexIOSTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/Hm/Desktop/ITestSwipe0713.py", line 78, in test_ihexin03
        self.driver.set_value(60004)
    TypeError: set_value() takes exactly 3 arguments (2 given)
    
    ----------------------------------------------------------------------
    Ran 1 test in 33.931s
    
    FAILED (errors=1)
    

    app 关键日志:

    info: --> POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element {"using":"accessibility id","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae","value":"自选"}
    info: [debug] Waiting up to 0ms for condition
    info: [debug] Pushing command to appium work queue: "au.getElementByAccessibilityId('自选')"
    info: [debug] Sending command to instruments: au.getElementByAccessibilityId('自选')
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:29 oumeikai IHexin[1495] <Warning>: DEBUG: setData: InstanceId=1, FrameId=2790, RealData=0
    
    info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: Got new command 3 from instruments: au.getElementByAccessibilityId('自选')
    
    info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: evaluating au.getElementByAccessibilityId('自选')
    
    info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: evaluation finished
    
    info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: Lookup returned [object UIAButton] with the name "自选" (id: 0).
    
    info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: responding with:
    info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: Running system command #4: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"ELEMENT":"0"}}...
    
    info: [debug] Socket data received (38 bytes)
    
    info: [debug] Socket data being routed.
    info: [debug] Got result from instruments: {"status":0,"value":{"ELEMENT":"0"}}
    info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"0"},"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    info: <-- POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element 200 1465.546 ms - 87 {"status":0,"value":{"ELEMENT":"0"},"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    info: --> POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element/0/click {"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae","id":"0"}
    info: [debug] Pushing command to appium work queue: "au.tapById('0')"
    info: [debug] Sending command to instruments: au.tapById('0')
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:31 oumeikai MobileGestaltHelper[1409] <Error>: libMobileGestalt MobileGestalt.c:281: server_access_check denied access to question UniqueDeviceID for pid 1496
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:31 oumeikai ScriptAgent[1496] <Error>: libMobileGestalt MobileGestaltSupport.m:151: pid 1496 (ScriptAgent) does not have sandbox access for re6Zb+zwFKJNlkQTUeT+/w and IS NOT appropriately entitled
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:31 oumeikai ScriptAgent[1496] <Error>: libMobileGestalt MobileGestalt.c:542: no access to UniqueDeviceID (see <rdar://problem/11744455>)
    
    info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: Got new command 4 from instruments: au.tapById('0')
    
    info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: evaluating au.tapById('0')
    
    info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: UIAButton.tap()
    
    info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: evaluation finished
    
    info: [debug] Socket data received (25 bytes)
    
    info: [debug] Socket data being routed.
    info: [debug] Got result from instruments: {"status":0,"value":""}
    info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    
    info: <-- POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element/0/click 200 1182.725 ms - 74 {"status":0,"value":"","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    info: --> POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element {"using":"accessibility id","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae","value":"搜索"}
    info: [debug] Waiting up to 0ms for condition
    info: [debug] Pushing command to appium work queue: "au.getElementByAccessibilityId('搜索')"
    info: [debug] Sending command to instruments: au.getElementByAccessibilityId('搜索')
    info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: responding with:
    info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: Running system command #5: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: DEBUG: RequestFlush: FrameId=2201, Content:
    
    info: [IOS_SYSLOG_ROW ] [frame]
    info: [IOS_SYSLOG_ROW ] id=2201
    info: [IOS_SYSLOG_ROW ] pageList=10002,10006
    info: [IOS_SYSLOG_ROW ] reqPage=10006
    info: [IOS_SYSLOG_ROW ] reqPageCount=1
    info: [IOS_SYSLOG_ROW ] [10006]
    info: [IOS_SYSLOG_ROW ] id=1264
    info: [IOS_SYSLOG_ROW ] startrow=0
    info: [IOS_SYSLOG_ROW ] rowcount=17
    info: [IOS_SYSLOG_ROW ] columnorder=55|10|34818|34821|48|13|34312|34311|34304|34305|49|7|6|8|9|53|34819|4|34393|34338|
    info: [IOS_SYSLOG_ROW ] sortid=-1
    info: [IOS_SYSLOG_ROW ] sortorder=1
    info: [IOS_SYSLOG_ROW ] newrealtime=1
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: DEBUG: setData: InstanceId=10006, FrameId=2201, RealData=0
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: DEBUG: RequestImm: FrameId=9001, Content:
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: [frame]
    info: [IOS_SYSLOG_ROW ] id=9001
    info: [IOS_SYSLOG_ROW ] pageList=10002,10006,10007
    info: [IOS_SYSLOG_ROW ] reqPage=10007
    info: [IOS_SYSLOG_ROW ] reqPageCount=1
    info: [IOS_SYSLOG_ROW ] [10007]
    info: [IOS_SYSLOG_ROW ] id=1201
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: DEBUG: setData: InstanceId=10007, FrameId=2201, RealData=0
    
    info: [debug] [INST] 2016-07-21 06:34:32 +0000 Debug: Got new command 5 from instruments: au.getElementByAccessibilityId('搜索')
    
    info: [debug] [INST] 2016-07-21 06:34:32 +0000 Debug: evaluating au.getElementByAccessibilityId('搜索')
    
    info: [debug] [INST] 2016-07-21 06:34:33 +0000 Debug: evaluation finished
    
    info: [debug] [INST] 2016-07-21 06:34:33 +0000 Debug: Lookup returned [object UIAButton] with the name "搜索" (id: 1).
    
    info: [debug] [INST] 2016-07-21 06:34:33 +0000 Debug: responding with:
    info: [debug] [INST] 2016-07-21 06:34:33 +0000 Debug: Running system command #6: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"ELEMENT":"1"}}...
    
    info: [debug] Socket data received (38 bytes)
    
    info: [debug] Socket data being routed.
    info: [debug] Got result from instruments: {"status":0,"value":{"ELEMENT":"1"}}
    info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    
    info: <-- POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element 200 1581.437 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    info: --> POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element/1/click {"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae","id":"1"}
    info: [debug] Pushing command to appium work queue: "au.tapById('1')"
    info: [debug] Sending command to instruments: au.tapById('1')
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai MobileGestaltHelper[1409] <Error>: libMobileGestalt MobileGestalt.c:281: server_access_check denied access to question UniqueDeviceID for pid 1496
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai ScriptAgent[1496] <Error>: libMobileGestalt MobileGestaltSupport.m:151: pid 1496 (ScriptAgent) does not have sandbox access for re6Zb+zwFKJNlkQTUeT+/w and IS NOT appropriately entitled
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai ScriptAgent[1496] <Error>: libMobileGestalt MobileGestalt.c:542: no access to UniqueDeviceID (see <rdar://problem/11744455>)
    
    info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: Got new command 6 from instruments: au.tapById('1')
    
    info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: evaluating au.tapById('1')
    
    info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: UIAButton.tap()
    
    info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: evaluation finished
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai IHexin[1495] <Warning>: StopRealData:
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai IHexin[1495] <Warning>: [frame]
    info: [IOS_SYSLOG_ROW ] id=2201
    info: [IOS_SYSLOG_ROW ] pageList=
    
    info: [debug] Socket data received (25 bytes)
    
    info: [debug] Socket data being routed.
    info: [debug] Got result from instruments: {"status":0,"value":""}
    info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    info: <-- POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element/1/click 200 1271.332 ms - 74 {"status":0,"value":"","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:35 oumeikai SpringBoard[58] <Warning>: [<_UIKeyboardArbiterHandle: 0x1307ac0e0; PID 177: (null) <(null)>; hosting PIDs {(
    
    info: [IOS_SYSLOG_ROW ] )}; level 0.000000; active NO [wants NO]; suppression 0>] could not take process assertion
    
    info: --> DELETE /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae {}
    
    info: Shutting down appium session
    info: [debug] Stopping ios
    info: [debug] Destroying instruments client socket.
    info: [debug] Closing socket server.
    info: [debug] Instruments socket server was closed
    info: [debug] Sending sigterm to instruments
    
    info: [debug] [INST] 2016-07-21 06:34:36 +0000 Stopped: Script was stopped by the user
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai SpringBoard[58] <Warning>: HW kbd: Failed to set (null) as keyboard focus
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai SpringBoard[58] <Warning>: HW kbd: Failed to set (null) as keyboard focus
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai SpringBoard[58] <Warning>: UNNotificationRegistrarConnectionListener connection invalidated
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai kbd[1350] <Warning>: __38-[TIWordSearch saveLearningDictionary]_block_invoke  Calling MecabraFlushDynamicData
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai com.apple.xpc.launchd[1] (UIKitApplication:cn.com.10jqka.IHexin[0x5316][1495]) <Notice>: Service exited due to signal: Killed: 9
    
    info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: responding with:
    info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: Running system command #7: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
    
    info: [debug] [INST STDERR] 2016-07-21 14:34:36.882 instruments[5634:135901] Attempting to change event horizon while disengage
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai SpringBoard[58] <Warning>: Application 'UIKitApplication:cn.com.10jqka.IHexin[0x5316]' exited abnormally via signal.
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai UserEventAgent[26] <Warning>: 1883645281118: id=cn.com.10jqka.IHexin pid=1495, state=0
    
    info: [IOS_SYSLOG_ROW ] Jul 21 14:34:38 oumeikai locationd[64] <Notice>: need a scan, count, 0, 0, lwatchdog, 0.0, interval, 60.0, needWatchdog, 0
    
    info: [debug] [INST] Instruments Trace Complete (Duration : 17.896297s; Output : /tmp/appium-instruments/instrumentscli0.trace)
    
    info: [debug] [INSTSERVER] Instruments exited with code 0
    
    info: [debug] Cleaning up after instruments exit
    info: [debug] Stopping iOS log capture
    info: [debug] Running ios sim reset flow
    info: [debug] Killing the simulator process
    info: [debug] Killing any other simulator daemons
    
    info: [debug] Killall iOS Simulator
    
    info: [debug] On a real device; cannot clean device state
    info: [debug] Cleaning up appium session
    info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    info: <-- DELETE /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae 200 2758.087 ms - 76 {"status":0,"value":null,"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
    
    info: --> GET /wd/hub/status {}
    

    请问下这个问题这么解决呢?

  • #1 楼 @pacerron setvlaue 不行,好像说是安卓专用的方法,今天打算尝试另外一种解决方法

  • #4 楼 @wangnima 请问这个问题有比较好的解决方式啦么

  • self.driver.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 2, "x": 181, "y": 192 })
    长按手势 mac 上录制的代码可以使用

  • #18 楼 @mads 额嗯呢,才知道时间是毫秒,截图分享的问题什么时候出来啊

  • #6 楼 @chenhengjie123 恩恩,去掉后解决

  • #coding:utf-8
    """
    More involved iOS tests, using UICatalog application.
    """
    import unittest
    import os
    import random
    import string
    from appium import webdriver
    from appium.webdriver.common.touch_action import TouchAction
    # from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.common.touch_actions import TouchActions
    # from selenium.webdriver.common.keys import Keys
    import urllib2
    import json
    from time import sleep
    
    # =================
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    # =================
    
    def str_generator(size=6, chars=string.ascii_uppercase + string.digits):
        return ''.join(random.choice(chars) for x in range(size))
    
    
    class ComplexIOSTests(unittest.TestCase):
    
        def setUp(self):
            # set up appium
            # ** Important Note **
            # Make sure you have build the UICatalog applcation in your local repository
            #app = os.path.join(os.path.dirname(__file__),
            #                   '../../Desktop/UICatalog/build/release-iphonesimulator',
            #                   'UICatalog.app')
            #app = os.path.abspath(app)
    
            #app = os.path.abspath('/Users/hulianghai/Desktop/Test/build/Debug-iphonesimulator/UICatalog.app')
    
            app = "cn.com.10jqka.IHexin"
            self.driver = webdriver.Remote(
                command_executor='http://127.0.0.1:4723/wd/hub',
                desired_capabilities={
                    'app': app,
                    'udid': '57e95712fdd52a1fce030ed46808f1a98e9b2f5e',
                    'platformName': 'iOS',
                    #'platformName': '',
                    'platformVersion': '9.3',
                    'deviceName': 'iPhone 6'
                })
            self._values = []
    
        def tearDown(self):
            self.driver.quit()
    
    
        def test_ihexin03(self):
            self.driver.swipe(start_x = 41, start_y = 577, end_x = 52, end_y = 228, duration = 1000 )
    
    
    suite = unittest.TestLoader().loadTestsFromTestCase(ComplexIOSTests)
    unittest.TextTestRunner(verbosity=2).run(suite)
    

    终端报错如下

    HeminWon-Extranet:~ Hm$ python /Users/Hm/Desktop/ITest0704.py
    test_ihexin03 (__main__.ComplexIOSTests) ... ERROR
    
    ======================================================================
    ERROR: test_ihexin03 (__main__.ComplexIOSTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/Hm/Desktop/ITest0704.py", line 73, in test_ihexin03
        self.driver.swipe(start_x = 41, start_y = 577, end_x = 52, end_y = 228, duration = 1000 )
    AttributeError: 'WebDriver' object has no attribute 'swipe'
    
    
    
  • 现在我也遇到这个问题,请问没有是在 appium 文件夹下面是什么意思

  • #6 楼 @mads 😪 我是开发,职位不符,最近公司让给测试做一款工具才研究的自动化,这方面没什么经验。

  • 哈哈哈

  • 公式内网环境可以使用么?