Save 37% off PRO during our Black Friday Sale! »

UI testing in XCode7

UI testing in XCode7

503b1ca28b167b0d94a5992aad1a57b1?s=128

horimislime

June 30, 2015
Tweet

Transcript

  1. ✔ UI Testing in XCode7 Google I/O & WWDCใࠂձ@Fablic @horimislime

  2. ࣗݾ঺հ & ࿩͢͜ͱ • ɹ @horimislime • ɹ גࣜձࣾτϨλ •

    XCode7Ͱ௥Ճ͞ΕͨUI Testingͷ࿩Ͱ͢
  3. None
  4. ΍ͬͯΔ͜ͱ • BtoBࣄۀɻக໋తόά ≒ ܖ໿ղফ • ςετ΍Ζ͏ → KIFಋೖ΁ (WWDCલ)

    • UI Testingొ৔
  5. UI TestingͰԿ͕มΘΔ͔ʁ • جຊతʹ͸KIFͱࣅ͍ͯΔ • γϯϓϧͳAPIɻᙱ͍ͱ͜Ζʹख͕ಧ͖ͦ͏ • UI RecordingɾScreenShotͷࣗಈࡱӨ

  6. func testReserve() { // tester.tapViewWithAccessibilityLabel("৽ن༧໿") XCUIApplication().buttons["৽ن༧໿"].tap() }

  7. ίʔυ͸”جຊ”खॻ͖ෆཁ • UI RecordingͰSimulatorૢ࡞ɾίʔυੜ੒ • ViewͷAccessibilityLabelࢦఆ͕”΄΅”ෆཁ

  8. ίʔυ͸”جຊ”खॻ͖ෆཁ • UI RecordingͰSimulatorૢ࡞ɾίʔυੜ੒ • ViewͷAccessibilityLabelࢦఆ͕”΄΅”ෆཁ

  9. ͋͘·Ͱɺجຊతʹ͸ • AccessibilityLabelͷઃఆ͸ਪ঑͞ΕͯΔ • Label͕ແ͍ͱݫ͍͠έʔε΋ XCUIApplication().childrenMatchingType(.Window).elementAtIndex(0) .childrenMatchingType(.Unknown).elementAtIndex(0) .childrenMatchingType(.Unknown).elementAtIndex(0) .childrenMatchingType(.Unknown).elementAtIndex(0) .childrenMatchingType(.Unknown).elementAtIndex(0)

    .childrenMatchingType(.Unknown).elementAtIndex(1) .childrenMatchingType(.Unknown).elementAtIndex(0) .childrenMatchingType(.Button).elementAtIndex(0).tap()
  10. ScreenShotͷࣗಈࡱӨ • tap()ͳͲUIૢ࡞લʹը໘ΛࡱӨͯ͘͠ΕΔ

  11. xcodebuildͰ΋ $ xcodebuild 
 -workspace Toreta.xcworkspace 
 -scheme "Toreta UI

    Tests" 
 -destination 'platform=iOS Simulator,name=iPad Air 2,OS=9.0' 
 -derivedDataPath './output' test
  12. ίʔυ্ͰࡱӨ͸΋͏ཁΒͳ͍ʁ • Snapshot TestingΈ͍ͨͳࣄ͚ͨ͠Ε͹ݫ͍͠ • ը૾ϑΝΠϧ໊ͷࢦఆ͕Ͱ͖ͳ͍… • ςετຖʹը໘ͷࡱӨ͍͚ͨͩ͠ͳΒ

  13. ݸਓతʹخ͍͠ͱ͜Ζ • Simulatorͷىಈɾఀࢭ͕ίʔυ্ͰՄೳʹ • ࠔͬͯͨ͜ͱ
 - TOPը໘ˠઃఆը໘΁ͷભҠΛςετ
 - TOPը໘ˠ͓஌Βͤը໘΁ͷભҠΛςετ •

    ςετ։࢝࣌͸ΞϓϦىಈ௚ޙͷঢ়ଶʹ
  14. override func setUp() { … XCUIApplication().launch() } override func tearDown()

    { … XCUIApplication().terminate() }
  15. Simulator੍ޚ͕ॊೈʹ • ςετ։࢝࣌͸ΞϓϦ্ཱͪ͛ͨ௚ޙͷঢ়ଶ • tearDown()ͰTOP΁໭Δॲཧ͕ෆཁʹ • Simulatorͷىಈ৚݅΋ࢦఆՄೳ

  16. override func setUp() { super.setUp() let app = XCUIApplication() app.launch()

    }
  17. override func setUp() { super.setUp() let app = XCUIApplication() app.launchArguments

    += ["-AppleLanguages (English)"] app.launch() }
  18. ͜ΕΒΛ౿·͑ͯ • ৽نͰॻ͘UI Testʹ͸࢖ͬͯ΋͍͍͔΋ • ෳ਺ݴޠͰͷςετ͸AccessibilityLabelඞਢ
 - XCUIApplication().buttons[“ઃఆ”].tap() // Fail!!

    • KIFͰॻ͍ͨςετίʔυɺϓϥΠεϨε
  19. ·ͱΊ • XCode7͔ΒUIͷࣗಈςετ͕ڧԽ • FluentͳAPIɺSimulator΋ॊೈʹૢ࡞Մ • UI RecordingͰಋೖ΋ΧδϡΞϧʹ