TestHelper.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*****************************************************************************
  2. * TestHelper.swift
  3. * VLC for iOSUITests
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Mike JS. Choi <mkchoi212 # icloud.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. import Foundation
  13. import XCTest
  14. struct TestHelper {
  15. let localizationBundle: Bundle
  16. init(lang: String, target: AnyClass) {
  17. localizationBundle = TestHelper.loadLocalizables(lang: lang, target: target)
  18. }
  19. func localized(key: String) -> String {
  20. return NSLocalizedString(key, bundle: localizationBundle, comment: "")
  21. }
  22. func tap(tabDescription: String, app: XCUIApplication) {
  23. let target = app.tabBars.buttons.element(matching: .button, identifier: tabDescription)
  24. if target.exists {
  25. target.tap()
  26. } else if app.tabBars.buttons.count == 5 {
  27. // 5 tabBar buttons for iPhone
  28. let moreTab = app.tabBars.buttons.element(boundBy: 4)
  29. moreTab.tap()
  30. app.cells.staticTexts[tabDescription].tap()
  31. }
  32. }
  33. }
  34. extension TestHelper {
  35. static func loadLocalizables(lang: String, target: AnyClass) -> Bundle {
  36. let mainBundle = Bundle(for: target.self)
  37. guard let path = mainBundle.path(forResource: lang, ofType: ".lproj") else {
  38. XCTFail("Could not resolve localization file for \(lang)")
  39. return Bundle()
  40. }
  41. guard let bundle = Bundle(path: path) else {
  42. XCTFail("Could not load bundle at \(path)")
  43. return Bundle()
  44. }
  45. return bundle
  46. }
  47. }