Getting started with iOSUILabelChange Status Bar ColorPassing Data between View ControllersManaging the KeyboardUIButtonUILocalNotificationUIImageViewChecking for Network ConnectivityAccessibilityUITableViewAuto LayoutUIViewUIAlertControllerMKMapViewUIColorNSAttributedStringCAAnimationUITextViewUINavigationControllerConcurrencyCAGradientLayerUIGestureRecognizerCustom UIViews from XIB filesSafari ServicesUIStackViewUIImageUIWebViewCALayeriOS - Implementation of XMPP with Robbie Hanson frameworkSwift and Objective-C interoperabilityNSDateCustom fontsAVSpeechSynthesizerUIBarButtonItemUIScrollViewLocalizationNSNotificationCenterUITextFieldAlamofireUIViewControlleriBeaconCLLocationNSURLSessionUISwitchChecking iOS versionUniversal LinksUICollectionViewPDF Creation in iOSIn-App PurchaseNSTimerCGContext ReferenceUITabBarControllerUISearchControllerUIActivityViewControllerCore LocationFacebookSDKAFNetworkingCTCallCenterUIImagePickerControllerNSUserDefaultsUIControl - Event Handling with BlocksUIBezierPathUIPageViewControllerUIAppearancePush NotificationsKey Value Coding-Key Value ObservationInitialization idiomsStoryboardBackground Modes and EventsFastlaneCAShapeLayerWKWebViewUUID (Universally Unique Identifier)CategoriesHandling URL SchemesRealmARC (Automatic Reference Counting)UIPickerViewDynamic TypeNSURLSWRevealViewControllerSnapshot of UIViewDispatchGroupGCD (Grand Central Dispatch)Size Classes and AdaptivityUIScrollView AutoLayoutIBOutletsAWS SDKDebugging CrashesUISplitViewControllerUISplitViewControllerUIDeviceCloudKitGameplayKitXcode Build & Archive From Command LineXCTest framework - Unit TestingNSDataAVPlayer and AVPlayerViewControllerDeep Linking in iOSApp Transport Security (ATS)Core GraphicsSeguesUIDatePickerNSPredicateEventKitNSBundleSiriKitContacts FrameworkDynamically updating a UIStackViewiOS 10 Speech Recognition APINSURLConnectionStoreKitCode signingCreate .ipa File to upload on appstore with ApplicationloaderResizing UIImageSize Classes and AdaptivityMKDistanceFormatter3D TouchGameCenter LeaderboardsKeychainHandle Multiple Environment using MacroSet View BackgroundBlockContent Hugging/Content Compression in AutolayoutiOS Google Places APINavigation BarUITextField DelegateApp wide operationsUILabel text underliningCut a UIImage into a circleMake selective UIView corners roundedConvert HTML to NSAttributed string and vice verseConvert NSAttributedString to UIImageCoreImage FiltersFace Detection Using CoreImage/OpenCVMPMediaPickerDelegateGraph (Coreplot)NSHTTPCookieStorageFCM Messaging in SwiftCreate a Custom framework in iOSCustom KeyboardAirDropSLComposeViewControllerAirPrint tutorial in iOSUISliderCarthage iOS SetupHealthkitCore SpotLight in iOSUI TestingCore MotionQR Code Scannerplist iOSNSInvocationUIRefreshControl TableViewWCSessionDelegateAppDelegateApp Submission ProcessMVVMUIStoryboardBasic text file I/OiOS TTSMPVolumeViewObjective-C Associated ObjectsPassing Data between View Controllers (with MessageBox-Concept)UIPheonix - easy, flexible, dynamic & highly scalable UI frameworkChain Blocks in a Queue (with MKBlockQueue)SimulatorBackground ModesNSArrayOpenGLUIScrollView with StackView childCache online imagesMVP ArchitectureUIKit DynamicsConfigure Beacons with CoreBluetoothCore DataExtension for rich Push Notification - iOS 10.Profile with InstrumentsApplication rating/review requestMyLayoutUIFontSimulator BuildsSimulating Location Using GPX files iOSCustom methods of selection of UITableViewCellsCustom methods of selection of UITableViewCellsUISegmentedControlSqlCipher integrationCustom UITextFieldSecurityGuideline to choose best iOS Architecture PatternsUIFeedbackGeneratorUIKit Dynamics with UICollectionViewMulticast DelegatesUsing Image AseetsUITableViewCellRuntime in Objective-CModelPresentationStylesCydiaSubstrate tweakCreate a video from imagesCodableFileHandleNSUserActivityRich NotificationsLoad images asyncADDING A SWIFT BRIDGING HEADERCreating an App IDSwift: Changing the rootViewController in AppDelegate to present main or login/onboarding flowattributedText in UILabelUITableViewController

