मैं एक लेबल (टोस्ट लेबल) की उपस्थिति का परीक्षण करने के लिए संघर्ष कर रहा हूं, जो कि मेरे पास गलत ईमेल में प्रवेश करते समय संक्षेप में एनिमेट करता है।दिखाई देने वाले एनिमेटेड लेबल का परीक्षण पाठ
private func registerNewUser(email: String, password: String, confirmationPassword: String) {
if password == confirmationPassword {
firebaseData.createUser(email: email, password: password, completion: { (error, _) in
if let error = error {
self.showToast(in: self.view, with: error.localizedDescription)
} else {
self.showToast(in: self.view, with: "Registered succesfully")
self.signInUser(email: email, password: password)
}
})
} else {
//raise password mismatch error
print("password mismatch error")
}
}
func showToast(in toastSuperView: UIView, with text: String) {
let toastLabel = ToastLabel()
toastLabel.text = text
toastSuperView.addSubview(toastLabel)
layoutToastLabel(toastLabel)
animateToastLabel(toastLabel)
}
private func layoutToastLabel(_ toastLabel: ToastLabel) {
toastLabel.centerYToSuperview()
toastLabel.pinToSuperview(edges: [.left, .right])
}
private func animateToastLabel(_ toastLabel: ToastLabel) {
UIView.animate(withDuration: 2.5, delay: 0, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: { _ in
toastLabel.removeFromSuperview()
})
}
मैं सिर्फ इतना है कि त्रुटि पाठ वापस प्राप्त उपयोगकर्ता के बाद एक ईमेल कि पहले से ही लिया गया है में प्रवेश करती है firebase प्रकट होता है से परीक्षण करना चाहते हैं।
func testRegisteringWithUsedEmailDisplaysFirebaseError() {
let email = registeredEmail
let password = "password"
welcomeScreenHelper.register(email: email,
password: password,
confirmationPassword: password,
completion: {
let firebaseErrorMessage = "The email address is already in use by another account."
XCTAssert(self.app.staticTexts[firebaseErrorMessage].exists)
})
}
func register(email: String, password: String, confirmationPassword: String, completion: (() -> Void)? = nil) {
let emailTextField = app.textFields[AccesID.emailTextField]
let passwordTextField = app.secureTextFields[AccesID.passwordTextField]
let confirmPasswordTextField = app.secureTextFields[AccesID.confirmPasswordTextField]
let registerButton = app.buttons[AccesID.registerButton]
emailTextField.tap()
emailTextField.typeText(email)
passwordTextField.tap()
passwordTextField.typeText(password)
registerButton.tap()
confirmPasswordTextField.tap()
confirmPasswordTextField.typeText(confirmationPassword)
registerButton.tap()
completion?()
}
जब मैं उम्मीदों और एक्ससीटीवाइटर जैसे अन्य टूल्स का उपयोग करता हूं तो परीक्षण और लेबल निश्चित रूप से दिखाई देने के बावजूद परीक्षण पास नहीं होते हैं। मुझे इस तरह का परीक्षण कभी नहीं करना पड़ा है, इसलिए मुझे यकीन नहीं है कि मैं गलत कहां जा रहा हूं, भले ही मुझे एनिमेटेड व्यू या कुछ परीक्षण करने के लिए कुछ अलग करना है।
Update1:
इसलिए मैं थोड़ा और खेलने जब मैं registerButton नल टोस्ट एकदम सही ढंग से लेकिन जब तक यह फिर से गायब हो गया है परीक्षण के लिए जारी नहीं करता प्रतीत होता है कि के बाद देख सकते हैं। मुझे यह अजीब लगता है क्योंकि यह रजिस्टर से सख्ती से जुड़ा हुआ नहीं है बटन अपने स्वयं के विचार हैं।
Update2:
मैं इस प्रकार अपने परीक्षण अद्यतन है:
func testRegisteringWithUsedEmailDisplaysFirebaseError() {
welcomeScreenHelper.register(email: registeredEmail,
password: password,
confirmationPassword: password,
completion: {
let firebaseErrorMessage = "The email address is already in use by another account."
let text = self.app.staticTexts[firebaseErrorMessage]
let exists = NSPredicate(format: "exists == true")
self.expectation(for: exists, evaluatedWith: text, handler: nil)
self.waitForExpectations(timeout: 10, handler: nil)
XCTAssert(self.app.staticTexts[firebaseErrorMessage].exists)
})
}
के योग के साथ
:
override func setUp() {
app.launch()
UIView.setAnimationsEnabled(false)
super.setUp()
}
override func tearDown() {
if let email = createdUserEmail {
firebaseHelper.removeUser(with: email)
}
UIView.setAnimationsEnabled(true)
super.tearDown()
}
लेकिन अभी तक कोई भाग्य। मैं अभी भी देख सकता हूं कि func register
में पंजीकरण बटन को टोस्ट शो टैप करने के बाद और अगली पंक्ति तब तक नहीं बुलाई जाती जब तक टोस्ट लेबल ने एनिमेटिंग समाप्त नहीं की हो।
यह मुश्किल है, हालांकि अपने कोड में समस्या दिखाई देती है के लिए - वहाँ कुछ तरीके हैं लेकिन संदर्भ गुम है पसंद: 'func testRegisteringWithUsedEmailDisplaysFirebaseError()' निश्चित रूप से 'क्लास माईटेस्ट: XCTestCase' में है; 'func रजिस्टर है (ईमेल: स्ट्रिंग, पासवर्ड: स्ट्रिंग, पुष्टिकरण पासवर्ड: स्ट्रिंग, समापन: (() -> शून्य)? = शून्य) '' MyTest' 'का एक तरीका भी है? एक स्टब विधि की तरह लगता है। क्या आप किसी भी तरह 'फायरबेस डेटा' इंजेक्शन कर रहे हैं? अधिक संदर्भ देने से निश्चित रूप से प्रश्न की गुणवत्ता में सुधार होगा। –
कृपया, –