Can we store element info in a library and access in multiple scripts

Hello All,

Though I have been using Mac’s for quite a few years and using AppleScripts for few basic needs, I had been troubled by a problem at work for sometime and wanted to see if I could get some kind of solution here. I am a software tester in Macintosh domain and here is my problem.

PROBLEM
I need to automate an application say “MyApp” whose UI is being worked upon while I am expected to write up the required applescripts to reduce the time taken during regression. As the time between final UI version and time to finish testing is less, I need to write the scripts as the UI is being developed and fix the scripts in case they get broken due to change in UI.

The major problem I face is my 20 odd scripts get ready and developer changes the UI layout a bit which totally breaks all my scripts and I end up sitting long hours “tweaking” all my scripts. The changes are trivial but they end up taking a lot of time. Here’s an example:
Sample-1 (my code before UI change):

click button "Click here" of group 1 of group 2 of group 1 of window "MyApp"

Sample-2 (my code after UI change)

click button "Click here" of group 1 of group 1 of group 2 of group 1 of window "MyApp"

As you can see, the change was that the button has been embedded in an additional group (initially there were 3 but then it became 4). Though this change is trivial, it affects all my scripts and I end up sitting doing this manually.

MY QUESTION
I toyed with an idea to list all my application controls in one library as variables and then refer to those variables through all of my scripts thereby, insulating me from changing them everywhere. If developer changes the UI, all I have to do is change one library and all scripts still work.

However, I am unable to implement this successfully as I can not find a way to make my scripts successfully access the control info from another library.
I was hoping that I would be able to do something like this:

Library holds control info for button “Click here” as

set bttnClickHere as "button \"Click here\" of group 1 of group 1 of group 2 of group 1 of window \"MyApp\""

And then write in my script

click Lib's bttnClickHere

This way, even if the button is embedded in another group, I have to change one variable and all my scripts remain untouched.

I am not sure if what I envision is possible or not, or if I am doing something wrong…would really appreciate any help/direction in this problem of mine.

Thanks in advance!

A library is the way to go but I believe you will need to put the entire call for each button click
like so. Then you would only have to make the changes in one place.

-- Library of click commands
on clickPlay()
	activate application "iTunes"
	tell application "System Events"
		tell process "iTunes"
			click menu item "Play                       space" of menu 1 of menu bar item "Controls" of menu bar 1
		end tell
	end tell
end clickPlay

on showCurrentSong()
	activate application "iTunes"
	tell application "System Events"
		tell process "iTunes"
			click menu item "Show Current Song" of menu 1 of menu bar item "File" of menu bar 1
		end tell
	end tell
end showCurrentSong

Another option if you are only testing the application and not the fact that it is
GUI scriptable would be to use something like Extra Suites. Then you could keep
all the mouse click pairs {1320, 744} in a list. Just a thought.

Cheers,

Craig

Thanks for the quick response Craig!

Yes, having common functions in library is a good idea but the trouble starts when I need to do different things with the same control in different scripts e.g find out which value is currently selected in a dropdown control in one script then, find out a specific value in same drop-down in another script (or same script but different code location), and then I could be doing something like selecting a different value in that drop-down via a separate script.

During my testing, the list of possibilities for all the controls (which are at least 100-150) are immense and listing out individual functions for all possible actions for each control becomes daunting.
What I was hoping was that if I could keep the control-location info to 1 script (I know it will be a long script for all those control locations) and refer to them in all of my 20-30 scripts, it will be a saner world to live in.

FYI, I am using combination of ExtraSuites and PreFab’s UI Browser to get all the basic code setup and then add testing logic to it.
Thanks.

Finally sorted out a way to achieve what I wanted…sharing here so that its available to any interested reader.

The solution basically needs me to store a reference to the control and then pass that on to any script that wants to access that control. Let me demonstrated this via an example script:

LIbrary Script (myLib.scpt)


on returnControl()
return a reference to row 1 of table 1 of scroll area 1 of window "MyApp"
end returnControl()

Working Script


set LibPath to "HD:Users:rahul:desktop:myLib.scpt"
set Lib to load script file LibPath

set theControl to a reference to Lib's returnControl()
click theControl

With above logic, I am able to keep references to each control in single file and then access them in all my other scripts.

Hope this helps.

Rahul.

Very nice! :smiley:

I am glad you got that working. I am sure it will be a tremendous
time saver.

Cheers,

Craig