UI Testing

Other topics

Adding Test Files to Xcode Project

When creating the project

You should check "Include UI Tests" in the project creation dialog.

enter image description here

After creating the project

If you missed checking UI target while creating project, you could always add test target later.

Setps:

  • While project open go to File -> New -> Target
  • Find iOS UI Testing Bundle

enter image description here

Accessibility Identifier

When Accessibility enabled in Utilities

  • Select storyboard.
  • Expand the Utilities
  • Select Identity Inspector
  • Select your element on storyboard
  • Add new Accessibility Identifier (in example addButton)

enter image description here

When Accessibility disabled in Utilities

  • Select storyboard.
  • Expand the Utilities
  • Select Identity Inspector
  • Select your element on storyboard
  • Add attribute in User Defined Runtime Attributes
  • For Key Path type - accessibilityIdentifier
  • For Type - `String
  • For Value - new accessibility identifier for your element (in example view)

enter image description here

Setting up in UITest file

import XCTest

class StackOverFlowUITests: XCTestCase {

    private let app = XCUIApplication()

    //Views

    private var view: XCUIElement!

    //Buttons

    private var addButton: XCUIElement!


    override func setUp() {
        super.setUp()
    
        app.launch()
    
        //Views
    
        view = app.otherElements["view"]
    
        //Buttons
    
        addButton = app.buttons["addButton"]
    }

    func testMyApp() {

        addButton.tap()
        view.tap()
    }    
}

In [ ] add Accessibility Identifier for element.

UIView, UIImageView, UIScrollView

let imageView = app.images["imageView"]
let scrollView = app.scrollViews["scrollView"]
let view = app.otherElements["view"]

UILabel

let label = app.staticTexts["label"]

UIStackView

let stackView = app.otherElements["stackView"]

UITableView

let tableView = app.tables["tableView"]

UITableViewCell

let tableViewCell = tableView.cells["tableViewCell"]

UITableViewCell elements

let tableViewCellButton = tableView.cells.element(boundBy: 0).buttons["button"]

UICollectionView

let collectionView = app.collectionViews["collectionView"]

UIButton, UIBarButtonItem

let button = app.buttons["button"]
let barButtonItem = app.buttons["barButtonItem"]

UITextField

  • normal UITextField
let textField = app.textFields["textField"]
  • password UITextField
let passwordTextField = app.secureTextFields["passwordTextField"]

UITextView

let textView = app.textViews["textView"]

UISwitch

let switch = app.switches["switch"]

Alerts

let alert = app.alerts["About yourself"] // Title of presented alert

Disable animations during UI Testing

In a test you can disable animations by adding in setUp:

    app.launchEnvironment = ["animations": "0"]

Where app is instance of XCUIApplication.

Lunch and Terminate application while executing

Lunch application for testing

override func setUp() {
    super.setUp()

    let app = XCUIApplication()

    app.launch()
}

Terminating application

func testStacOverFlowApp() {
    
    app.terminate()
}

Rotate devices

Device can be rotate by changing orientation in XCUIDevice.shared().orientation:

XCUIDevice.shared().orientation = .landscapeLeft
XCUIDevice.shared().orientation = .portrait

Syntax:

  • XCUIApplication() // Proxy for an application. The information identifying the application is specified in the Xcode target settings as the "Target Application".
  • XCUIElement() // A user interface element in an application.

Contributors

Topic Id: 7526

Example Ids: 24833,24834,24835,24836,24840

This site is not affiliated with any of the contributors.