How does #import work on iOS 'UI Automation?

I am creating a small test framework that uses a JavaScript module template to test user interface automation in iOS. However, it looks like I am getting odd results based on #import and module extensions.

I have a basic test module called Tester-Module.js :

 (function() { var Tester = this.Tester = {}; Tester.setUp = function() { UIALogger.logMessage('Regular SetUp()'); } }).call(this); 

If I import this module into my test case, it works fine. Here's the test file tester.js ( tester.js is the file that I import into Tools):

 #import "./Tester-Module.js" // Prints 'Regular SetUp()' Tester.setUp(); 

However, if I try to extend the Tester-Module.js in another module file, I cannot reference the Tester object. Tester-Extension.js extends the tester module defined in Tester-Module.js :

 #import "./Tester-Module.js" // Outputs: // Exception raised while running script: // ReferenceError: Can't find variable: Tester\n Tester.setUp = function() { UIALogger.logMessage('Overwritten SetUp()'); } 

And the updated tester.js test file file:

 #import "./Tester-Extension.js" // Exception is thrown before this Tester.setUp(); 

My reliable related questions:

  • Why can't I reference the Tester object inside Tester-Extension.js , but maybe in tester.js ?

  • What does macroC # import do?

+7
source share
1 answer

After some searching and testing, this is similar to using #import in each module file - similar to the requirement in Node.js - it is not supported using the automation infrastructure of the user interface.

The work around is to include a header file that imports each module and then simply imports it into a test file. Using the example above, the header file will look like this:

 // Tester-Header.js #import "./Tester-Module.js" #import "./Tester-Extension.js" 

And the test file simply imports the header file as follows:

 #import "./Tester-Header.js" // Prints "Overwritten SetUp()" Tester.setUp(); 

Mother may user interface. The BDD framework has a more extensive example header file and imports the header file to file . Disclosure: I wrote the structure and originally asked this question to make the structure more modular.

+5
source

All Articles