SlideShare a Scribd company logo
1 of 27
Today I’d like to talk about UIAutomation,
          how you can use it to make your iOS apps
          better.

          After I’ve given you the downlow on UIA,
          I’m going to show you how to make it
          better with a framework I’ve created called
          mechanic.




mechanic.js
uiautomation++
So what is UIAutomation? UIAutomation is a
         software tool (and its accompanying
         framework) built by Apple that allows
         developers to automate interacting with their
         iOS apps for testing.

         UIAutomation makes it easy to script clicks,
         drags, location changes, etc. and allows you
         to assert on the state of your UI.




what is
uiautomation?
play time:
1. Open your favorite project in XCode
2. Cmd-I
3. Choose “Automation” as the Trace Template and click
  “Profile”
4. In the “Scripts” section, click “Add” and create a
  script
5. Automate!
                            4) You don’t have to create a new script, you can import an
                            existing script in your source directory.

                            - Scripts can be ran from the console using the ‘instruments’
                            cmd line utility, as well.

                            - The ‘bwoken’ gem can also be used - it allows you to write
                            tests in coffeescript and run them from the cmd line (though I
                            haven’t been able to get it to work for me just yet)

                            * open instruments and create a simple script that logs element
                            tree for frontMostApp().mainWindow() and describe it *
* show uiautomation/jasmine demo. Explain how it is set
           up (i.e. how to use #import, etc.) *

           * for those of you not familiar with jasmine, it’s an
           RSpec-like framework for writing Javascript specs




uiautomation and
jasmine are pretty cool..
UIAutomation is not without it’s blemishes. Though it’s Apple’s official tool for this
              sort of automation (one reason I’d be wary of using tools like Square’s KIF and
              Frankified), it’s very young

              1. The API isn’t shaped like a modern JS framework like we expect (underscore,
              jQuery, requireJS, Knockout, etc.)

              2. The API is relatively verbose (and at times redundant)

              3. The mechanisms to navigate your app’s “DOM” make it difficult to “get” the
              elements you’re trying to interact with and assert on




what’s the catch?
    What’s the answer to these problems? Mechanic is (or I hope it is)!

    Mechanic servers as a shim to alleviate these pains.
So...


        What’s in
          it for me?
So I’ve given you the elevator pitch.. Now the hard sell:




actions speak louder
than words...
var mainWindow =
UIATarget.localTarget().frontMostApp.mainWindow();
mainWindow.tableViews[‘members’].cells()[‘First row’].tap();
UIATarget.localTarget().delay(2);
var navBar = mainWindow.navigationBars()[‘userDetails’];

assertEquals(‘Back’, navBar.buttons()[0].label());
assertEquals(‘Close’, navBar.buttons()[1].label());


                                 vs                   (describe what the code is
$(‘#members cell’).first()                             doing)
                                                      * # of lines is not much
 .tap()                                               different buuuutttt...
                                                      * code density
 .delay(2);                                           * law of demeter
                                                      * cheated a bit, top code
                                                      would span more lines if
var buttons = $(‘#userDetails button’);               abstracted to the same level

assertEquals(‘Back’, buttons[0].label());
assertEquals(‘Close’, buttons[0].last().label());
and another...
// click all buttons
 var mainWindow = UIATarget.localTarget().frontMostApp.mainWindow();
 var i, j, k, l, m, n, o, p;
 var someButtonElements = mainWindow.elements[‘some_buttons’].elements();
 for (i = 0; i < someButtonElements.length; i++) {
    if (someButtonElements typeof UIAButton) {
      someButtonElements[i].tap();
    }
 }
 var moreButtons = mainWindow.scrollViews()[‘first scrollview’].elements();
 for (i = 0; i < moreButtons.length; i++) {
    if (moreButtons typeof UIAButton) {
      moreButtons[i].tap();
    }



                                         vs
 }
 // ...snip




                                                       (describe what the code is doing - trying to tap all
                                                       of the buttons in the app’s window)

                                                       * the non-mechanic version is intrinsically more
$(‘button’).tap();                                     difficult since there’s no easy mechanism for
                                                       searching the window’s “DOM”
                                                       * This example might be unfair - is it a realistic use
                                                       case?
* mechanic-core is the heart of
                mechanic
                * it’s the reason I wrote / am writing
                mechanic
                * gives you the DOM searching/
                traversing that’s missing from
                UIAutomation, similar to jQuery,
                Prototype, etc.
                * gives you the chaining that we
                know and love and have come to
                expect in selector engines.
                * The other “modules” in mechanic
                are really just niceties or chained
                wrappers on top of the existing
                  UIAutomation APIs.




act i.
mechanic-core
selector                         * UIAutomation places different element
                                     types (buttons, text, images, table cells,



    shortcuts
                                     etc.) into rather verbose classes. When
                                     searching for elements of a certain type,
                                     I’ve provided shorter class names to
                                     decrease the signal-to-noise ratio.




The UIAutomation environment is
pretty minimal. Mechanic provides
                                    functional
                                    extensions
some simple functional-type
functions like map, each, slice,
reduce, etc.




      dom
                                            Most of the UIAutomation scripting
                                            I’ve done, most of the work goes
                                            into “getting” the element you’re



      traversal
                                            looking for. Mechanic provides a
                                            number of means of filtering and
                                            expanding sets of matched
                                            elements.
find stuff:
           (+ more)

$(‘#my-scroll-view image’).each(function(img) { img.log(); });


$(‘text’, aPopover).siblings(‘image’);


var names = $(‘*’).map(function() { return this.name() });


var allNonTextEls = $(‘window’).children().not(‘text’);


var el = $(‘*’).predicate(‘where label == “Some label”’);
act ii.
events
device
                                            We can change the device’s volume,
                                            location, lock the device, etc.




manipulation

Simulate screen touches, rotations, etc.
                                           screen
                                           actions

element
                                              taps, touches, rotations on
                                              buttons, pickers, text, etc.




interaction
do stuff:
             (+ more)


$.orientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT);

$.volume(‘down’, 2);

$(‘#my-scrollview’).dragInside(
 {startOffset : {x:0,y:2}, endOffset: {x:20,y:30}, duration:2});


$(‘#password’, loginScreen).input(‘my password’);


$(‘#my-scroll-view text’).last().scrollToVisible();
act iii.
data
application
preferences

         element
         details
  app
  info
get stuff:
            (+ more)

$.message($(aStaticTextElement).value());


var firstImageLabel = $(‘image’).first().label();


$.message($.bundleId());


$.prefs({ prefA: 1, prefB: ‘some value’ });


var lastElIsVisible = $(‘*’).last().isVisible();
act iv.
logging
screen
  capture
            console
            logging
element
information
record stuff:
        (+ more.. well, not really..)

$.warn(‘An element was not where it should have been!’);


$(‘text’).log();


$(‘window’).logTree();


$(‘image’).capture();

$(‘#my-button’).tap()
 .parent().capture()
 .message(‘tapped the button and then captured a picture!’);
act v.
act v.
choose your
own adventure!
selectors
    documentation
                         more coverage
                                               assertions??
Big thing is that only simple selectors are
                                                create issues
supported, though the functions in mechanic-        use it!!!
core make it easy to construct complex               please...?
constructors.

Reworking mechanic-core based on Sizzle
and qwery currently, which should expose
more complex queries.
submit issues. read docs. fork. download. commit. write specs. add
new features. maintain examples. submit issues. read docs. fork.
download. commit. write specs. add new features. maintain
examples. submit issues. read docs. fork. download. commit. write
specs. add new features. maintain examples. submit issues. read
docs. fork. download. commit. write specs. add new features.
maintain examples. submit issues. read docs. fork. download.
commit. write specs. add new features. maintain examples. submit
issues. read docs. fork. download. commit. write specs. add new
features. maintain examples. submit issues. read docs. fork.
download. commit. write specs. add new features. maintain
                                    find out more @
examples.submit issues. read docs. fork. download. commit. write
             github.com/jaykz52/mechanic
specs. add new features. maintain examples. submit issues. read
docs. fork. download. commit. write specs. add new features.
maintain examples. submit issues. read docs. fork. download.
commit. write specs. add new features. maintain examples. submit
issues. read docs. fork. download. commit. write specs. submit
QUESTIONS???

@jaykz52
I L OV E TO TA L K

More Related Content

What's hot

The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
sumitjoshi01
 
The City Bars App with Sencha Touch 2
The City Bars App with Sencha Touch 2The City Bars App with Sencha Touch 2
The City Bars App with Sencha Touch 2
James Pearce
 
Beginning iphone 4_devlopement_chpter7_tab_b
Beginning iphone 4_devlopement_chpter7_tab_bBeginning iphone 4_devlopement_chpter7_tab_b
Beginning iphone 4_devlopement_chpter7_tab_b
Jihoon Kong
 

What's hot (13)

Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
 
Standford 2015 week5: 1.View Controller Lifecycle, Autolayout 2. Scroll View ...
Standford 2015 week5: 1.View Controller Lifecycle, Autolayout 2. Scroll View ...Standford 2015 week5: 1.View Controller Lifecycle, Autolayout 2. Scroll View ...
Standford 2015 week5: 1.View Controller Lifecycle, Autolayout 2. Scroll View ...
 
Eclipse Tricks
Eclipse TricksEclipse Tricks
Eclipse Tricks
 
The City Bars App with Sencha Touch 2
The City Bars App with Sencha Touch 2The City Bars App with Sencha Touch 2
The City Bars App with Sencha Touch 2
 
Swift Tableview iOS App Development
Swift Tableview iOS App DevelopmentSwift Tableview iOS App Development
Swift Tableview iOS App Development
 
JWC - Rapid application development with FOF
JWC - Rapid application development with FOFJWC - Rapid application development with FOF
JWC - Rapid application development with FOF
 
Sencha Touch - Introduction
Sencha Touch - IntroductionSencha Touch - Introduction
Sencha Touch - Introduction
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Beginning iphone 4_devlopement_chpter7_tab_b
Beginning iphone 4_devlopement_chpter7_tab_bBeginning iphone 4_devlopement_chpter7_tab_b
Beginning iphone 4_devlopement_chpter7_tab_b
 
Rich mobile apps with sencha touch - class system
Rich mobile apps with sencha touch  -  class systemRich mobile apps with sencha touch  -  class system
Rich mobile apps with sencha touch - class system
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
 
Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.com
 

Viewers also liked

The Future of Selenium Testing for Mobile Web and Native Apps
The Future of Selenium Testing for Mobile Web and Native AppsThe Future of Selenium Testing for Mobile Web and Native Apps
The Future of Selenium Testing for Mobile Web and Native Apps
Sauce Labs
 

Viewers also liked (9)

45 Tools to Boost Your Front-End
45 Tools to Boost Your Front-End45 Tools to Boost Your Front-End
45 Tools to Boost Your Front-End
 
The Future of Selenium Testing for Mobile Web and Native Apps
The Future of Selenium Testing for Mobile Web and Native AppsThe Future of Selenium Testing for Mobile Web and Native Apps
The Future of Selenium Testing for Mobile Web and Native Apps
 
WebDriver: The Final Frontier - Selenium Camp 2014
WebDriver: The Final Frontier - Selenium Camp 2014WebDriver: The Final Frontier - Selenium Camp 2014
WebDriver: The Final Frontier - Selenium Camp 2014
 
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
 
iOS Parallel Automation: run faster than fast — Viktar Karanevich — SeleniumC...
iOS Parallel Automation: run faster than fast — Viktar Karanevich — SeleniumC...iOS Parallel Automation: run faster than fast — Viktar Karanevich — SeleniumC...
iOS Parallel Automation: run faster than fast — Viktar Karanevich — SeleniumC...
 
Testing Metrics - Making your tests visible
Testing Metrics - Making your tests visibleTesting Metrics - Making your tests visible
Testing Metrics - Making your tests visible
 
An easy way to automate complex UI
An easy way to automate complex UIAn easy way to automate complex UI
An easy way to automate complex UI
 
Test Automation Architecture in Microservices
Test Automation Architecture in MicroservicesTest Automation Architecture in Microservices
Test Automation Architecture in Microservices
 
End-to-End Test Automation for Both Horizontal and Vertical Scale
End-to-End Test Automation for Both Horizontal and Vertical ScaleEnd-to-End Test Automation for Both Horizontal and Vertical Scale
End-to-End Test Automation for Both Horizontal and Vertical Scale
 

Similar to UIAutomation + Mechanic.js

Introduction to nodejs
Introduction to nodejsIntroduction to nodejs
Introduction to nodejs
James Carr
 
UI Automation_White_CodedUI common problems and tricks
UI Automation_White_CodedUI common problems and tricksUI Automation_White_CodedUI common problems and tricks
UI Automation_White_CodedUI common problems and tricks
Tsimafei Avilin
 
Top 3 SWT Exceptions
Top 3 SWT ExceptionsTop 3 SWT Exceptions
Top 3 SWT Exceptions
Lakshmi Priya
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 
The Mouse is mightier than the sword
The Mouse is mightier than the swordThe Mouse is mightier than the sword
The Mouse is mightier than the sword
Priyanka Aash
 

Similar to UIAutomation + Mechanic.js (20)

iOS Automation Primitives
iOS Automation PrimitivesiOS Automation Primitives
iOS Automation Primitives
 
Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016
 
Introduction to nodejs
Introduction to nodejsIntroduction to nodejs
Introduction to nodejs
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
UI Automation_White_CodedUI common problems and tricks
UI Automation_White_CodedUI common problems and tricksUI Automation_White_CodedUI common problems and tricks
UI Automation_White_CodedUI common problems and tricks
 
Top 3 SWT Exceptions
Top 3 SWT ExceptionsTop 3 SWT Exceptions
Top 3 SWT Exceptions
 
Implementation
ImplementationImplementation
Implementation
 
Cucumber meets iPhone
Cucumber meets iPhoneCucumber meets iPhone
Cucumber meets iPhone
 
iOS
iOSiOS
iOS
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...
 
Clipboard support on Y! mail
Clipboard support on Y! mailClipboard support on Y! mail
Clipboard support on Y! mail
 
Cocoaheads Montpellier Meetup : 3D Touch for iOS
Cocoaheads Montpellier Meetup : 3D Touch for iOSCocoaheads Montpellier Meetup : 3D Touch for iOS
Cocoaheads Montpellier Meetup : 3D Touch for iOS
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Mobile optimization
Mobile optimizationMobile optimization
Mobile optimization
 
A to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperA to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java Developer
 
The Mouse is mightier than the sword
The Mouse is mightier than the swordThe Mouse is mightier than the sword
The Mouse is mightier than the sword
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.js
 
The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
Migrating Objective-C to Swift
Migrating Objective-C to SwiftMigrating Objective-C to Swift
Migrating Objective-C to Swift
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

UIAutomation + Mechanic.js

  • 1. Today I’d like to talk about UIAutomation, how you can use it to make your iOS apps better. After I’ve given you the downlow on UIA, I’m going to show you how to make it better with a framework I’ve created called mechanic. mechanic.js uiautomation++
  • 2. So what is UIAutomation? UIAutomation is a software tool (and its accompanying framework) built by Apple that allows developers to automate interacting with their iOS apps for testing. UIAutomation makes it easy to script clicks, drags, location changes, etc. and allows you to assert on the state of your UI. what is uiautomation?
  • 3. play time: 1. Open your favorite project in XCode 2. Cmd-I 3. Choose “Automation” as the Trace Template and click “Profile” 4. In the “Scripts” section, click “Add” and create a script 5. Automate! 4) You don’t have to create a new script, you can import an existing script in your source directory. - Scripts can be ran from the console using the ‘instruments’ cmd line utility, as well. - The ‘bwoken’ gem can also be used - it allows you to write tests in coffeescript and run them from the cmd line (though I haven’t been able to get it to work for me just yet) * open instruments and create a simple script that logs element tree for frontMostApp().mainWindow() and describe it *
  • 4. * show uiautomation/jasmine demo. Explain how it is set up (i.e. how to use #import, etc.) * * for those of you not familiar with jasmine, it’s an RSpec-like framework for writing Javascript specs uiautomation and jasmine are pretty cool..
  • 5. UIAutomation is not without it’s blemishes. Though it’s Apple’s official tool for this sort of automation (one reason I’d be wary of using tools like Square’s KIF and Frankified), it’s very young 1. The API isn’t shaped like a modern JS framework like we expect (underscore, jQuery, requireJS, Knockout, etc.) 2. The API is relatively verbose (and at times redundant) 3. The mechanisms to navigate your app’s “DOM” make it difficult to “get” the elements you’re trying to interact with and assert on what’s the catch? What’s the answer to these problems? Mechanic is (or I hope it is)! Mechanic servers as a shim to alleviate these pains.
  • 6. So... What’s in it for me?
  • 7. So I’ve given you the elevator pitch.. Now the hard sell: actions speak louder than words...
  • 8. var mainWindow = UIATarget.localTarget().frontMostApp.mainWindow(); mainWindow.tableViews[‘members’].cells()[‘First row’].tap(); UIATarget.localTarget().delay(2); var navBar = mainWindow.navigationBars()[‘userDetails’]; assertEquals(‘Back’, navBar.buttons()[0].label()); assertEquals(‘Close’, navBar.buttons()[1].label()); vs (describe what the code is $(‘#members cell’).first() doing) * # of lines is not much .tap() different buuuutttt... * code density .delay(2); * law of demeter * cheated a bit, top code would span more lines if var buttons = $(‘#userDetails button’); abstracted to the same level assertEquals(‘Back’, buttons[0].label()); assertEquals(‘Close’, buttons[0].last().label());
  • 10. // click all buttons var mainWindow = UIATarget.localTarget().frontMostApp.mainWindow(); var i, j, k, l, m, n, o, p; var someButtonElements = mainWindow.elements[‘some_buttons’].elements(); for (i = 0; i < someButtonElements.length; i++) { if (someButtonElements typeof UIAButton) { someButtonElements[i].tap(); } } var moreButtons = mainWindow.scrollViews()[‘first scrollview’].elements(); for (i = 0; i < moreButtons.length; i++) { if (moreButtons typeof UIAButton) { moreButtons[i].tap(); } vs } // ...snip (describe what the code is doing - trying to tap all of the buttons in the app’s window) * the non-mechanic version is intrinsically more $(‘button’).tap(); difficult since there’s no easy mechanism for searching the window’s “DOM” * This example might be unfair - is it a realistic use case?
  • 11. * mechanic-core is the heart of mechanic * it’s the reason I wrote / am writing mechanic * gives you the DOM searching/ traversing that’s missing from UIAutomation, similar to jQuery, Prototype, etc. * gives you the chaining that we know and love and have come to expect in selector engines. * The other “modules” in mechanic are really just niceties or chained wrappers on top of the existing UIAutomation APIs. act i. mechanic-core
  • 12. selector * UIAutomation places different element types (buttons, text, images, table cells, shortcuts etc.) into rather verbose classes. When searching for elements of a certain type, I’ve provided shorter class names to decrease the signal-to-noise ratio. The UIAutomation environment is pretty minimal. Mechanic provides functional extensions some simple functional-type functions like map, each, slice, reduce, etc. dom Most of the UIAutomation scripting I’ve done, most of the work goes into “getting” the element you’re traversal looking for. Mechanic provides a number of means of filtering and expanding sets of matched elements.
  • 13. find stuff: (+ more) $(‘#my-scroll-view image’).each(function(img) { img.log(); }); $(‘text’, aPopover).siblings(‘image’); var names = $(‘*’).map(function() { return this.name() }); var allNonTextEls = $(‘window’).children().not(‘text’); var el = $(‘*’).predicate(‘where label == “Some label”’);
  • 15. device We can change the device’s volume, location, lock the device, etc. manipulation Simulate screen touches, rotations, etc. screen actions element taps, touches, rotations on buttons, pickers, text, etc. interaction
  • 16. do stuff: (+ more) $.orientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT); $.volume(‘down’, 2); $(‘#my-scrollview’).dragInside( {startOffset : {x:0,y:2}, endOffset: {x:20,y:30}, duration:2}); $(‘#password’, loginScreen).input(‘my password’); $(‘#my-scroll-view text’).last().scrollToVisible();
  • 18. application preferences element details app info
  • 19. get stuff: (+ more) $.message($(aStaticTextElement).value()); var firstImageLabel = $(‘image’).first().label(); $.message($.bundleId()); $.prefs({ prefA: 1, prefB: ‘some value’ }); var lastElIsVisible = $(‘*’).last().isVisible();
  • 21. screen capture console logging element information
  • 22. record stuff: (+ more.. well, not really..) $.warn(‘An element was not where it should have been!’); $(‘text’).log(); $(‘window’).logTree(); $(‘image’).capture(); $(‘#my-button’).tap() .parent().capture() .message(‘tapped the button and then captured a picture!’);
  • 25. selectors documentation more coverage assertions?? Big thing is that only simple selectors are create issues supported, though the functions in mechanic- use it!!! core make it easy to construct complex please...? constructors. Reworking mechanic-core based on Sizzle and qwery currently, which should expose more complex queries.
  • 26. submit issues. read docs. fork. download. commit. write specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. add new features. maintain find out more @ examples.submit issues. read docs. fork. download. commit. write github.com/jaykz52/mechanic specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. add new features. maintain examples. submit issues. read docs. fork. download. commit. write specs. submit

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n