How to control state in UI Test

Db5cf21a75ebe2484b95ea9dec5f573b?s=47 Shingo Tamaki
February 20, 2019

How to control state in UI Test

I considered what how to controll state in UI Test interactively.
This is summary of my idea.

Db5cf21a75ebe2484b95ea9dec5f573b?s=128

Shingo Tamaki

February 20, 2019
Tweet

Transcript

  1. XCUITestʹ͓͚Δঢ়ଶ ੍ޚʹ͍ͭͯߟ͑Δ

  2. XCUITestͱ͸ XCTestʹؚ·ΕΔUI Testingͷ௨শ ςετର৅ͷΞϓϦʹର͠ɺϢʔβͱಉ౳ͷૢ࡞Λߦ͏UIςε τͷͨΊͷػೳ

  3. ঢ়ଶʹ͍ͭͯ UIςετ͸ΑΓϢʔβʹ͍ۙܗͰςετର৅ΞϓϦΛϒϥοΫ ϘοΫεతʹૢ࡞͢ΔͨΊɺ ಺෦͔Βม਺΍ϝιουʹΞΫηε͠΍͍͢୯ମςετʹൺ΂ Δͱঢ়ଶΛ࡞Γʹ͍͘ͱݴ͑·͢ɻ

  4. ঢ়ଶ੍ޚͷྫ(XCTest) XCUIApplicationͷlaunchArguments΍launchEnvironmentΛ ࢖ͬͯىಈ࣌ʹઃఆ஋Λ༩͑Δ let app = XCUIApplication() app.launchArguments.append("loggedIn") app.launchArguments.append(contentsOf: ["-key",

    "abc111222333"]) app.launchArguments.append(contentsOf: ["-skipLogin", "YES"]) app.launchEnvironment["TestMode"] = "UITest"
  5. ঢ়ଶ੍ޚͷྫ(Target Application) ςετର৅ͷΞϓϦͰProcessInfoͷarguments,environment ͔Β஋ΛऔΓग़ͯ͠࢖༻͠·͢ɻ ProcessInfo.processInfo.arguments.contains("loggedIn") UserDefaults.standard.string(forKey: "key") UserDefaults.standard.bool(forKey: "skipLogin") ProcessInfo.processInfo.environment["TestMode"]

  6. ىಈ࣌ʹҰׅͰ༩͑Δ͔͠ͳ͍

  7. ! ىಈޙʹ΍Εͳ͍ͩΖ ͏͔ʁ

  8. ྫ͑͹͜Μͳ෩ʹ ౎౓ςετ͔Β஋ΛૹΓɺඞཁͳΒςετର৅͔Βड͚औΔ

  9. ݁࿦͔Β

  10. ग़དྷ·ͨ͠

  11. Darwin notifications

  12. Darwin notificationsͱ͸ʁ CϕʔεͷAPIͰɺΞϓϦؒΛ·͍ͨͰ௨஌ΛૹΔ͜ͱ͕ՄೳͰ ͢ ! MMWormholeͳͲʹ΋࢖ΘΕ͓ͯΓɺWatch΍Extensionͷ։ ൃΛͨ͠ࣄ͕͋Δਓ͸ฉ͍ͨ͜ͱ͕͋Δ͔΋͠Ε·ͤΜɻ

  13. ! ྑͦ͞͏

  14. Darwin notificationsͷΠϝʔδ

  15. Darwin notificationsͷ੍ݶ ௨஌ͷΈΛૹΓ·͢ɻ NotificationͷΑ͏ʹuserInfoͳͲ͕͋Γ·ͤΜ σʔλΛ΍ΓऔΓ͢ΔͷͰ͋Ε͹Կ͔ผͷ࢓૊Έ͕ඞཁʹͳΓ ·͢ !

  16. ͋͞Ͳ͏͠Α͏ʁ

  17. UIPasteboard

  18. UIPasteboard ΞϓϦؒͷ৘ใ࿈ܞͱͯ͠ڞ௨Ͱѻ͑ΔϦιʔεͱͯ͠ݕ౼͠ ͨதͰ࢖͍উख͕ྑͦ͞͏ͳ΋ͷͱͯ͠UIPasteboardΛ࢖ͬͯ ΈΔ͜ͱʹ͠·ͨ͠ɻ

  19. Telepathy

  20. Telepathy (Ծ)

  21. Sample Code(XCTest) let exp = XCTestExpectation(description: "normal") Telepathy.ask(with: "normal") {

    message in exp.fulfill() } wait(for: [exp], timeout: 5)
  22. Sample Code(Target Application) Telepathy.listen { (message) in if message ==

    "foo" { // something } Telepathy.answer() }
  23. ࣮ݱग़དྷ·ͨ͠Ͷʁ

  24. ऴΘΓʹ Telepathy͸·ͩΞΠσΟΞݕূஈ֊Ͱະެ։ͷϥΠϒϥϦͰ ͢ɻ ࣮ફʹ͋ͨΓ༗ޮͳϢʔεέʔεͳͲΛ໛ࡧͯ͠Δ࠷தͳͷͰ͝ ҙݟ͍͚ͨͩΔͱ޾͍Ͱ͢ɻ

  25. Ҏ্