Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:38:06+00:00 2026-05-29T05:38:06+00:00

I use the iOS UI Automation framework to make sure my iPhone app rocks.

  • 0

I use the iOS UI Automation framework to make sure my iPhone app rocks.

Everybody who uses this framework would tell you that it’s great, but that it’s lacking a lot of structure.

So I have to deal with instances of UIAWindow, which represent different screens of my app. To be more object-oriented, I’d like to have a specific class for each screen, so I could add specific methods, like

myScreen1.tapDoneButton();
var total = myScreen2.getNumberOfElements();

For the moment, I’m able to achieve this by passing the instances of UIAWindow to functions that will add the appropriate methods, like this :

function makeMainScreen(actualScreen)
{   
    actualScreen.constructor.prototype.getAddButton = function() {
        return this.buttons()["add button"];
    };
    actualScreen.constructor.prototype.tapAddButton = function() {
        this.getAddButton().tap();
    };
    // Add any desired method...

return actualScreen;
}

It works fine, I use it like this :

var mainScreen = makeMainScreen(app.mainWindow());
mainScreen.tapAddButton();

But that doesn’t seem object-oriented enough, I would like to create real objects, using the new and this keywords, so I’d have a declaration like this :

function MainScreen(actualScreen){
  // This line doesn't work : because 'this' is immutable
  this = actualScreen;

  this.tapAddButton = function(){
    this.getAddButton().tap();
  }

  //...

}

And I’d use it like this :

var mainScreen = new MainScreen(app.mainWindow());
mainScreen.tapAddButton();

I thought I could save the actualScreen as a property of the object (Like in Grace Shao’s answer below), and call all the methods on it, but I’d like keep the original UIAWindow methods.

Does anybody know how to do this?
Or perhaps what I’m trying to achieve doesn’t make sense, in which case I’d be happy to know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:38:07+00:00Added an answer on May 29, 2026 at 5:38 am

    If I understand correctly, you could try the following:

    function MainScreen(actualScreen){
        this.screen = actualScreen;
    }
    
    MainScreen.prototype.tapAddButton = function () {
        this.screen.getAddButton().tap();
    };
    
    MainScreen.prototype.getScreen = function () {
        return this.screen;
    };
    
    //...
    
    var mainScreen = new MainScreen(app.mainWindow());
    
    mainScreen.tapAddButton();
    

    You are correct that you cannot assign anything to this. You could also define the methods inside the constructor MainScreen, but they would be considered privileged members.

    function MainScreen(actualScreen){
        this.screen = actualScreen;
    
        this.tapAddButton = function () {
            this.screen.getAddButton().tap();
        };
    }
    

    If you dont want them to be privileged members, it is better to define them outside the constructor. Otherwise, the members will be initialized over and over again everytime when you instantiate a new object.

    Updated:
    You could also wrappers for the methods of screen inside the constructor as below.

    var prop;
    
    for (prop in actualScreen) {
        if (typeof actualScreen[prop] !== 'Function') {
            continue;
        }
        this[prop] = function () {
            return actualScreen[prop].apply(actualScreen, arguments);
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use YAJL-iOS framework in my iOS app. But I m just
I am building an assistive iOS app for a kid that uses a switch
I face a problem, I use ios 5 build the distribute version app as
Using my FB account I created an FB app for use by an iOS
Would anyone know a good and easy-to-use library on iOS to parse KML in
I start writing a simple app to use FaceBook IOS SDK from GitHub. I
I would like to use the iOS notification image (the numeric bubble shown over
I develop for iOS and use XCode 3.2.5, GCC 4.2. UPD This code works:
I developed an app for iPhone with Xcode 3.2.4 and iOS 4.1. Now I
I'd like to use the iOS speech engine in my app to speak some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.