Commit 731460bc authored by Mike JS. Choi's avatar Mike JS. Choi

[UI] Modify iOS test cases for iPad

iOS test cases are now compatible with both iPhone and iPad.
parent a19889e9
/*****************************************************************************
* LocaleHelper.swift
* TestHelper.swift
* VLC for iOSUITests
*****************************************************************************
* Copyright (c) 2018 VideoLAN. All rights reserved.
......@@ -13,21 +13,34 @@
import Foundation
import XCTest
struct LocaleHelper {
struct TestHelper {
let localizationBundle: Bundle
let inherantBundle = Bundle(for: UIApplication.self)
init(lang: String, target: AnyClass) {
localizationBundle = LocaleHelper.loadLocalizables(lang: lang, target: target)
localizationBundle = TestHelper.loadLocalizables(lang: lang, target: target)
}
func localized(key: String) -> String {
let res = NSLocalizedString(key, bundle: localizationBundle, comment: "")
return res
}
func tap(tabDescription: String, app: XCUIApplication) {
let target = app.tabBars.buttons.element(matching: .button, identifier: tabDescription)
if target.exists {
target.tap()
} else if app.tabBars.buttons.count == 5 {
// 5 tabBar buttons for iPhone
let moreTab = app.tabBars.buttons.element(boundBy: 4)
moreTab.tap()
app.cells.staticTexts[tabDescription].tap()
}
}
}
extension LocaleHelper {
extension TestHelper {
static func loadLocalizables(lang: String, target: AnyClass) -> Bundle {
let mainBundle = Bundle(for: target.self)
guard let path = mainBundle.path(forResource: lang, ofType: ".lproj") else {
......
......@@ -15,20 +15,20 @@ import XCTest
class VLCiOSTestMenu: XCTestCase {
let app = XCUIApplication()
let helper = LocaleHelper(lang: deviceLanguage, target: VLCiOSTestVideoCodecs.self)
let moreTab = XCUIApplication().tabBars.buttons.element(boundBy: 4)
var helper: TestHelper!
override func setUp() {
super.setUp()
XCUIDevice.shared.orientation = .portrait
setupSnapshot(app)
helper = TestHelper(lang: deviceLanguage, target: VLCiOSTestMenu.self)
app.launch()
}
func testNavigationToAudioTab() {
let audio = helper.localized(key: "AUDIO")
app.tabBars.buttons[audio].tap()
helper.tap(tabDescription: audio, app: app)
XCTAssertNotNil(app.navigationBars[audio])
snapshot("audio_tab")
......@@ -36,54 +36,46 @@ class VLCiOSTestMenu: XCTestCase {
func testNavigationToNetworkTab() {
let localNetwork = helper.localized(key: "LOCAL_NETWORK")
app.tabBars.buttons[localNetwork].tap()
helper.tap(tabDescription: localNetwork, app: app)
XCTAssertNotNil(app.navigationBars[localNetwork])
snapshot("network_tab")
}
func testNavigationToVideoTab() {
app.tabBars.buttons["Video"].tap()
helper.tap(tabDescription: "Video", app: app)
XCTAssertNotNil(app.navigationBars["Video"])
snapshot("video_tab")
}
func testNavigationToSettingsTab() {
let settings = helper.localized(key: "Settings")
app.tabBars.buttons[settings].tap()
helper.tap(tabDescription: settings, app: app)
XCTAssertNotNil(app.navigationBars[settings])
}
func testNavigationToCloudServices() {
moreTab.tap()
let cloudServices = helper.localized(key: "CLOUD_SERVICES")
app.cells.staticTexts[cloudServices].tap()
helper.tap(tabDescription: cloudServices, app: app)
XCTAssertNotNil(app.navigationBars[cloudServices])
}
func testNavigationToDownloads() {
moreTab.tap()
let downloads = helper.localized(key: "DOWNLOAD_FROM_HTTP")
app.cells.staticTexts[downloads].tap()
helper.tap(tabDescription: downloads, app: app)
XCTAssertNotNil(app.navigationBars[downloads])
}
func testNavigationToNetworkStream() {
moreTab.tap()
let network = helper.localized(key: "OPEN_NETWORK")
app.cells.staticTexts[network].tap()
helper.tap(tabDescription: network, app: app)
XCTAssertNotNil(app.navigationBars[network])
}
func testNavigationToAbout() {
moreTab.tap()
let about = helper.localized(key: "ABOUT_APP")
app.cells.staticTexts[about].tap()
helper.tap(tabDescription: about, app: app)
XCTAssertNotNil(app.navigationBars[about])
}
}
......@@ -15,22 +15,23 @@ import XCTest
class VLCiOSTestVideoCodecs: XCTestCase {
let app = XCUIApplication()
let helper = LocaleHelper(lang: deviceLanguage, target: VLCiOSTestVideoCodecs.self)
let moreTab = XCUIApplication().tabBars.buttons.element(boundBy: 4)
var helper: TestHelper!
override func setUp() {
super.setUp()
XCUIDevice.shared.orientation = .portrait
setupSnapshot(app)
helper = TestHelper(lang: deviceLanguage, target: VLCiOSTestVideoCodecs.self)
app.launch()
}
func testDownload() {
download(name: "http://jell.yfish.us/media/jellyfish-10-mbps-hd-h264.mkv")
app.tabBars.buttons["Video"].tap()
helper.tap(tabDescription: "Video", app: app)
app.collectionViews.cells.element(boundBy: 0).tap()
app.navigationBars["VLCMovieView"].buttons[helper.localized(key: "VIDEO_ASPECT_RATIO_BUTTON")].tap()
snapshot("playback")
}
......@@ -51,8 +52,8 @@ class VLCiOSTestVideoCodecs: XCTestCase {
}
func download(name fileName: String) {
moreTab.tap()
app.staticTexts[helper.localized(key: "DOWNLOAD_FROM_HTTP")].tap()
let download = helper.localized(key: "DOWNLOAD_FROM_HTTP")
helper.tap(tabDescription: download, app: app)
let downloadTextfield = app.textFields["http://myserver.com/file.mkv"]
downloadTextfield.clearAndEnter(text: fileName)
......@@ -69,14 +70,13 @@ class VLCiOSTestVideoCodecs: XCTestCase {
}
func stream(named fileName: String) {
moreTab.tap()
app.staticTexts[helper.localized(key: "OPEN_NETWORK")].tap()
let stream = helper.localized(key: "OPEN_NETWORK")
helper.tap(tabDescription: stream, app: app)
let addressTextField = app.textFields["http://myserver.com/file.mkv"]
addressTextField.clearAndEnter(text: fileName)
app.buttons[helper.localized(key: "OPEN_NETWORK")].tap()
app.otherElements.children(matching: .button)[helper.localized(key: "OPEN_NETWORK")].tap()
let displayTime = app.navigationBars["VLCMovieView"].buttons["--:--"]
let zeroPredicate = NSPredicate(format: "exists == 0")
expectation(for: zeroPredicate, evaluatedWith: displayTime, handler: nil)
......
......@@ -249,7 +249,7 @@
CAA0B0EF2072651800B9274E /* VLCiOSTestVideoCodecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAF76D9120709C7000E2AD7B /* VLCiOSTestVideoCodecs.swift */; };
CAA0B0F02072651A00B9274E /* XCUIElement+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAF76D9320709C9500E2AD7B /* XCUIElement+Helpers.swift */; };
CAA0B0F52072686E00B9274E /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A79246C6170F11DF0036AAF2 /* Localizable.strings */; };
CAA0B0F720726A0E00B9274E /* LocaleHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA0B0F620726A0E00B9274E /* LocaleHelper.swift */; };
CAA0B0F720726A0E00B9274E /* TestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA0B0F620726A0E00B9274E /* TestHelper.swift */; };
CAF76D9520709CDE00E2AD7B /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A79246C6170F11DF0036AAF2 /* Localizable.strings */; };
CC1BBC461704938300A20CBF /* libiconv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CC1BBC451704938300A20CBF /* libiconv.dylib */; };
CC1BBC4C1704939B00A20CBF /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CC1BBC4B1704939B00A20CBF /* libsqlite3.dylib */; };
......@@ -945,7 +945,7 @@
A79246C9170F11E40036AAF2 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
AC40202FFE42CEDCEB37E50D /* Pods-VLC-tvOS.distribution.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VLC-tvOS.distribution.xcconfig"; path = "Pods/Target Support Files/Pods-VLC-tvOS/Pods-VLC-tvOS.distribution.xcconfig"; sourceTree = "<group>"; };
C6872E7B396534F3DAF4E48F /* Pods-VLC-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VLC-iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-VLC-iOS/Pods-VLC-iOS.release.xcconfig"; sourceTree = "<group>"; };
CAA0B0F620726A0E00B9274E /* LocaleHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocaleHelper.swift; sourceTree = "<group>"; };
CAA0B0F620726A0E00B9274E /* TestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHelper.swift; sourceTree = "<group>"; };
CAF76D8D20709BE400E2AD7B /* SnapshotHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SnapshotHelper.swift; path = fastlane/SnapshotHelper.swift; sourceTree = SOURCE_ROOT; };
CAF76D8F20709C4100E2AD7B /* VLCiOSTestMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCiOSTestMenu.swift; sourceTree = "<group>"; };
CAF76D9120709C7000E2AD7B /* VLCiOSTestVideoCodecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCiOSTestVideoCodecs.swift; sourceTree = "<group>"; };
......@@ -1239,7 +1239,7 @@
CAF76D8D20709BE400E2AD7B /* SnapshotHelper.swift */,
CAF76D8F20709C4100E2AD7B /* VLCiOSTestMenu.swift */,
CAF76D9120709C7000E2AD7B /* VLCiOSTestVideoCodecs.swift */,
CAA0B0F620726A0E00B9274E /* LocaleHelper.swift */,
CAA0B0F620726A0E00B9274E /* TestHelper.swift */,
CAF76D9320709C9500E2AD7B /* XCUIElement+Helpers.swift */,
);
path = "VLC for iOSUITests";
......@@ -2946,7 +2946,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CAA0B0F720726A0E00B9274E /* LocaleHelper.swift in Sources */,
CAA0B0F720726A0E00B9274E /* TestHelper.swift in Sources */,
CAA0B0EF2072651800B9274E /* VLCiOSTestVideoCodecs.swift in Sources */,
CAA0B0F02072651A00B9274E /* XCUIElement+Helpers.swift in Sources */,
CAA0B0ED2072651000B9274E /* VLCiOSTestMenu.swift in Sources */,
......
devices([
"iPhone X",
"iPhone 8"
"iPhone 5s",
"iPhone 6",
"iPhone 6 Plus",
"iPhone 6s",
"iPhone 6s Plus",
"iPhone 7",
"iPhone 7 Plus",
"iPhone 8",
"iPhone 8 Plus",
"iPhone SE",
"iPhone X",
"iPad Air",
"iPad Air 2",
"iPad (5th generation)",
"iPad Pro (9.7-inch)",
"iPad Pro (12.9-inch)",
"iPad Pro (12.9-inch) (2nd generation)",
"iPad Pro (10.5-inch)"
])
languages([
"en",
"de",
"fr",
"fr"
])
clear_previous_screenshots(true)
......
......@@ -161,12 +161,7 @@ open class Snapshot: NSObject {
return
}
guard let window = app.windows.allElementsBoundByIndex.first(where: { $0.frame.isEmpty == false }) else {
print("Couldn't find an element window in XCUIApplication with a non-empty frame.")
return
}
let screenshot = window.screenshot()
let screenshot = app.windows.firstMatch.screenshot()
guard let simulator = ProcessInfo().environment["SIMULATOR_DEVICE_NAME"], let screenshotsDir = screenshotsDirectory else { return }
let path = screenshotsDir.appendingPathComponent("\(simulator)-\(name).png")
do {
......@@ -276,4 +271,6 @@ private extension CGFloat {
}
}
// SnapshotHelperVersion [1.10]
// Please don't remove the lines below
// They are used to detect outdated configuration files
// SnapshotHelperVersion [1.9]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment