Please help!!! I am trying to add some performtaskwithpathargumentstimeout functions to my ios UI automation javascript. Specifically I am submitting a form within the app and subsequently want to check that it has been submitted successfully. However I am having problems.
I want to do several things. The ideal was to do a curl request to a url, and then search the stdout body that comes back to ensure that several keywords were there. However, instruments keeps crashing when I try and use any indexOf or .search functions on the result.stdout...
I thought another option would be to output the html to a file, and then search that file by writing a command line application which will search for the keyword passed as an argument. However, when I try and output the file to a directory using the following-
var target = UIATarget.localTarget();
var host = target.host();
result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["-o /Users/andrewweaver/Documents/output.html", "http://www.google.co.uk"], 30);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
I get the following error-
Warning: Failed to create the file /Users/me/Documents/output.html:
\nWarning: No such file or directory
This directory DOES exist, and has permissions for anyone to read & write to it.... also, if I create the .html file in that directory the same thing happens. If I run the same command from terminal it works fine...
I also wanted to do a write out of the http code...
result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["--write-out %{http_code}", "http://www.google.co.uk"], 30);
But again, that is failing....
curl: option --write-out %{http_code}: is unknown
I'm not sure what I'm doing wrong....
Any help would be much appreciated : - )
Fixed it. Each of the args passed into performTaskWithPathArgumentsTimeout needs to be separated by "" and a ,
So, for example to query a website and write the output to a file...
var host = target.host();
var result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["-o", "/Users/me/Documents/football.html", "http://www.bbc.co.uk/"], 30);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
And then to search the outputted file for a particular element I use grep...
var str = "BBC Sport - Football";
var result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/grep", ["-w", (str), "/Users/me/Documents/football.html"], 15);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
This will return a 0 if the regex is found, and BBC Sport - Football as the stdout.
I can then use an if statement to pass or fail (or use a tuneup js assert) based on whether the expected expression is present...
Useful for sending requests to webservices and then verifying the content...
Related
I'm using Lua in Scite on Windows, but hopefully this is a general Lua question.
Let's say I want to write a temporary string content to a temporary file in Lua - which I want to be eventually read by another program, - and I tried using io.tmpfile():
mytmpfile = assert( io.tmpfile() )
mytmpfile:write( MYTMPTEXT )
mytmpfile:seek("set", 0) -- back to start
print("mytmpfile" .. mytmpfile .. "<<<")
mytmpfile:close()
I like io.tmpfile() because it is noted in https://www.lua.org/pil/21.3.html :
The tmpfile function returns a handle for a temporary file, open in read/write mode. That file is automatically removed (deleted) when your program ends.
However, when I try to print mytmpfile, I get:
C:\Users\ME/sciteLuaFunctions.lua:956: attempt to concatenate a FILE* value (global 'mytmpfile')
>Lua: error occurred while processing command
I got the explanation for that here Re: path for io.tmpfile() ?:
how do I get the path used to generate the temp file created by io.tmpfile()
You can't. The whole point of tmpfile is to give you a file handle without
giving you the file name to avoid race conditions.
And indeed, on some OSes, the file has no name.
So, it will not be possible for me to use the filename of the tmpfile in a command line that should be ran by the OS, as in:
f = io.popen("python myprog.py " .. mytmpfile)
So my questions are:
Would it be somehow possible to specify this tmpfile file handle as the input argument for the externally ran program/script, say in io.popen - instead of using the (non-existing) tmpfile filename?
If above is not possible, what is the next best option (in terms of not having to maintain it, i.e. not having to remember to delete the file) for opening a temporary file in Lua?
You can get a temp filename with os.tmpname.
local n = os.tmpname()
local f = io.open(n, 'w+b')
f:write(....)
f:close()
os.remove(n)
If your purpose is sending some data to a python script, you can also use 'w' mode in popen.
--lua
local f = io.popen(prog, 'w')
f:write(....)
#python
import sys
data = sys.stdin.readline()
Edit: The example below did actually work, I misinterpreted the output the compiler gave me. The answer may still be helpful to some.
Is there a way for an action in a rule to generate a file that is consumed by a later action in that same rule?
E.g.:
def _example_rule_impl(ctx):
thefile = ctx.actions.declare_file("required_file.json")
ctx.actions.write(
output = thefile,
content = "CONTENT",
)
args = ctx.actions.args()
args.add("--config", thefile)
ctx.actions.run(
inputs = ctx.files.srcs + ctx.files.deps + [thefile],
outputs = outs,
arguments = [args],
progress_message = "Compiling...",
executable = ctx.executable._compiler,
)
The main problem with this seems to be, that all action outputs seem to be written to bazel-out, but the run action requires the generated file to be written next to the srcs and deps files in the execroot for it to work. Is there a way to have an action write to the execroot or is this not the correct approach?
Actions taking the outputs of other actions as inputs is a very typical thing to do, and should basically just work as you've set it up. Bazel takes care of handling input and output files, e.g., on linux using a lot of symlinks, mounting things in sandboxes, uploading and downloading files for remote execution, etc.
See
https://docs.bazel.build/versions/main/output_directories.html
Also, regarding this line:
inputs = ctx.files.srcs + ctx.files.deps + [thefile],
Depending on what you need to do, you may want to use depsets for performance reasons. See https://docs.bazel.build/versions/main/skylark/depsets.html
and in particular at the end https://docs.bazel.build/versions/main/skylark/depsets.html#performance
I'm writing some scripts in ActionScript to automate some tasks in Adobe Indesign 2019 (part of the Creative Cloud Suite), but this applies to all scripting for all applications in Adobe Creative Cloud.
I don't want to use ExtendScript Toolkit for editing/running the script, because it is terribly slow.
Because there is no such thing as console.log() available (at least that I'm aware of) and alert() will stop for user input to continue, I created a small file logger, but it does not append the file, but keeps on overwriting the first line. I use tail -f indesign.log to monitor the log file.
Here is the code of the logger
function logger(message){
var logFilePath = new File ('indesign.log');
logFilePath.encoding = 'UTF-8';
try {
logFilePath.open('a');
}
catch(err) {
logFilePath.close();
logFilePath.open('a');
}
logFilePath.write(new Date().toLocaleString() +": " + message + "\n");
//logFilePath.writeln(new Date().toLocaleString() +": " + message + "\n");
logFilePath.close()
}
logger("Script started")
logger("2nd line")
logger("3rd line")
logger("4th line")
logger("Script finished")
I tried also using writeln instead of write, but it does not make a difference.
I tried different line feeds, like "\n" and "\r\n", but it does not make a difference.
I tried different File.open options like .open('w'), .open('ra'). The documentation about this is either not clear or really outdated (Or I just can't find it).
Any suggestions in the comments about the best IDE to edit/run ActionScripts is highly appreciated.
I am attempting to record audio on an iPhone using PhoneGap, then send that audio to a server. I am using PhoneGaps Media APIs to make the recording, then the PhoneGap file transfer API to send the file to the server.
I am able to make the recording just fine, and playing it back works perfectly. When I try to send it to the server, however, the recording shows up on the server but it says the file is 0k big.
I've done fairly extensive searching on this issue and found others that have had this problem. For example: https://groups.google.com/forum/#!topic/phonegap/zjzSs6JVokE
function win(r) {
alert("Code = " + r.responseCode);
alert("Response = " + r.response);
alert("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
function upLoad() {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=myPath.substr(myPath.lastIndexOf('/')+1);
options.mimeType="audio/wav";
var params = new Object();
var headers={'headerParam':'headerValue'};
options.headers = headers;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(encodeURI(myPath), encodeURI("http://myserver.com/upload.php"), win, fail, options);
}
Here is the code on the server side:
print_r($_FILES);
$new_image_name = "testFile.wav";
move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/wwwroot/recordings/".$new_image_name);
I think that this may be an issue with the fact that I am sending .wav files. When I send the file over, r.bytesSent usually shows about 200 to 400 bytes (regardless of the size of the file), so it seems like the actual content of the file just isn't being sent over.
I have tested the above code with a simple text file and it goes through just fine, so I don't think it's a permissions or syntactical issue. I haven't tried this with image files, but I can't imagine it makes to much of a difference what I am sending.
Has anyone done this successfully?
I managed to solve this a few days ago.
It's about the myPath variable in the question's example.
myPath can't be anything other than the tmp folder (the temporary folder phonegap/device creates)
So when you try to send a file, you know for sure a copy of that file was made in the tmp folder.
So do this just before the ft.upload:
myPath = myPath.replace(myFolderPath, 'tmp');
In my case myFolderPath was 'Documents\media'.
The Documents path is where the custom created files are kept on your device.
I hope this saves people from all visited google search pages :)
(This worked for phonegap 3.0.0)
I use this code to log the many lines (SQL.Add) making complex scripts i have to build:
Ex:
[...]
SQL.Add('ENTITY_ID, PRO_CODE, PHASE_CODE, TASK_CODE, PERIOD_REF');
SQL.Add('from ' + trim(SourceJrnl) + ' where');
SQL.Add('MASTER_ID = ' + IntToStr(TranID) + ' and');...
[...]
{ for debugging only }
for i := 0 to SQL.Count-1 do
ShowMessage('Line #' + IntToStr(i+1) + ' : '+ SQL.Strings[i]);
Any simple way (function) to have the lines written to a file out of a stringlist or memo.
[EDIT] Sorry. NO memo or stringlist but a simple log file.
Calling SQL.SaveToFile will write the query to a file, but it will clobber the previous file contents, so you can only see one query and no other logs. Instead, read the SQL.Text property to get all the lines in a single string, and then write it to your log file using whatever logging technique you have for the rest of your program. In a pinch, a simple way to write a line of text to a file is to call Writeln, but people have asked about real logging libraries before.