菜鸟教程小白 发表于 2022-12-13 12:39:28

ios - 使用 Xcode 7.2 录制时 XCUITest 崩溃


                                            <p><p>我正在使用 Xcode 7.2 为 iOS 试验新的 UI 测试框架。</p>

<p>我遵循了一些教程并观看了 Apple 的演示视频并尝试记录一些测试用例。当目标是“模拟器”时,第一次测试成功。当我尝试在真实设备中重复这些步骤时,Xcode 在启动应用程序后立即崩溃。我用了<a href="https://developer.apple.com/library/ios/samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html" rel="noreferrer noopener nofollow">iPhoneCoreDataRecipes</a>来自 Apple 的演示应用程序,以便开始使用简单且“经过验证”的东西。 </p>

<p>下面是一个简单的测试类:</p>

<pre><code>#import &lt;XCTest/XCTest.h&gt;

@interface RecipesUITests : XCTestCase

@end

@implementation RecipesUITests

- (void)setUp {
    ;

    // Put setup code here. This method is called before the invocation of each test method in the class.

    // In UI tests it is usually best to stop immediately when a failure occurs.
    self.continueAfterFailure = NO;
    // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
    [[ init] launch];

    // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    ;
}

- (void)testExample {
    // Use recording to get started writing UI tests.
    // Use XCTAssert and related functions to verify your tests produce the correct results.


    XCUIApplication *app = [ init];
    .buttons[@&#34;Add&#34;] tap];
    typeText:@&#34;Lef&#34;];
    .buttons[@&#34;Save&#34;] tap];

    XCUIElementQuery *tablesQuery = app.tables;
    XCUIElement *descriptionTextField = tablesQuery.textFields[@&#34;Description&#34;];
    ;
    //;
    //;

    XCUIElement *lefNavigationBar = app.navigationBars[@&#34;Lef&#34;];
    tap];

    XCUIElement *overviewTextField = tablesQuery.textFields[@&#34;Overview&#34;];
    ;
    //;
    tap];
    tap];


}
</code></pre>

<p>这是一个已知问题吗?关于如何调试问题的任何想法?我需要“以某种方式”来启用设备吗?</p>

<p><strong>更新 #1</strong></p>

<p>当我尝试在设备中运行测试用例时,我在 Xcode 中收到了一些日志。</p>

<pre><code>2016-01-19 13:18:36.772 XCTRunner Running tests...
2016-01-19 13:18:36.776 XCTRunner Looking for test bundles in /var/mobile/Containers/Bundle/Application/42229178-A3D8-4BB1-A4CD-7E2FC28E90F9/RecipesUITests-Runner.app/PlugIns
2016-01-19 13:18:36.778 XCTRunner Found test bundle at /var/mobile/Containers/Bundle/Application/42229178-A3D8-4BB1-A4CD-7E2FC28E90F9/RecipesUITests-Runner.app/PlugIns/RecipesUITests.xctest
2016-01-19 13:18:36.780 XCTRunner Looking for configurations in /var/mobile/Containers/Bundle/Application/42229178-A3D8-4BB1-A4CD-7E2FC28E90F9/RecipesUITests-Runner.app/PlugIns/RecipesUITests.xctest
2016-01-19 13:18:36.784 XCTRunner Found configuration &lt;XCTestConfiguration: 0x145e317d0&gt;
                      testBundleURL:file:///Users/unifyit/Downloads/iPhoneCoreDataRecipes_3/Build/Products/Debug-iphoneos/RecipesUITests-Runner.app/PlugIns/RecipesUITests.xctest/
                  productModuleName:RecipesUITests
                        testsToSkip:(null)
                         testsToRun:RecipesUITests/testExample
               reportResultsToIDE:YES
                  sessionIdentifier:&lt;__NSConcreteUUID 0x145e235a0&gt; DD878763-999D-467F-968D-599B82EC5651
         pathToXcodeReportingSocket:(null)
          disablePerformanceMetrics:no
    treatMissingBaselinesAsFailures:no
                  baselineFileURL:(null)
            targetApplicationPath:/Users/unifyit/Downloads/iPhoneCoreDataRecipes_3/Build/Products/Debug-iphoneos/Recipes.app
          targetApplicationBundleID:com.example.apple-samplecode.Recipes
                   reportActivities:YES
         testsMustRunOnMainThread:YES
***** Begin XCTest Status Log *****
***** End XCTest Status Log *****
</code></pre>

<p>看起来什么都没有发生,没有执行测试用例,Xcode 尝试加载应用程序但它显示黑屏。</p>

<p>此外,当我尝试重新编码时,Xcode 会导致以下崩溃:</p>

<pre><code>Crashed Thread:      0Dispatch queue: com.apple.main-thread

Exception Type:      EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:      EXC_CORPSE_NOTIFY

Application Specific Information:
ProductBuildVersion: 7C68
ASSERTION FAILURE in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-9548/IDEKit/Testing/IDEUIRecordingManager.m:429
Details:(result) should not be nil.
Object:   &lt;IDEUIRecordingManager: 0x7fb40190c640&gt;
Method:   -_workspaceTabController
Thread:   &lt;NSThread: 0x7fb3fb519b00&gt;{number = 1, name = main}
Hints:   None
Backtrace:
00x0000000103e541fa - (in IDEKit)
10x00000001029e4761 _DVTAssertionHandler (in DVTFoundation)
20x00000001029e4978 _DVTAssertionFailureHandler (in DVTFoundation)
30x0000000103f3256b - (in IDEKit)
40x0000000103f33433 __94-_block_invoke_2 (in IDEKit)
50x0000000102a20a04 __DVTDispatchAsync_block_invoke (in DVTFoundation)
60x00007fff8c97d8f5 _dispatch_call_block_and_release (in libdispatch.dylib)
70x00007fff8c9723c3 _dispatch_client_callout (in libdispatch.dylib)
80x00007fff8c985c1b _dispatch_main_queue_callback_4CF (in libdispatch.dylib)
90x00007fff986ac999 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ (in CoreFoundation)
100x00007fff9866b9cd __CFRunLoopRun (in CoreFoundation)
110x00007fff9866afc8 CFRunLoopRunSpecific (in CoreFoundation)
120x00007fff8a5ead55 RunCurrentEventLoopInMode (in HIToolbox)
130x00007fff8a5eab8f ReceiveNextEventCommon (in HIToolbox)
140x00007fff8a5ea9cf _BlockUntilNextEventMatchingListInModeWithFilter (in HIToolbox)
150x00007fff93319d96 _DPSNextEvent (in AppKit)
160x00007fff933191c5 - (in AppKit)
170x0000000102fc00c2 - (in DVTKit)
180x00007fff9330dd28 - (in AppKit)
190x00007fff932d6fbe NSApplicationMain (in AppKit)
200x00007fff8fec85ad start (in libdyld.dylib)

abort() called
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我在黑暗中的最佳拍摄:</p>

<blockquote>
<p><em>IOS 8 ENHANCEMENT</em></p>

<p>iOS 8 includes a new Enable UI Automation preference under Settings &gt; Developer, which allows third-party developers finer control of when their devices are available to perform automation. For physical iOS devices, this setting is off by default and must be enabled prior to performing any UI Automation. In the simulator, the setting is enabled by default.</p>
</blockquote>

<p> <a href="https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UIAutomation.html" rel="noreferrer noopener nofollow">Source</a> </p>

<p>这是在更明显的要求(ios9 目标、10.10/11 等)之上的。该文档还列出了许多其他要求和链接,您可能会觉得对引用有帮助。 </p>

<p> <img src="/image/8Td6H.png" alt=""/> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 使用 Xcode 7.2 录制时 XCUITest 崩溃,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/34856924/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/34856924/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 使用 Xcode 7.2 录制时 XCUITest 崩溃