IOS/Swift - 实例成员 'app' 不能用于错误类型

IOS/Swift - Instance member 'app' cannot be used on type ERROR

我正在我的 UI 测试中创建一个 class 来调用登录以启动。
所以,我不会经常重复使用代码...我有创建了新测试 class.
但是,收到一个“实例成员 'app' 不能用于类型 'signup setup'.
我试过添加一个 get {}围绕我的代码(在其他问题中了解到)
但是,这没有用。

我的代码如下:

import XCTest
class signUpSetUp: XCTestCase {
    let app = XCUIApplication()
    var systemAlertMonitorToken: NSObjectProtocol? = nil

    static let signUpSetUp = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.springboard")

    class func signUpApp() {
        XCUIApplication().launch()
        signUpSetUp.launch()

        sleep(2)
        let element = app.buttons["Enable notifications"]
        if element.exists {
            element.tap()
        }
        sleep(3)

        let notifcationsAlert = self.app.alerts.buttons["OK"]
        if notifcationsAlert.exists{
            notifcationsAlert.tap()
            notifcationsAlert.tap()
        }
        sleep(2)
        waitForElementToAppear(self.app.tabBars.buttons["Nearby"])
        let nearbyTab = self.app.tabBars.buttons["Nearby"]
        if nearbyTab.exists {
            nearbyTab.tap()
        }
        sleep(2)
        let enableLocation = self.app.buttons["Enable location"]
        if enableLocation.exists {
            enableLocation.tap()
        }
        let allowLocation = self.app.alerts.buttons["Allow"]
        if allowLocation.exists {
            allowLocation.tap()
            allowLocation.tap()
        }
        sleep(2)
        waitForElementToAppear(self.app.tabBars.buttons.elementBoundByIndex(4))
        let settingsButton = self.app.tabBars.buttons.elementBoundByIndex(4)
        XCTAssert(settingsButton.exists)
        settingsButton.tap()

        let signUpButton = self.app.tables.staticTexts["Sign Up"]
        if signUpButton.exists {
            signUpButton.tap()
        }        

    }
}

有什么想法吗?

app 是一个实例变量。这意味着它只能从实例方法访问。

signUpApp 是一种类型方法。类型方法不是实例方法。类型方法无法访问任何实例变量或任何实例方法。

要么使 app 成为类型变量(就像 signUpSetUp),要么使 signUpApp 成为实例方法。仅进行这两项更改中的一项。

无关,但请注意,标准做法是命名 类 以大写字母开头。方法和变量名称以小写字母开头。