alibaba / tidevice

tidevice can be used to communicate with iPhone device
MIT License
2.43k stars 457 forks source link

调用set_text方法时候,wda经常莫名quited #73

Open ssfanli opened 3 years ago

ssfanli commented 3 years ago

现象

用tidevice起wda,在【直播底层页 - 多次发评论时候】wda服务经常会莫名quited,场景如下 image

尝试按照如下放开socket closed之前的错误信息,得到的堆栈如下: image

[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ["13:53:06.438 WebDriverAgentRunner-Runner[22962:4152260] Found matches {(\n    TextView, {{28.0, 479.0}, {358.0, 42.0}}, identifier: 'TBUIAutoTest_Property_inputCommentView', Keyboard Focused\n)} with root Application, pid: 22977, label: '央视频'\n"])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.438 WebDriverAgentRunner-Runner[22962:4152260] <XCTContext: 0x280227fc0> finished activity <XCActivityRecord: 0x283470000> 2021-04-18 05:53:05 +0000: Find the "TBUIAutoTest_Property_inputCommentView" TextView (0.444249s)\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_testCase:method:didFinishActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=2021-04-18 05:53:06.438379, start=2021-04-18 05:53:05.994130, title=Find the "TBUIAutoTest_Property_inputCommentView" TextView, uuid=300bb54b-6f71-4759-982a-25d918f23ab3)])
[D 210418 13:53:06 _instruments:611] server request not handled: ('_XCT_testCase:method:didFinishActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=2021-04-18 05:53:06.438379, start=2021-04-18 05:53:05.994130, title=Find the "TBUIAutoTest_Property_inputCommentView" TextView, uuid=300bb54b-6f71-4759-982a-25d918f23ab3)])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] <XCTContext: 0x280227fc0> started activity <XCActivityRecord: 0x283476710> 2021-04-18 05:53:06 +0000: Find the "TBUIAutoTest_Property_inputCommentView" TextView\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_testCase:method:willStartActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=None, start=2021-04-18 05:53:06.439494, title=Find the "TBUIAutoTest_Property_inputCommentView" TextView, uuid=cb87d56f-9731-4046-b519-0b8000a11d00)])
[D 210418 13:53:06 _instruments:611] server request not handled: ('_XCT_testCase:method:willStartActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=None, start=2021-04-18 05:53:06.439494, title=Find the "TBUIAutoTest_Property_inputCommentView" TextView, uuid=cb87d56f-9731-4046-b519-0b8000a11d00)])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Executing query:\n↪︎ Descendants matching type Any\n    ↪︎ Elements matching predicate \'wdName == "TBUIAutoTest_Property_inputCommentView" AND (1 == 1 OR identifier == 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0 OR selected == 0)\'\n        ↪︎ Identity Binding\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Should evaluate query remotely? XCTDisableRemoteQueryEvaluation(d-write): YES, hasAutomationSession: NO, supportsRemoteEvaluation: YES\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Getting matching snapshots for locally evaluated query\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Evaluating query:\n ↪︎ Descendants matching type Any\n    ↪︎ Elements matching predicate \'wdName == "TBUIAutoTest_Property_inputCommentView" AND (1 == 1 OR identifier == 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0 OR selected == 0)\'\n        ↪︎ Identity Binding\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Getting root element snapshot\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Getting snapshot for App element pid: 22977 for query ↪︎ Descendants matching type Any\n    ↪︎ Elements matching predicate \'wdName == "TBUIAutoTest_Property_inputCommentView" AND (1 == 1 OR identifier == 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0 OR selected == 0)\'\n        ↪︎ Identity Binding\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_testCase:method:willStartActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=None, start=2021-04-18 05:53:06.440209, title=Requesting snapshot of accessibility hierarchy for app with pid 22977, uuid=a444ddfe-1350-4f1e-b888-720683a3d867)])
[D 210418 13:53:06 _instruments:611] server request not handled: ('_XCT_testCase:method:willStartActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=None, start=2021-04-18 05:53:06.440209, title=Requesting snapshot of accessibility hierarchy for app with pid 22977, uuid=a444ddfe-1350-4f1e-b888-720683a3d867)])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] <XCTContext: 0x280227fc0> started activity <XCActivityRecord: 0x283474730> 2021-04-18 05:53:06 +0000: Requesting snapshot of accessibility hierarchy for app with pid 22977\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Query requires iOS snapshot attributes XC_kAXXCAttributeElementBaseType, XC_kAXXCAttributeFrame, XC_kAXXCAttributeElementType, XC_kAXXCAttributeIdentifier, XC_kAXXCAttributeValue, XC_kAXXCAttributeLabel, XC_kAXXCAttributeTraits, XC_kAXXCAttributePlaceholderValue.\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] XCUIElementQuery <XCTElementSnapshotProvider> getting snapshot\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Snapshot request has custom attributes XC_kAXXCAttributeElementBaseType, XC_kAXXCAttributeFrame, XC_kAXXCAttributeElementType, XC_kAXXCAttributeIdentifier, XC_kAXXCAttributeValue, XC_kAXXCAttributeLabel, XC_kAXXCAttributeTraits, XC_kAXXCAttributePlaceholderValue\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.440 WebDriverAgentRunner-Runner[22962:4152260] Current snapshot generation is 3109\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.441 WebDriverAgentRunner-Runner[22962:4152260] Query rootElementSnapshot is non-null with generation count 3109\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.441 WebDriverAgentRunner-Runner[22962:4152260] Capturing a new snapshot\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.441 WebDriverAgentRunner-Runner[22962:4152260] Fetching snapshot for App element pid: 22977 from testmanagerd with attributes XC_kAXXCAttributeElementBaseType, XC_kAXXCAttributeFrame, XC_kAXXCAttributeElementType, XC_kAXXCAttributeIdentifier, XC_kAXXCAttributeLabel, XC_kAXXCAttributeTraits, XC_kAXXCAttributeTruncatedValue, XC_kAXXCAttributeParent, XC_kAXXCAttributePlaceholderValue and parameters {\n    maxArrayCount = 2147483647;\n    maxChildren = 2147483647;\n    maxDepth = 50;\n    traverseFromParentsToChildren = 1;\n}.\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ["13:53:06.441 WebDriverAgentRunner-Runner[22962:4152260] Creating future for 'fetching snapshot from testmanagerd.' with timeout 65.00\n"])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.441 WebDriverAgentRunner-Runner[22962:4152260] <XCTWaiter: 0x283388180, state: XCTWaiterStateInProgress> entering wait loop for 65.00s with expectations: `fetching snapshot from testmanagerd.`\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.874 WebDriverAgentRunner-Runner[22962:4155376] Got snapshot response from testmanagerd.\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:0 flags:2 ('outputReceived:fromProcess:atTime:', ['    t =   521.06s     Find: Descendants matching type Any\n', 22962, 26508288801741])
[D 210418 13:53:06 _device:944] logProcess:     t =   521.06s     Find: Descendants matching type Any
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_testCase:method:didFinishActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=2021-04-18 05:53:06.874365, start=2021-04-18 05:53:06.440209, title=Requesting snapshot of accessibility hierarchy for app with pid 22977, uuid=a444ddfe-1350-4f1e-b888-720683a3d867)])
[D 210418 13:53:06 _instruments:611] server request not handled: ('_XCT_testCase:method:didFinishActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=2021-04-18 05:53:06.874365, start=2021-04-18 05:53:06.440209, title=Requesting snapshot of accessibility hierarchy for app with pid 22977, uuid=a444ddfe-1350-4f1e-b888-720683a3d867)])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.874 WebDriverAgentRunner-Runner[22962:4152260] <XCTContext: 0x280227fc0> finished activity <XCActivityRecord: 0x283474730> 2021-04-18 05:53:06 +0000: Requesting snapshot of accessibility hierarchy for app with pid 22977 (0.434156s)\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_testCase:method:willStartActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=None, start=2021-04-18 05:53:06.874707, title=Find: Descendants matching type Any, uuid=9a86c443-0b37-4446-ad44-04ef52b19ba1)])
[D 210418 13:53:06 _instruments:611] server request not handled: ('_XCT_testCase:method:willStartActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=None, start=2021-04-18 05:53:06.874707, title=Find: Descendants matching type Any, uuid=9a86c443-0b37-4446-ad44-04ef52b19ba1)])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.875 WebDriverAgentRunner-Runner[22962:4152260] XCTPerformOnMainRunLoop[MT]: already on MT; performing block without run loop dispatch - timeouts will not be enforced.\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.875 WebDriverAgentRunner-Runner[22962:4152260] XCTElementQuery: set data source for rootElementSnapshot to (null)\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.875 WebDriverAgentRunner-Runner[22962:4152260] Finding all matches with input Application, pid: 22977, label: \'央视频\' using transformers \n↪︎ Descendants matching type Any\n    ↪︎ Eents matching predicate \'wdName == "TBUIAutoTest_Property_inputCommentView" AND (1 == 1 OR identifier == 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0 OR selected == 0)\'\n        ↪︎ Identity Binding\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.875 WebDriverAgentRunner-Runner[22962:4152260] <XCTContext: 0x280227fc0> started activity <XCActivityRecord: 0x283499220> 2021-04-18 05:53:06 +0000: Find: Descendants matching type Any\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:0 flags:2 ('outputReceived:fromProcess:atTime:', ['    t =   521.07s     Find: Elements matching predicate \'wdName == "TBUIAutoTest_Property_inputCommentView" AND (1 == 1 OR identifier == 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0 OR selected == 0)\'\n', 22962, 26508288921858])
[D 210418 13:53:06 _device:944] logProcess:     t =   521.07s     Find: Elements matching predicate 'wdName == "TBUIAutoTest_Property_inputCommentView" AND (1 == 1 OR identifier == 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0 OR selected == 0)'
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_logDebugMessage:', ['13:53:06.876 WebDriverAgentRunner-Runner[22962:4152260] <XCTContext: 0x280227fc0> finished activity <XCActivityRecord: 0x283499220> 2021-04-18 05:53:06 +0000: Find: Descendants matching type Any (0.00103307s)\n'])
[D 210418 13:53:06 _instruments:592] DTXMessage: expects_reply:1 flags:2 ('_XCT_testCase:method:didFinishActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=2021-04-18 05:53:06.875740, start=2021-04-18 05:53:06.874707, title=Find: Descendants matching type Any, uuid=9a86c443-0b37-4446-ad44-04ef52b19ba1)])
[D 210418 13:53:06 _instruments:611] server request not handled: ('_XCT_testCase:method:didFinishActivity:', ['none', 'none', XCActivityRecord(activityType=com.apple.dt.xctest.activity-type.internal, attachments=[], finish=2021-04-18 05:53:06.875740, start=2021-04-18 05:53:06.874707, title=Find: Descendants matching type Any, uuid=9a86c443-0b37-4446-ad44-04ef52b19ba1)])
[W 210418 13:53:06 _instruments:560] unexpected error: read expect length: 0x22E64, got: 0x10526
[W 210418 13:53:06 _instruments:567] unexpected error 2: 'NoneType' object has no attribute 'conversation_index'
[D 210418 13:53:06 _instruments:570] dtxm socket closed
[I 210418 13:53:06 _device:1119] xctrunner quited

补充

调试代码如下:

import wda

if __name__ == '__main__':

    c = wda.USBClient()
    c.session('com.cctv.yangshipin.app.iphone')
    ipt = input('wait for ready ...')
    if ipt:
        n = 1
        while n < 50:
            # 用className定位,几乎不quited
            # c(className='XCUIElementTypeTextView').set_text('👏👏👏🌺🌺🍃%s' % n)
            # 用name定位,经常quited
            # p.s. TBUIAutoTest: http://yulingtianxia.com/blog/2016/03/28/Add-UITest-Label-for-UIAutomation/
            c(name='TBUIAutoTest_Property_inputCommentView').set_text('👏👏👏🌺🌺🍃%s' % n)
            n += 1

p.s. 评论框原始name属性为空,通过TBUIAutoTest插桩添加的属性

codeskyblue commented 3 years ago

这个issue写的好,各种需要的信息都有