Dive into autotesting on iOS. Part 1. How to work with the accessibilityidentifier of objects

Hello everyone!





My name is Boris. I am an AQA iOS-engineer at Vivid Money.





This is an introductory article in a series of articles on iOS automation, in which I want to talk about the benefits of ui tests on a project, their effective use and writing.





iOS-, , XCUITest ui-.





, :





  1. ui- .





  2. .





  3. ui- accessibilityidentifier.





UI-?

'', -. - , ?





ui-. !





β€” , : , , .





, , , , . .





UI-?

, , .





UI , , , .





:





  • , manual QA;





  • ;





  • ;





  • β€” - 100500 ;





  • .





, , ? :





  • , ;





  • ui-;





  • ;





  • unit- ( β€” ui- );





  • unit- (unit- , ui- 5).





, , , ui- .





:

ui-, . , UI- .





, ui- :





  1.  File > New > Target.





  2.  UI Testing Bundle.





  3.  Next  .





  4.  Finish.





Xcode UITest . .





, , ui . β€” Accessibilityidentifier .





Accessibilityidentifier?

Accessibilityidentifier β€” ui-.





Accessibilityidentifier ui- .





ui- accessibilityidentifier, , . accessibilityidentifier ui , , β€” .





id

accessibilityidentifier .





, storyboard

  1.  storyboard.





  2.  the Utilities.





  3.  Identity Inspector.





  4. storyboard.





  5. Enabled.





  6. identifier ( : button).





, SwiftUI

  1. View.





  2. .accessibility(identifier: "nameOfID") .





,

  1. ViewController.





  2. accessibilityidentifier viewDidLoad .





import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var button: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        button.accessibilityIdentifier = "button"
    }

}
      
      



id

, accessibilityidentifier , , id .





Accessibility Inspector

Xcode. , id .





:





  1. .





  2. Xcode.





  3. Open Developer Tools.





  4. Accesibility Inspector.





  5. Accessibility Inspector .





  6. .





  7. .





:





Basic

  1. Label β€” , .





  2. Value β€” , . , TextFields.





  3. Traits β€” (: Button, Static Text).





  4. Identifier β€” id .





Actions:

, . , .





Element:

Class β€” .





Address β€” .





Controller β€” View Controller, .





Hierarchy:

. id.





Console (lldb)

, , :





po XCUIApplication().debugDescription
      
      



po β€” print object , .





XCUIApplication β€” , ui .





debugDescription β€” , .





Attributes: Application, pid: 67835, label: 'UiTestssProjects'
Element subtree:
 β†’Application, 0x6000026290a0, pid: 67835, label: 'UiTestssProjects'
    Window (Main), 0x600002629180, {{0.0, 0.0}, {375.0, 667.0}}
      Other, 0x600002629260, {{0.0, 0.0}, {375.0, 667.0}}
        Other, 0x600002629340, {{0.0, 0.0}, {375.0, 667.0}}
          Other, 0x600002629420, {{0.0, 0.0}, {375.0, 667.0}}
            Button, 0x600002629500, {{40.0, 156.0}, {46.0, 30.0}}, label: 'Button'
              StaticText, 0x6000026295e0, {{40.0, 162.0}, {46.0, 18.0}}, label: 'Button'
            StaticText, 0x6000026296c0, {{144.0, 161.0}, {42.0, 21.0}}, label: 'Label'
            Button, 0x6000026297a0, {{40.0, 216.0}, {46.0, 30.0}}, identifier: 'ButtonID', label: 'Button'
              StaticText, 0x600002629880, {{40.0, 222.0}, {46.0, 18.0}}, label: 'Button'
            Switch, 0x600002629960, {{183.0, 245.0}, {51.0, 31.0}}, value: 1
            Button, 0x600002629a40, {{40.0, 268.0}, {46.0, 30.0}}, label: 'Button'
              StaticText, 0x600002629b20, {{40.0, 274.0}, {46.0, 18.0}}, label: 'Button'
            TextField, 0x600002629c00, {{133.0, 374.0}, {97.0, 34.0}}
    Window, 0x600002629ce0, {{0.0, 0.0}, {375.0, 667.0}}
      Other, 0x600002629dc0, {{0.0, 0.0}, {375.0, 667.0}}
        Other, 0x600002629ea0, {{0.0, 0.0}, {375.0, 667.0}}
Path to element:
 β†’Application, 0x6000026290a0, pid: 67835, label: 'UiTestssProjects'
Query chain:
 β†’Find: Target Application 'fox.UiTestssProjects'
  Output: {
    Application, pid: 67835, label: 'UiTestssProjects'
  }
      
      



, , , , , , , identifier.





Test Recorder

Test recorder β€” Apple, . .





:





  • UI test target() ;





  • , test.





record . id β€” ,  β€” , .





:

Ui- β€” , . , , , . .





, , ui- iOS- ui-.








All Articles