I'm trying to setup UI Test in my project. I'm making a UI test that tries to login through my apps login prompt. In order to ensure that the login prompt is shown when the test launches, I'm trying to run ServerManager.logout()
, which is in the project's codebase. This will cause the Login prompt to be shown on launch.
import XCTest
class SmokeTest: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
XCUIApplication().launch()
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
ServerManager.logout()
}
func testLogin() {
let app = XCUIApplication()
let emailTextField = app.textFields["email textfield"]
emailTextField.tap()
emailTextField.typeText("test@test.com")
let passwordTextField = app.secureTextFields["password textfield"]
passwordTextField.tap()
passwordTextField.typeText("12345678")
let loginButton = app.buttons["log in button"]
loginButton.tap()
}
}
How should I set up my project to get access to ServerManager
?
When I checked on Target Membership for UITest target (called DonkeyProductionUITests) on the ServerManager.swift file, Xcode started complaining that many reference in that file was undefined for the UITest target. So I added Target Membership for all files in my project to the UITest Target including all CocoaPods. It solved most issues. Still I have some weird leftovers:
What source files should the UITest target have as "Compile Sources"?
Why are types like UIColor
and UIViewController
suddenly not recognizer by Xcode?