تعمق في الاختبار التلقائي على iOS. الجزء 1. كيفية العمل مع معرّف إمكانية الوصول للكائنات

مرحبا جميعا!





اسمي بوريس. أنا مهندس AQA iOS في Vivid Money.





هذه مقالة تمهيدية في سلسلة من المقالات حول أتمتة iOS ، حيث أود أن أتحدث عن فوائد اختبارات واجهة المستخدم في مشروع ما ، واستخدامها الفعال وكتابتها.





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