Passing Functional parameters to Eggplant from Applescript

ssing Functional parameters(Variables) to Eggplant from Applescript

Hi ,

I have a Functionality which reads from Excel through apple Script , now i want to pass the values to Eggplant for script execution.

Example

global AccountName,AccountPass
do AppleScript {{
tell application “Microsoft Excel”
open “Macintosh HD:Users:admin:Documents:test_Demo.suite:test_Automation_Template.xls”
set AccountName to(get value of range(“D3”))
display dialog AccountName
set AccountPass to(get value of range(“D4”))
display dialog AccountPass
end tell
}}

Now I want AccountName .AccountPass read from excel through applescript to be passed to eggplant as functional parameters.

Can any one help me out to automate this scenario.

Thanks in Advance.

The first thing to do is to return the values you want from your AppleScript code. To return more than one value you can make a list, which in AppleScript is done by listing the values inside curly braces. In your case, just add this line at the end of your AppleScript:

return {AccountName, AccountPass}

Then, to access the returned values within SenseTalk, use the result function on the very next line after calling AppleScript. Since an AppleScript list was returned, it will become a list in SenseTalk. You can use SenseTalk’s multiple assignment ability to assign the two values that were returned to two different variables.

So, your whole script might look like this:

global AccountName,AccountPass 
do AppleScript {{ 
tell application "Microsoft Excel" 
open "Macintosh HD:Users:admin:Documents:test_Demo.suite:test_Automation_Template.xls" 
set AccountName to(get value of range("D3")) 
display dialog AccountName 
set AccountPass to(get value of range("D4")) 
display dialog AccountPass 
end tell 
return {AccountName, AccountPass}
}} 
put the result into (AccountName, AccountPass)

Hi, I am trying something similar but i need the output from a terminal window to be saved as an Eggplant variable to use in another script.
Here is my code so far:


global x

do AppleScript {{
tell application "Terminal"
  do script "ssh user@192.168.1.1"
 delay 1
 do script "PASSWORD" in window 1
 delay 1
 set x to do script "date +%H:%M:%S" in window 1
end tell
return x
}}

TypeText x
//do something with value

This code gives me an AppleScript error saying the variable x is undefined.
Any help appreciated!


First of all, I would suggest not using AppleScript at all in this case. :wink: The SenseTalk “open process”, “read from process” and “write to process” commands could be used instead:

open process "/bin/sh"
write "ssh user@192.168.1.1" & return to process "/bin/sh"
wait 1 second
write "PASSWORD" & return to process "/bin/sh"
read from process "/bin/sh" until end -- ignore output to this point
write "date +%H:%M:%S" & return to process "/bin/sh"
read from process "/bin/sh" until end into x

TypeText x

close process "/bin/sh"

As far as getting values back from AppleScript, your script is just missing one line. After the do AppleScript command, the value returned from AppleScript is available as the result, so you need to add this line:

put the result into x

Note that the x variable in AppleScript and x in SenseTalk are unrelated.

Thanks for that, worked a treat! :smiley:

Nice! I had thought there was only shell(), but this works more like Expect (http://expect.nist.gov/) so one can do more interactive things. Very cool, Doug!

One more thought on this: you can also copy things and get remoteclipboard(), which may or may not work depending on the app and how it was copied. I just tried it with a Google Docs spreadsheet, and it worked:

select the cells by some means. Then:

TypeCommand “c”
put remoteClipboard() into myCellData – mine came as tab-delimited

In terminal, you can also pipe things to pbcopy, which puts it on the clipboard.

in a shell window

TypeText “ls -al” | pbcopy
put remoteClipboard() into myFileList

v

Those are great suggestions, viztester! It shows that there are lots of ways of approaching a problem, some of which may be easier to use in some situations than others. Finding the best solution for a particular case sometimes takes a bit of experimentation. The more tools you have in your belt, the more likely you’ll have one that suits the job at hand.

Hi,
I noticed after trying to add another command to the script above that the date command runs on the local Mac machine rather than the remote server the ssh command goes to. So I dug a little in the console and found this error:
Pseudo-terminal will not be allocated because stdin is not a terminal.

Turns out that you need to put in a -T after ssh to force it to turn off pseudo-tty allocation. This disallows the following commands from being entered into the ssh session (including the password).

So unless anyone has another way to log into a remote server and pull the time and run a command with the time as a parameter…?

(PS RSA authentication for ssh will not work in this case as the remote server is constantly being upgraded.)

So you’re saying this WONT work:

You can ssh withoutt a password by setting things up ahead of time by generating a key from your Eggplant machine via

ssh-keygen -t rsa

and then on your SUT machine, create ~/.ssh/authorized_keys2 and copy that gen’d key. Now you can log into your test machine via ssh without a password.

So maybe a solution would be something like the ideas in

http://www.macosxhints.com/article.php?story=2007091814022049&query=keygen

where you’d “as frequently as your remote server is being upgraded + 1” copy gen’d keys out to other machines?