2016-01-18 35 views
1

我正在使用XCode 7.2試驗iOS的新UI測試框架。使用XCode 7.2錄製時XCUITest崩潰

我跟隨了一些教程,並觀看了來自Apple的演示視頻,並試圖記錄一些測試用例。當目標是「模擬器」時,第一次測試是成功的。當我嘗試在真正的設備中重複這些步驟時,XCode在啓動應用程序後立即崩潰。我使用Apple的iPhoneCoreDataRecipes演示應用程序開始使用簡單和「已驗證」的內容。

下面一個簡單的測試類:

#import <XCTest/XCTest.h> 

@interface RecipesUITests : XCTestCase 

@end 

@implementation RecipesUITests 

- (void)setUp { 
    [super 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. 
    [[[XCUIApplication alloc] 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. 
    [super tearDown]; 
} 

- (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 = [[XCUIApplication alloc] init]; 
    [app.navigationBars[@"Recipes"].buttons[@"Add"] tap]; 
    [app.textFields[@"Recipe Name"] typeText:@"Lef"]; 
    [app.navigationBars[@"Add Recipe"].buttons[@"Save"] tap]; 

    XCUIElementQuery *tablesQuery = app.tables; 
    XCUIElement *descriptionTextField = tablesQuery.textFields[@"Description"]; 
    [descriptionTextField tap]; 
    //[descriptionTextField tap]; 
    //[descriptionTextField tap]; 

    XCUIElement *lefNavigationBar = app.navigationBars[@"Lef"]; 
    [lefNavigationBar.buttons[@"Edit"] tap]; 

    XCUIElement *overviewTextField = tablesQuery.textFields[@"Overview"]; 
    [overviewTextField tap]; 
    //[overviewTextField typeText:@"Lef2"]; 
    [lefNavigationBar.buttons[@"Done"] tap]; 
    [lefNavigationBar.buttons[@"Recipes"] tap]; 


} 

它是一個已知的問題?有關如何調試問題的任何想法?我是否需要「以某種方式」啓用設備?

更新#1

當我試圖在設備運行測試用例,我收到的Xcode的一些日誌。

2016-01-19 13:18:36.772 XCTRunner[9331:2287347] Running tests... 
2016-01-19 13:18:36.776 XCTRunner[9331:2287347] 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[9331:2287347] 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[9331:2287347] 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[9331:2287347] Found configuration <XCTestConfiguration: 0x145e317d0> 
         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:<__NSConcreteUUID 0x145e235a0> 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 ***** 

看起來沒有任何反應,不執行測試用例時,Xcode嘗試加載應用程序,但黑屏

此外,當我試圖重新編碼的Xcode提供了以下崩潰:

Crashed Thread:  0 Dispatch 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: <IDEUIRecordingManager: 0x7fb40190c640> 
Method: -_workspaceTabController 
Thread: <NSThread: 0x7fb3fb519b00>{number = 1, name = main} 
Hints: None 
Backtrace: 
    0 0x0000000103e541fa -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:assertionSignature:messageFormat:arguments:] (in IDEKit) 
    1 0x00000001029e4761 _DVTAssertionHandler (in DVTFoundation) 
    2 0x00000001029e4978 _DVTAssertionFailureHandler (in DVTFoundation) 
    3 0x0000000103f3256b -[IDEUIRecordingManager _workspaceTabController] (in IDEKit) 
    4 0x0000000103f33433 __94-[IDEUIRecordingManager _startRecordingWithLaunchSession:alwaysAskForAPIAccess:reservedNames:]_block_invoke_2 (in IDEKit) 
    5 0x0000000102a20a04 __DVTDispatchAsync_block_invoke (in DVTFoundation) 
    6 0x00007fff8c97d8f5 _dispatch_call_block_and_release (in libdispatch.dylib) 
    7 0x00007fff8c9723c3 _dispatch_client_callout (in libdispatch.dylib) 
    8 0x00007fff8c985c1b _dispatch_main_queue_callback_4CF (in libdispatch.dylib) 
    9 0x00007fff986ac999 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ (in CoreFoundation) 
10 0x00007fff9866b9cd __CFRunLoopRun (in CoreFoundation) 
11 0x00007fff9866afc8 CFRunLoopRunSpecific (in CoreFoundation) 
12 0x00007fff8a5ead55 RunCurrentEventLoopInMode (in HIToolbox) 
13 0x00007fff8a5eab8f ReceiveNextEventCommon (in HIToolbox) 
14 0x00007fff8a5ea9cf _BlockUntilNextEventMatchingListInModeWithFilter (in HIToolbox) 
15 0x00007fff93319d96 _DPSNextEvent (in AppKit) 
16 0x00007fff933191c5 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] (in AppKit) 
17 0x0000000102fc00c2 -[DVTApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in DVTKit) 
18 0x00007fff9330dd28 -[NSApplication run] (in AppKit) 
19 0x00007fff932d6fbe NSApplicationMain (in AppKit) 
20 0x00007fff8fec85ad start (in libdyld.dylib) 

abort() called 

回答

2

我在黑暗中最好的射手:

IOS 8增強

iOS 8在Settings> Developer中包含一個新的Enable UI Automation首選項,允許第三方開發人員更好地控制其設備何時可用於執行自動化。對於物理iOS設備,默認情況下該設置處於關閉狀態,必須在執行任何UI自動化之前啓用該設置。在模擬器中,該設置默認啓用。

Source

這在較爲明顯的要求外(ios9目標,10.10/11等),該文件還列出了其他一些要求,並鏈接你可能會發現有用的參考。

+1

不幸的不是。我啓用了該選項,但是具有相同的行爲。 – cateof

+1

重新啓動手機後,它似乎工作。也許這會補充你的答案。 – cateof

+0

@cateof並不是說路易斯的答案沒有幫助,但我發現很多Xcode的UI測試錯誤可以通過重新啓動設備或通過Xcode>設備移除應用程序並重新安裝(例如,當您運行UI測試,它給你「成功」,甚至沒有運行任何東西,或記錄我也經歷過的崩潰) –

1

證實,使UI自動化和功率循環該設備不會允許蘋果的用戶界面測試在真實設備上運行。在Xcode 8 + iOS 10.1上測試。