Skip to content

Commit

Permalink
Migrating ScreenshotsUITests to latest swift
Browse files Browse the repository at this point in the history
  • Loading branch information
dvor committed Jan 23, 2017
1 parent 9c9a52c commit b0d39e5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 41 deletions.
11 changes: 7 additions & 4 deletions Antidote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
111782C11DC643A3000C1721 /* OCTSubmanagerFriendsMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 111782951DC53458000C1721 /* OCTSubmanagerFriendsMock.swift */; };
111782C21DC643A3000C1721 /* OCTSubmanagerObjectsMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 111782981DC53545000C1721 /* OCTSubmanagerObjectsMock.swift */; };
111782C31DC643A3000C1721 /* OCTSubmanagerUserMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1117829B1DC5363C000C1721 /* OCTSubmanagerUserMock.swift */; };
111782C51DC64607000C1721 /* SnapshotHelper2-3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 111782C41DC64607000C1721 /* SnapshotHelper2-3.swift */; };
111782D21DC64796000C1721 /* BaseCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1193AB651C1F5694006AA9E5 /* BaseCell.swift */; };
111782D31DC64796000C1721 /* BaseCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1193AB671C1F569A006AA9E5 /* BaseCellModel.swift */; };
111782D41DC64796000C1721 /* ChatBaseTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11F276AD1D3EBEF700C613AA /* ChatBaseTextCell.swift */; };
Expand Down Expand Up @@ -250,6 +249,7 @@
114962931C5E1BE0001E5435 /* ChangePasswordController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 114962911C5E1BE0001E5435 /* ChangePasswordController.swift */; };
114962951C64051A001E5435 /* CallBaseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 114962941C64051A001E5435 /* CallBaseController.swift */; };
114962961C64051A001E5435 /* CallBaseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 114962941C64051A001E5435 /* CallBaseController.swift */; };
114D2D401E34D6E400662713 /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 114D2D3F1E34D6E400662713 /* SnapshotHelper.swift */; };
1156A4791C0E478D005AC8C6 /* StaticTableBaseCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1156A4781C0E478D005AC8C6 /* StaticTableBaseCellModel.swift */; };
1156A47B1C0F6178005AC8C6 /* StaticTableButtonCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1156A47A1C0F6178005AC8C6 /* StaticTableButtonCellModel.swift */; };
1156A47D1C0F632C005AC8C6 /* StaticTableSelectableCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1156A47C1C0F632C005AC8C6 /* StaticTableSelectableCellModel.swift */; };
Expand Down Expand Up @@ -680,7 +680,6 @@
111782A71DC64391000C1721 /* ScreenshotsUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ScreenshotsUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
111782A91DC64391000C1721 /* ScreenshotsUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotsUITests.swift; sourceTree = "<group>"; };
111782AB1DC64391000C1721 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
111782C41DC64607000C1721 /* SnapshotHelper2-3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "SnapshotHelper2-3.swift"; path = "fastlane/SnapshotHelper2-3.swift"; sourceTree = SOURCE_ROOT; };
1117835E1DC64C89000C1721 /* ScreenshotUITests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ScreenshotUITests-Bridging-Header.h"; sourceTree = "<group>"; };
112422651BDD2032004D7926 /* KeyboardNotificationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardNotificationController.swift; sourceTree = "<group>"; };
112495361DE7ABFF00EF45C4 /* KeyboardObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardObserver.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -723,6 +722,7 @@
114962741C5CEB0B001E5435 /* ProfileDetailsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileDetailsController.swift; sourceTree = "<group>"; };
114962911C5E1BE0001E5435 /* ChangePasswordController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangePasswordController.swift; sourceTree = "<group>"; };
114962941C64051A001E5435 /* CallBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallBaseController.swift; sourceTree = "<group>"; };
114D2D3F1E34D6E400662713 /* SnapshotHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SnapshotHelper.swift; path = fastlane/SnapshotHelper.swift; sourceTree = SOURCE_ROOT; };
1156A4781C0E478D005AC8C6 /* StaticTableBaseCellModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticTableBaseCellModel.swift; sourceTree = "<group>"; };
1156A47A1C0F6178005AC8C6 /* StaticTableButtonCellModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticTableButtonCellModel.swift; sourceTree = "<group>"; };
1156A47C1C0F632C005AC8C6 /* StaticTableSelectableCellModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticTableSelectableCellModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -990,7 +990,7 @@
111782AB1DC64391000C1721 /* Info.plist */,
111782A91DC64391000C1721 /* ScreenshotsUITests.swift */,
1117835E1DC64C89000C1721 /* ScreenshotUITests-Bridging-Header.h */,
111782C41DC64607000C1721 /* SnapshotHelper2-3.swift */,
114D2D3F1E34D6E400662713 /* SnapshotHelper.swift */,
);
path = ScreenshotsUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1518,6 +1518,7 @@
TargetAttributes = {
111782A61DC64391000C1721 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0820;
TestTargetID = 1164762E19794D3300DB20B8;
};
1164762E19794D3300DB20B8 = {
Expand Down Expand Up @@ -1860,6 +1861,7 @@
111782F61DC64796000C1721 /* StaticTableInfoCellModel.swift in Sources */,
111782F21DC64796000C1721 /* StaticTableChatButtonsCellModel.swift in Sources */,
111783011DC6479E000C1721 /* FriendListDataSource.swift in Sources */,
114D2D401E34D6E400662713 /* SnapshotHelper.swift in Sources */,
111783291DC647DF000C1721 /* InterfaceIdiom.swift in Sources */,
111782DC1DC64796000C1721 /* ChatIncomingFileCellModel.swift in Sources */,
111782D91DC64796000C1721 /* ChatIncomingCallCell.swift in Sources */,
Expand Down Expand Up @@ -1966,7 +1968,6 @@
111782BC1DC643A3000C1721 /* OCTSubmanagerBootstrapMock.swift in Sources */,
111782D51DC64796000C1721 /* ChatBaseTextCellModel.swift in Sources */,
111783241DC647D9000C1721 /* NotificationCoordinator.swift in Sources */,
111782C51DC64607000C1721 /* SnapshotHelper2-3.swift in Sources */,
111782DF1DC64796000C1721 /* ChatListCellModel.swift in Sources */,
111783111DC647BD000C1721 /* PortraitNavigationController.swift in Sources */,
111782F01DC64796000C1721 /* StaticTableButtonCellModel.swift in Sources */,
Expand Down Expand Up @@ -2517,6 +2518,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ScreenshotsUITests/ScreenshotUITests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = Antidote;
};
name = Debug;
Expand Down Expand Up @@ -2570,6 +2572,7 @@
PRODUCT_BUNDLE_IDENTIFIER = me.dvor.ScreenshotsUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ScreenshotsUITests/ScreenshotUITests-Bridging-Header.h";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = Antidote;
};
name = Release;
Expand Down
51 changes: 16 additions & 35 deletions ScreenshotsUITests/ScreenshotsUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ScreenshotsUITests: XCTestCase {
func createAccount() {
let app = XCUIApplication()

XCUIDevice.sharedDevice().orientation = .Portrait
XCUIDevice.shared().orientation = .portrait

app.buttons[localizedString("create_account")].tap()

Expand All @@ -61,7 +61,7 @@ class ScreenshotsUITests: XCTestCase {

app.keyboards.buttons["Go"].tap()

addUIInterruptionMonitorWithDescription("Notifications alert") { (alert) -> Bool in
addUIInterruptionMonitor(withDescription: "Notifications alert") { (alert) -> Bool in
let button = alert.buttons["OK"]
if button.exists {
button.tap()
Expand All @@ -76,17 +76,17 @@ class ScreenshotsUITests: XCTestCase {
let app = XCUIApplication()

// need to interact with the app for the handler to fire
app.tapTabBarElement(.Chats)
app.tapTabBarElement(element: .Chats)

snapshot(Constants.SnapshotContactList)

app.tables.staticTexts[localizedString("app_store_screenshot_conversation_7")].tap()

snapshot(Constants.SnapshotConversation)

app.navigationBars[localizedString("chats_title")].buttons.elementBoundByIndex(0).tap()
app.navigationBars[localizedString("chats_title")].buttons.element(boundBy: 0).tap()

app.tapTabBarElement(.Profile)
app.tapTabBarElement(element: .Profile)

pinPart()
}
Expand All @@ -96,13 +96,13 @@ class ScreenshotsUITests: XCTestCase {

app.tables.staticTexts[localizedString("app_store_screenshot_conversation_7")].tap()

app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(2).childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(0).childrenMatchingType(.TextView).element.tap()
app.children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element(boundBy: 2).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0).children(matching: .textView).element.tap()

XCUIDevice.sharedDevice().orientation = .LandscapeRight
XCUIDevice.shared().orientation = .landscapeRight

snapshot(Constants.SnapshotConversation)

app.navigationBars["Antidote.PrimaryIpad"].childrenMatchingType(.Other).element.childrenMatchingType(.Button).element.tap()
app.navigationBars["Antidote.PrimaryIpad"].children(matching: .other).element.children(matching: .button).element.tap()

pinPart()
}
Expand All @@ -118,12 +118,12 @@ class ScreenshotsUITests: XCTestCase {
button.tap()
button.tap()

let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1.0 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
let delayTime = DispatchTime.now() + Double(Int64(1.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: delayTime) {
snapshot("03_Pin")
}

app.buttons["7"].pressForDuration(5.0)
app.buttons["7"].press(forDuration: 5.0)
}
}

Expand All @@ -150,16 +150,16 @@ extension XCUIApplication {

func tapTabBarElement(element: TabBarElement) {
// TODO refactor me pls
let button = childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(1).childrenMatchingType(.Other).elementBoundByIndex(element.index).childrenMatchingType(.Button).element
let button = children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element(boundBy: 1).children(matching: .other).element(boundBy: element.index).children(matching: .button).element

button.tap()
}
}

func localizedString(key: String) -> String {
func localizedString(_ key: String) -> String {
class LocalizableDummy {}

let bundle = NSBundle(forClass: LocalizableDummy().dynamicType)
let bundle = Bundle(for: type(of: LocalizableDummy()))

var language = deviceLanguage

Expand All @@ -170,28 +170,9 @@ func localizedString(key: String) -> String {
break
}

let path = bundle.pathForResource(language, ofType: "lproj")!
let path = bundle.path(forResource: language, ofType: "lproj")!

let localizationBundle = NSBundle(path: path)!
let localizationBundle = Bundle(path: path)!
return NSLocalizedString(key, bundle:localizationBundle, comment: "")
}

func localizedString(key: String) -> String {
class LocalizableDummy {}

let bundle = NSBundle(forClass: LocalizableDummy().dynamicType)

var language = deviceLanguage

switch language {
case "en-US":
language = "en"
default:
break
}

let path = bundle.pathForResource(language, ofType: "lproj")!

let localizationBundle = NSBundle(path: path)!
return NSLocalizedString(key, bundle:localizationBundle, comment: "")
}
2 changes: 1 addition & 1 deletion fastlane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Runs all the tests
```
fastlane ios shots
```
Create screenshots and upload them
Create screenshots
### ios beta
```
fastlane ios beta
Expand Down
2 changes: 1 addition & 1 deletion fastlane/Snapfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
devices([
"iPad Air",
"iPad Pro",
"iPad Pro (12.9 inch)",
"iPhone 4s",
"iPhone 5",
"iPhone 6",
Expand Down

0 comments on commit b0d39e5

Please sign in to comment.