damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

damusUITests.swift (4020B)


      1 //
      2 //  damusUITests.swift
      3 //  damusUITests
      4 //
      5 //  Created by William Casarin on 2022-04-01.
      6 //
      7 
      8 import XCTest
      9 
     10 class damusUITests: XCTestCase {
     11     var app = XCUIApplication()
     12     typealias AID = AppAccessibilityIdentifiers
     13 
     14     override func setUpWithError() throws {
     15         // Put setup code here. This method is called before the invocation of each test method in the class.
     16         self.app = XCUIApplication()
     17 
     18         // In UI tests it is usually best to stop immediately when a failure occurs.
     19         continueAfterFailure = false
     20 
     21         // 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.
     22         
     23         // Set app language to English
     24         app.launchArguments += ["-AppleLanguages", "(en)"]
     25         app.launchArguments += ["-AppleLocale", "en_US"]
     26         
     27         // Force portrait orientation
     28         XCUIDevice.shared.orientation = .portrait
     29         
     30         // Optional: Reset the device's orientation before each test
     31         addTeardownBlock {
     32             XCUIDevice.shared.orientation = .portrait
     33         }
     34         
     35         app.launch()
     36     }
     37 
     38     override func tearDownWithError() throws {
     39         // Put teardown code here. This method is called after the invocation of each test method in the class.
     40     }
     41 
     42     /// Tests if banner edit button is clickable.
     43     /// Note: This is able to detect if the button is obscured by an invisible overlaying object.
     44     /// See https://github.com/damus-io/damus/issues/2636 for the kind of issue this guards against.
     45     func testEditBannerImage() throws {
     46         // Use XCTAssert and related functions to verify your tests produce the correct results.
     47         try self.loginIfNotAlready()
     48         
     49         guard app.buttons[AID.main_side_menu_button.rawValue].tapIfExists(timeout: 5) else { throw DamusUITestError.timeout_waiting_for_element }
     50         guard app.buttons[AID.side_menu_profile_button.rawValue].tapIfExists(timeout: 5) else { throw DamusUITestError.timeout_waiting_for_element }
     51         guard app.buttons[AID.own_profile_edit_button.rawValue].tapIfExists(timeout: 5) else { throw DamusUITestError.timeout_waiting_for_element }
     52         
     53         guard app.buttons[AID.own_profile_banner_image_edit_button.rawValue].waitForExistence(timeout: 5) else { throw DamusUITestError.timeout_waiting_for_element }
     54         let bannerEditButtonCoordinates = app.buttons[AID.own_profile_banner_image_edit_button.rawValue].coordinate(withNormalizedOffset: CGVector.zero).withOffset(CGVector(dx: 15, dy: 15))
     55         bannerEditButtonCoordinates.tap()
     56         
     57         guard app.buttons[AID.own_profile_banner_image_edit_from_url.rawValue].waitForExistence(timeout: 5) else { throw DamusUITestError.timeout_waiting_for_element }
     58     }
     59     
     60     func loginIfNotAlready() throws {
     61         if app.buttons[AID.sign_in_option_button.rawValue].waitForExistence(timeout: 5) {
     62             try self.login()
     63         }
     64 
     65         app.buttons[AID.onboarding_sheet_skip_button.rawValue].tapIfExists(timeout: 5)
     66         app.buttons[AID.post_composer_cancel_button.rawValue].tapIfExists(timeout: 5)
     67     }
     68     
     69     func login() throws {
     70         app.buttons[AID.sign_in_option_button.rawValue].tap()
     71         
     72         guard app.secureTextFields[AID.sign_in_nsec_key_entry_field.rawValue].tapIfExists(timeout: 10) else { throw DamusUITestError.timeout_waiting_for_element }
     73         app.typeText("nsec1vxvz8c7070d99njn0aqpcttljnzhfutt422l0r37yep7htesd0mq9p8fg2")
     74         
     75         guard app.buttons[AID.sign_in_confirm_button.rawValue].tapIfExists(timeout: 5) else { throw DamusUITestError.timeout_waiting_for_element }
     76     }
     77     
     78     enum DamusUITestError: Error {
     79         case timeout_waiting_for_element
     80     }
     81 }
     82 
     83 extension XCUIElement {
     84     @discardableResult
     85     func tapIfExists(timeout: TimeInterval) -> Bool {
     86         if self.waitForExistence(timeout: timeout) {
     87             self.tap()
     88             return true
     89         }
     90         return false
     91     }
     92 }