How to use the function ` performTaskWithPathArgumentsTimeout` of the UIAutomation class? - ios

I am automating some test cases for an iPhone app and I am using the UIAutomation class. I want to use the function performTaskWithPathArgumentsTimeout, which I believe runs some external script. But I cant use it. I have the following code:
#import "revision3.js"
#import "tuneup/tuneup.js"
test("script call", function(target, app){
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("fwasim/Desktop/registration.js, ["null"], 5);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
});
The instrument console says:
Error: launch path not accessible.
I have searched on the internet but there seems to be very scarce resources on UIAutomation class and more specifically on the above function. Can anyone tell me what I am doing wrong?

The performTaskWithPathArgumentsTimeout() method on the host is for executing shell programs not JavaScript. That error message is telling you that it can't find an executable command at the path you gave.
Here's how you could execute a command with that method:
var result = host.performTaskWithPathArgumentsTimeout("/usr/bin/whoami", [], 5);
That executes the whoami command that lives in the /usr/bin directory. That command just prints out the logged in username which you can get at with result.stdout as you're already using.
I'm not quite sure what you're trying to do here, though. From the looks of the script you were trying to execute (fwasim/Desktop/registration.js), are you just trying to run some registration tests that are in a different file? If so, there's an easier way to do that. Just type this:
#import "fwasim/Desktop/registration.js"
That tries to import that JavaScript file as if it was relative to the directory of the script file that is running. You'd only need performTaskWithPathArgumentsTimeout() if you're trying to execute an external shell script or something like that. It's not for executing JavaScript inside UI Automation.

Related

Getting `spss.Submit` to log commands into the `output` window?

When I execute spss syntax commands from a .sps script, each command is written to the output window before it executes giving me a clear log of exactly how an output was created.
Even if the command is an INSERT command executing a different script - I get a log of the commands from that script.
This is very useful for many reasons:
sanity checking - I can always see exactly what went in to creating a specific output (which filters I used, etc.)
recreation - I (or someone else with this output) can easily re-run the same commands because they're right there.
debugging - if there's an error, I can see which commands caused it
However, when I run commands using spss.Submit inside a python block (in a BEGIN PROGRAM-END PROGRAM block), the actual commands called aren't logged into the output window.
I know I can find a full log in a log file - but that's not helpful.
Is there a way to tell spss to continue to log all the commands in the output window?
You can use set mprint on. before the begin program statement to have the syntax that is run via spss.Submit()show up in the output window. I like simpy putting it on the very top of my syntax file as a "set it and forget it".
For example like so:
set mprint on.
begin program python3.
import spss
vars = list(range(1,11))
for var in vars:
spss.Submit(f'compute v{var} = 0. ')
end program.

"** exception error: undefined function add:addfunc/0 in Erlang "

I'm trying to execute a simple erlang program of adding two numbers.
I'm trying to do this in Eclipse on Ubuntu 10.04 LTS.
When i execute this program, I'm getting the error as shown below:
** exception error: undefined function add:addfunc/0
How do i go about solving this error? Thanks in advance.
This program when executed in the erlang shell is working fine. But when it comes to eclipse it's giving me this error. Not this, any program for that matter is giving me the similar error. Guess I would be missing something about the eclipse configuration.
EDIT:
Anyways, This is the sample add program,
-module(add).
-export([addfunc/0]).
addfunc() ->
5 + 6.
This message tells you that module add doesn't have an exported function addfunc/0.
Ensure the function you want to be called has exactly that name, doesn't expect any
parameters, is
exported, the module is
compiled, the search path includes the compiled beam file and that there is no module clashes using code:clash()
Update
It's not clear how erlide (eclipse erlang plug-in you seem to use) compiles and runs a program. Try to compile source using erlc or inside erl shell. That way you'll have much easier controllable environment and you'll better understand what's going on.
I got exactly the same problem -for a tail recursive fibonacci function- below:
-module(math2).
-export([fibonacci/1]).
fibonacci(0) -> 0;
fibonacci(1) -> 1;
fibonacci(M) -> fibonacci(M-1) + fibonacci(M-2).
In the end, had realized that this is a compile-time exception. Then, have opened a new tab on my shell and tried with erlc, instead of erl.
$ erlc math2.erl
Now I am also able to see math2.beam file created.
Called fibonacci with 10:
4> math2:fibonacci(10).
55
and it worked!
I think you have not compiled the code and you are trying to run the program.
In eclipse, using the "Run" icon, trigger the run; which will get you to the erl shell in the console window.
There you do -
cd("C:\Learning_ERL\src").
And you should see output like-
(Learning-ERL#DALAKSHM-MNFSM)7> cd("C:\Learning_ERL\src").
c:/Learning_ERL/src
ok
Then compile the code -
c(add)
you should see something like this on the erl shell-
(Learning-ERL#DALAKSHM-MNFSM)10> c(add).
{ok,add}
Now you should be seeing a new file called - add.beam in the same directory as that of your erl source file - add.erl
add.beam is a bytecode file
Now you should be able to run the program without any error
How do you try to execute your code?
In your editor, right-click and choose "Run as"->"Erlang application". The VM that is launched will have your project loaded automatically and when editing/saving a file it will get reloaded. When launching, a console appears and you can call your code from there.
If it still doesn't work, what message do you get for m(add).?

Version 2.0 script causes exception when run under version 3.0

WRT this question -- I got something working by getting the current 'prompt' function as a string and writing a new .ps1 file defining 'prompt'.
In writing the new function, I put the functionality I want to add in a try/catch block, and write the existing prompt functionality into a finally block.
Not at all ideal, but it works in v2.0. When I run it in v3.0, I get an exception:
"Control cannot leave a finally block"
Is there any way to for a script to ask the host for a certain version's behavior?
Thanks for any insights.
Current 'prompt' function consists of:
return " > "
I want to add some functionality to the prompt function, so I write a new temp.ps1 file. I add my functionality in try/catch block, and include the existing in a finally block.
The temp.ps1 looks something like:
function global:prompt {
try {
pushd
}
catch {
$errors[0] | fl * -force
}
finally {
return " > "
}
}
This works as expected in v2, causes the "Control cannot leave..." error in V3.
If you plan to keep using Powershell V3, you cannot have a return statement in your finally block. See Page 6 of Windows Management Framework 3.0 Release notes: (You shouldn't need a return value there anyways)
http://download.microsoft.com/download/5/2/B/52B59966-3009-4F39-A99E-3732717BBE2A/WMF3%200%20Beta%20Release%20Notes.docx

Azure: Unable to start cloud service running vbs startup task

For some specific purpose, I need to install some fonts on the instances. It comes as no surprise when I choose StartUp Task to accomplish that goal. I've configured the Service Definitions as below:
<Startup>
<Task commandLine="Fonts\InstallFonts.vbs" executionContext="elevated" taskType="simple" />
</Startup>
Nothing special here. Click and run, it failed. However, if I changed the commandLine into a cmd file including just nonsense, namely "echo test", the instance would run without ado. So there must be some issue with my scripting:
Const FONTS = &H14&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("."))
Set fontFolder = objShell.Namespace(FONTS)
Set rxTTF = New RegExp
rxTTF.IgnoreCase = True
rxTTF.Pattern = "\.ttf$"
Set fso = CreateObject("Scripting.FileSystemObject")
FOR EACH FontFile IN objFolder.Items()
IF rxTTF.Test(FontFile.Path) THEN
IF NOT fso.FileExists(fontFolder.Self.Path+"\\"+FontFile.Name) THEN
FontFile.InvokeVerb("Install")
END IF
END IF
NEXT
The script should come with no error because I've tested it either locally or on Azure via RDP.
Weirdly, when I put it in the startup, the role just won't start. The instance just keeps recycling and at last says "I'm unhealthy". Even if I deprecate the vbs into just one line of code - the first line Const FONTS = &H14&, it just won't start. Even if I wrap the invocation of the vbs into a cmd file, namely to put something like "cscript /B file.vbs", it won't run either.
So I'm concluding that there must be some issue regarding the communication between the script and the Windows Azure monitor. I'm not sure but I think the monitor might take the running script as a failed task. Besides, I'm wondering if there is any timeout for the startup task, which should be the problem though, because the script can guarantee that no UI interaction block the process.
Any idea would be greatly appreciated.
I am sure you must have but just for the sake of confirmation, have you checked that the InstallFonts.vbs file is exported with the package? I mean is the "Copy To Output Directory" is set to "Copy Always/Copy if newer"?
This is pretty much possible that it is not able to locate your file.
You need to write a cmd file as a start up task. In your cmd file, you can call the vbs file using the command line tool cscript.
Azure start up can compile only command line tools.
Oh god, I finally solved the problem.
Although the compiler does quite a good job usually, it allows to use subfolder as a source of command, I mean something like "Subfolder\command.cmd", which will not work always. I've seen examples in which people put whatever we do in cmd in commandLine property, such as "copy fileA fileB" and it really works. But as for vbs, you need to be cautious. Until now I still don't know what's under the cover, but there should be some problem with the path. And the solution is definitely simple, instead of doing the subfolder work for tidiness, just leave the command file in the root folder like most people do:
<Startup>
<Task commandLine="InstallFonts.vbs" executionContext="elevated" taskType="simple" />
</Startup>
And thank you all the same, Kunal. :)

How to execute a .bat file from a C# windows form app?

What I need to do is have a C# 2005 GUI app call a .bat and several VBScript files at user's request. This is just a stop-gap solution until the end of the holidays and I can write it all in C#. I can get the VBScript files to execute with no problem but I am unable to execute the .bat file. When I "click" in the C# app to execute the .bat file a DOS window opens up and closes very fast and the test .bat file does not execute - "Windows does not recognize bat as an internal or external command" is the error returned in the DOS box. If I simply doubl-click the .bat file or manually run it from the command prompt it does execute. I also need the .bat file to execute silently unless a user interaction is required - this script copies 11k+ files to folders on a networked machine and occasionally Windows "forgets" if the destination is a file or directory and asks for the user to tell it what it is (this is a whole other issue not for discussion here...needless to say I am annoyed by it).
So far in my C# source I have this :
Process scriptProc = new Process();
if (File.Exists("c:\\scripts\\batchfile1.bat"))
{
scriptProc.StartInfo.FileName = #"cscript";
scriptProc.StartInfo.Arguments = ("cmd.exe", "/C C:\\scripts\\batchfile1.bat"); // Wacky psuedo code //
scriptProc.Start();
scriptProc.WaitForExit(1500000);
scriptProc.Close();
}
if (!File.Exists("c:\\scripts\\batchfile1.bat"))
{
}
I am aware that this code does not work - but it is essentially what I want it to do. What I am looking at is something like this for .bat files. I assume I have to tell the system to use cmd to run the .bat. I am at a loss as to how to do this. I have checked out this site which is for C# 2003. Not much help for me as I am very green with C#.
EDIT: Using Kevin's post I attempted it again. Same solution script from that post but modified for me since I do not need to redirect:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "C:\\scripts\\batchfile1.bat";
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
Here is what you are looking for:
Service hangs up at WaitForExit after calling batch file
It's about a question as to why a service can't execute a file, but it shows all the code necessary to do so.
For the problem you're having about the batch file asking the user if the destination is a folder or file, if you know the answer in advance, you can do as such:
If destination is a file:
echo f | [batch file path]
If folder:
echo d | [batch file path]
It will essentially just pipe the letter after "echo" to the input of the batch file.

Resources