コードを再利用するのではなく、自分のアプリケーションにサインインするためにヘルパークラスSignUpSetUp
を作成しました。このクラスで私はプライベート関数waitForElementToAppear
を持って、テストスイート内の要素が現れるのを待つ。しかし、この関数を使用するとエラーが発生します:'XCUIElement'型の値を期待される引数型 'SignUpSetUp'に変換できません
Cannot convert value of type 'XCUIElement' to expected argument type 'SignUpSetUp'
なぜこれを解決しますか?
私のコードは次のとおりです。
import XCTest
class SignUpSetUp: XCTestCase {
var systemAlertMonitorToken: NSObjectProtocol? = nil
static let signUpApp = XCUIApplication()
static let app = XCUIApplication()
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()
}
}
private func waitForElementToAppear(element: XCUIElement,
file: String = #file, line: UInt = #line) {
let existsPredicate = NSPredicate(format: "exists == true")
expectationForPredicate(existsPredicate,
evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(5) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after 5 seconds."
self.recordFailureWithDescription(message,
inFile: file, atLine: line, expected: true)
}
}
}
なぜあなたのクラス名と同じ変数( 'SignUpSetUp')に名前を付けようとしていますか? – rmaddy
申し訳ありませんが、これが正しいです、編集されました。 –
最後の質問に自分のコメントを忘れないでください。メソッド名と変数名は小文字で始まる必要があります。変数の名前を変更したので、あなたの質問を更新してください。 – rmaddy