Upgrade to Pro — share decks privately, control downloads, hide ads and more …

About UITests

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.
Avatar for HIRAI Hiroaki HIRAI Hiroaki
September 08, 2019

About UITests

Avatar for HIRAI Hiroaki

HIRAI Hiroaki

September 08, 2019
Tweet

Other Decks in Programming

Transcript

  1. ࣗಈੜ੒ίʔυ
 ఺͘Β͍ʁ let app = XCUIApplication() app.launch() let window =

    XCUIApplication().windows["Window"] let field1TextField = window.textFields["field1"] field1TextField.click() field1TextField.typeText("10") let field2TextField = window.textFields["field2"] field2TextField.click() field2TextField.typeText("20\r") XCTAssert("30" == window.staticTexts["result"].value as? String) ͜ͷέʔεͰ͸ɺ݁Ռ൑ఆ͸ɺࣗ෼Ͱॻ͖଍͢ඞཁ͕͋Δ
  2. ࣗಈੜ੒ίʔυ
 εϥΠμʔ͸ɺΫϦοΫʹ͞Εͯ͠·͏ let app = XCUIApplication() app.launch() let window =

    XCUIApplication().windows["Window"] let valueIndicator = XCUIApplication().windows["Window"].sliders["slider1"].children(matching: .valueIndicator).element valueIndicator.click() //ਅΜதΛΫϦοΫ͢Δ͚ͩ valueIndicator.click() //ਅΜதΛΫϦοΫ͢Δ͚ͩ let app = XCUIApplication() app.launch() let slider = XCUIApplication().windows["Window"].sliders["slider1"] slider.adjust(toNormalizedSliderPosition: 1.0) slider.adjust(toNormalizedSliderPosition: 0.0) ਖ਼͘͠͸
  3. 6*5FTUTͷίʔυ  4UFQɿΞϓϦىಈ
 
 
 4UFQɿϘλϯ΍ϝχϡʔͳͲΛ୳͢
 4UFQɿ୳͠ग़ͨ͠ϘλϯͳͲΛΫϦοΫͳͲ͢Δ
 
 4UFQʙ̏Λ܁Γฦͯ͠
 


    
 
 
 4UFQ-BTUɿ࠷ऴతͳ݁ՌΛ֬ೝ͢Δ XCUIApplication().launch() app.windows[“໊শະઃఆ”].buttons["બ୒…"].click()
 app.menuBars.menuBarItems["ฤू"].click() app.menuBars.menuItems["ϖʔετ"].click() XCTAssert("30" == window.staticTexts["result"].value as? String)
  4. ίʔυͷ৔߹
 ΞϓϦຊମͷίʔυͰ࣮૷ w ɹ
 
 
 
 ˞0CKFDUJWF$ͩͱɺBDDFTTJCJMJUZ*OEFOUJpFS͸ɺϓϩύςΟʹͳ͍ͬͯΔ
 w 


    
 
 
 SwiftUI
 
 Text("") .accessibility(identifier: "label1") AppKit
 
 let button = NSButton() button.setAccessibilityIdentifier(“button1")
  5. print(XCUIApplication().windows["Window"].debugDescription) ΢Πϯυ΢ͷ্ʹɺͲΜͳ6*͕৐͍ͬͯΔͷ͔ʁ Attributes: Window (Main), {{340.0, 781.0}, {480.0, 292.0}}, identifier:

    '_NS:10', title: 'Window', Disabled Element subtree: →Window (Main), 0x600003b00b60, {{340.0, 781.0}, {480.0, 292.0}}, identifier: '_NS:10', title: 'Window', Disabled Button, 0x600003b00c40, {{493.0, 882.0}, {81.0, 32.0}}, identifier: 'button1', title: 'Button', Keyboard Focused Button, 0x600003b00d20, {{347.0, 784.0}, {14.0, 16.0}}, identifier: '_XCUI:CloseWindow' Button, 0x600003b00e00, {{387.0, 784.0}, {14.0, 16.0}}, identifier: '_XCUI:FullScreenWindow' Button, 0x600003b00ee0, {{367.0, 784.0}, {14.0, 16.0}}, identifier: '_XCUI:MinimizeWindow' StaticText, 0x600003b00fc0, {{553.0, 784.0}, {53.0, 16.0}}, value: Window Path to element: →Application, 0x600003b00a80, pid: 89463, title: 'sampleapp', Disabled ↳Window (Main), 0x600003b00b60, {{340.0, 781.0}, {480.0, 292.0}}, identifier: '_NS:10', title: 'Window', Disabled Query chain: →Find: Target Application 'jp.co.innoface.sampleapp' Output: { Application, pid: 89463, title: ‘sampleapp', Disabled } ↪Find: Descendants matching type Window Output: { Window (Main), {{340.0, 781.0}, {480.0, 292.0}}, identifier: '_NS:10', title: 'Window', Disabled } ↪Find: Elements matching predicate '"Window" IN identifiers' Output: { Window (Main), {{340.0, 781.0}, {480.0, 292.0}}, identifier: '_NS:10', title: 'Window', Disabled }
  6. print(XCUIApplication().windows["Window"].debugDescription) ΢Πϯυ΢ͷ্ʹɺͲΜͳ6*͕৐͍ͬͯΔͷ͔ʁ Button, ɾɾɾ identifier: 'button1', title: 'Button', ɾɾɾ Button,

    ɾɾɾ identifier: '_XCUI:CloseWindow' Button, ɾɾɾ identifier: '_XCUI:FullScreenWindow' Button, ɾɾɾ identifier: '_XCUI:MinimizeWindow' ※΢Πϯυ΢ࠨ্ͷϘλϯ͸ɺݻఆͷidentifier͕APIͱͯ͠ఏڙ͞Ε͍ͯΔ
 let XCUIIdentifierCloseWindow: String
 let XCUIIdentifierFullScreenWindow: String
 let XCUIIdentifierMinimizeWindow: String
  7. ඵϧʔϧʹ
 Ҿ͔͔ͬΒͳ͍Α͏ʹ଴ͭ
 FYQFDUBUJPO let expectation = self.expectation(description: "Download File") DispatchQueue.global(qos:

    .default).async(execute: { //ϙʔϦϯάͰɺEnableঢ়ଶͷButton͕ݟ͔ͭΔͷΛ଴ͭ var isNeedCheck = true repeat { Thread.sleep(forTimeInterval: 0.1) DispatchQueue.main.sync(execute: { if okButton.isEnabled { okButton.click() //expectation͕ແࣄʹ࣮ߦͰ͖ͨ expectation.fulfill() isNeedCheck = false } }) } while isNeedCheck }) self.waitForExpectations(timeout: 300) { error in if nil != error { XCTFail("Download Timeout") }else{ print("Download Success") } }
  8. %JTBCMFʹؾΛ͚ͭͯʂ w %JTBCMFঢ়ଶͷϘλϯͰ΋ɺΫϦοΫͯ͠0,ʹͳΔ
 ˞ਓؒͷςελʔͰ͸ɺ·ͣ͋Γ͑ͳ͍ͷͰ஫ҙʂʂʂ
 let button = XCUIApplication().windows["Window"].buttons["ॻ͖ग़͠"] if button.isEnabled

    { button.click() }else{ XCTFail() } let predicate = NSPredicate(format:"isEnabled == TRUE") app.ɾུɾ.buttons.matching(predicate)[“ॻ͖ग़͠”]
  9. ΞϓϦຊମͷڍಈΛม͑Δ let app = XCUIApplication() app.launchEnvironment = ["UITestOption": jsonString] app.launch()

    let environment = ProcessInfo.processInfo.environment let jsonString = environment["UITestOption"] 6*5FTUTଆ ΞϓϦຊମଆ
  10. จࣈྻͷೖྗ w γϣʔτΧοτΩʔ͕͓નΊ let pasteboard = NSPasteboard.general pasteboard.clearContents() pasteboard.setString(“SampleText",
 forType:

    NSPasteboard.PasteboardType.string) ɾ
 ɾ
 ɾ
 textField.click() textField.typeKey("a", modifierFlags:.command) textField.typeKey("v", modifierFlags:.command)
  11. &OE