Last active
September 24, 2019 16:27
-
-
Save mpahuja/40815fcba416c31e00e87126f5dd1c9b to your computer and use it in GitHub Desktop.
Utils - BaseTest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
private var globalSampleApp: XCUIApplication! | |
open class BaseTest: XCTestCase { | |
private var pages: [String: BasePage] = [:] | |
lazy var sampleApp = XCUIApplication() | |
public let globalSampleApp = XCUIApplication() | |
open override func setUp() { | |
continueAfterFailure = false | |
sampleApp.launch() | |
} | |
open override func tearDown() { | |
if let failureCount = self.testRun?.failureCount, failureCount > 0 { | |
let screen = XCUIScreen.main | |
let screenshot = screen.screenshot() | |
let attachment = XCTAttachment(screenshot: screenshot) | |
attachment.lifetime = .keepAlways | |
self.add(attachment) | |
} | |
self.sampleApp.terminate() | |
super.tearDown() | |
} | |
public func getPage<Type: BasePage>() -> Type { | |
if let page = self.pages[String(describing: Type.self)] as? Type { | |
return page | |
} else { | |
let page = Type(testCase: self) | |
self.pages[String(describing: Type.self)] = page | |
return page | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment