XCUI测试将自动测试转变为一致的选择器

时间:2018-03-24 15:11:58

标签: xcuitest

 func testExample() {
        XCUIApplication()/*@START_MENU_TOKEN@*/.otherElements.matching(identifier: " Menu  Add 10 e-books for mastering DIY electronics with Arduino UK Information Commissioner's Office raids Cambridge Analytica's London office Your passports are full of tech Cambridge Analytica became a US powerhouse thanks Mercer's laundered money and a judas goat named John Bolton These modern-day 1920s' style swimsuits are for any body NASA's got a computer model for predicting landslides You can have a giant lollipop made of your face People who make their own mechanical watches Egypt’s Election Should Be a Lock. So Why Is President Sisi Worried? French Police Officer Wounded in Hostage Standoff Dies Polish Women Protest Proposed Abortion Ban (Again) At Swedish Preschool, Boys Learn to Dance and Girls Learn to Yell North and South Korea to Hold Preparatory Talks for Summit Meeting ‘The Whole World Should Be Concerned’: U.S. Allies React to Bolton’s Appointment Uber's autonomous vehicles require frequent human intervention A tour of the manipulative, creepy bullshit Facebook pulls to stop you deleting your account Trump Just Pushed the World Trade Organization Toward Irrelevance Misreading Trump: Ally Japan Is Spurned on Tariff Exemptions 150 Whales Beached in Australia, as Rescuers Fight to Save Them Responding to Trump, China Plans New Tariffs on U.S. Goods Spectre and Meltdown: CPU bugs put a scare in the air From Capistrano to Kubernetes: Lessons from PhraseApp's transition 9 code and framework trends to watch in 2018 6 reasons to co-locate your app and automation code 5 IT Ops management trends to watch in 2018 GDPR wakeup call: 3 ways dev teams can build in privacy like security 6 levels of AI-based testing: Have no fear, QA pros How to map your DevOps journey Best of TechBeacon 2017: Quality comes first The best agile and lean development conferences of 2018 Dropbox IPOs. Its Founders Are Now Billionaires Uber's Self-Driving Cars Were Struggling Before Arizona Crash British Scientists Develop Wearable MRI Scanner One Startup is Using Phone Calls and Other Inexpensive Means To Save TB Patients Britain's Plan To Build a 2,000 Foot Aircraft Carrier Almost Entirely From Ice New York Councilman Proposes Bill That Would Grant NYC Workers 'Right To Disconnect' Spotify Says 2 Million Users Hacked Apps To Suppress Ads On Its Free Service Apple To Unveil a Cheaper iPad Next Week At Its Educational Event Facebook Gets Hit With Four Lawsuits Over Cambridge Analytica Scandal School Pays To Get an Algorithm To Scan Students' Social Media For Threats and Suicide Risks Posts  Previous Next ").staticTexts["Menu"]/*[[".otherElements[\"RssList\"]",".otherElements[\"rss_list_populated\"]",".scrollViews.otherElements[\" Menu  Add 10 e-books for mastering DIY electronics with Arduino UK Information Commissioner's Office raids Cambridge Analytica's London office Your passports are full of tech Cambridge Analytica became a US powerhouse thanks Mercer's laundered money and a judas goat named John Bolton These modern-day 1920s' style swimsuits are for any body NASA's got a computer model for predicting landslides You can have a giant lollipop made of your face People who make their own mechanical watches Egypt’s Election Should Be a Lock. So Why Is President Sisi Worried? French Police Officer Wounded in Hostage Standoff Dies Polish Women Protest Proposed Abortion Ban (Again) At Swedish Preschool, Boys Learn to Dance and Girls Learn to Yell North and South Korea to Hold Preparatory Talks for Summit Meeting ‘The Whole World Should Be Concerned’: U.S. Allies React to Bolton’s Appointment Uber's autonomous vehicles require frequent human intervention A tour of the manipulative, creepy bullshit Facebook pulls to stop you deleting your account Trump Just Pushed the World Trade Organization Toward Irrelevance Misreading Trump: Ally Japan Is Spurned on Tariff Exemptions 150 Whales Beached in Australia, as Rescuers Fight to Save Them Responding to Trump, China Plans New Tariffs on U.S. Goods Spectre and Meltdown: CPU bugs put a scare in the air From Capistrano to Kubernetes: Lessons from PhraseApp's transition 9 code and framework trends to watch in 2018 6 reasons to co-locate your app and automation code 5 IT Ops management trends to watch in 2018 GDPR wakeup call: 3 ways dev teams can build in privacy like security 6 levels of AI-based testing: Have no fear, QA pros How to map your DevOps journey Best of TechBeacon 2017: Quality comes first The best agile and lean development conferences of 2018 Dropbox IPOs. Its Founders Are Now Billionaires Uber's Self-Driving Cars Were Struggling Before Arizona Crash British Scientists Develop Wearable MRI Scanner One Startup is Using Phone Calls and Other Inexpensive Means To Save TB Patients Britain's Plan To Build a 2,000 Foot Aircraft Carrier Almost Entirely From Ice New York Councilman Proposes Bill That Would Grant NYC Workers 'Right To Disconnect' Spotify Says 2 Million Users Hacked Apps To Suppress Ads On Its Free Service Apple To Unveil a Cheaper iPad Next Week At Its Educational Event Facebook Gets Hit With Four Lawsuits Over Cambridge Analytica Scandal School Pays To Get an Algorithm To Scan Students' Social Media For Threats and Suicide Risks Posts  Previous Next \"]",".otherElements.matching(identifier: \" Menu  Add\")",".otherElements[\"main_header\"]",".otherElements[\" Menu\"].staticTexts[\"Menu\"]",".staticTexts[\"Menu\"]",".otherElements.matching(identifier: \" Menu  Add 10 e-books for mastering DIY electronics with Arduino UK Information Commissioner's Office raids Cambridge Analytica's London office Your passports are full of tech Cambridge Analytica became a US powerhouse thanks Mercer's laundered money and a judas goat named John Bolton These modern-day 1920s' style swimsuits are for any body NASA's got a computer model for predicting landslides You can have a giant lollipop made of your face People who make their own mechanical watches Egypt’s Election Should Be a Lock. So Why Is President Sisi Worried? French Police Officer Wounded in Hostage Standoff Dies Polish Women Protest Proposed Abortion Ban (Again) At Swedish Preschool, Boys Learn to Dance and Girls Learn to Yell North and South Korea to Hold Preparatory Talks for Summit Meeting ‘The Whole World Should Be Concerned’: U.S. Allies React to Bolton’s Appointment Uber's autonomous vehicles require frequent human intervention A tour of the manipulative, creepy bullshit Facebook pulls to stop you deleting your account Trump Just Pushed the World Trade Organization Toward Irrelevance Misreading Trump: Ally Japan Is Spurned on Tariff Exemptions 150 Whales Beached in Australia, as Rescuers Fight to Save Them Responding to Trump, China Plans New Tariffs on U.S. Goods Spectre and Meltdown: CPU bugs put a scare in the air From Capistrano to Kubernetes: Lessons from PhraseApp's transition 9 code and framework trends to watch in 2018 6 reasons to co-locate your app and automation code 5 IT Ops management trends to watch in 2018 GDPR wakeup call: 3 ways dev teams can build in privacy like security 6 levels of AI-based testing: Have no fear, QA pros How to map your DevOps journey Best of TechBeacon 2017: Quality comes first The best agile and lean development conferences of 2018 Dropbox IPOs. Its Founders Are Now Billionaires Uber's Self-Driving Cars Were Struggling Before Arizona Crash British Scientists Develop Wearable MRI Scanner One Startup is Using Phone Calls and Other Inexpensive Means To Save TB Patients Britain's Plan To Build a 2,000 Foot Aircraft Carrier Almost Entirely From Ice New York Councilman Proposes Bill That Would Grant NYC Workers 'Right To Disconnect' Spotify Says 2 Million Users Hacked Apps To Suppress Ads On Its Free Service Apple To Unveil a Cheaper iPad Next Week At Its Educational Event Facebook Gets Hit With Four Lawsuits Over Cambridge Analytica Scandal School Pays To Get an Algorithm To Scan Students' Social Media For Threats and Suicide Risks Posts  Previous Next \")"],[[[-1,7,3],[-1,2,3],[-1,1,2],[-1,0,1]],[[-1,7,3],[-1,2,3],[-1,1,2]],[[-1,7,3],[-1,2,3]],[[-1,6],[-1,5],[-1,4,5],[-1,3,4]],[[-1,6],[-1,5],[-1,4,5]],[[-1,6],[-1,5]]],[0,0]]@END_MENU_TOKEN@*/.tap()

        // Use recording to get started writing UI tests.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
    }

此处的标识符包含来自各种RSS源的文本,每次运行测试时都会更改这些文本。

我如何:

  1. 从其他元素或其他一些条件中选择索引
  2. 等待该元素。

1 个答案:

答案 0 :(得分:0)

答案是:

  func testClicksOnMenu() {
    let app = XCUIApplication();
    let containsMenu = NSPredicate(format: "label contains[c] %@", "Menu");
    let other = app.otherElements.containing(containsMenu).staticTexts["Menu"];
    let exists = other.waitForExistence(timeout: 10);
    XCTAssertTrue(exists, "Expected Menu to Exist");
    other.tap();
  }

基本上你只需要一个其他元素的匹配器它实际上返回11个匹配name的元素包含Menu但是对于staticText的Menu只有一个accessibilityId。测试也相当快速和稳定。