我想在我的运行过程中识别一些属性,并形成一个json对象,我想写入一个“.json”文件并将其保存在磁盘上。如何在ui自动化中读取和写入文件(Javascript)?
var target = UIATarget.localTarget();
var properties = new Object();
var jsonObjectToRecord = {"properties":properties}
jsonObjectToRecord.properties.name = "My App"
UIALogger.logMessage("Pretty Print TEST Log"+jsonObjectToRecord.properties.name);
var str = JSON.stringify(jsonObjectToRecord)
UIALogger.logMessage(str);
// -- CODE TO WRITE THIS JSON TO A FILE AND SAVE ON THE DISK --
我想:
// Sample code to see if it is possible to write data
// onto some file from my automation script
function WriteToFile()
{
set fso = CreateObject("Scripting.FileSystemObject");
set s = fso.CreateTextFile("/Volumes/DEV/test.txt", True);
s.writeline("HI");
s.writeline("Bye");
s.writeline("-----------------------------");
s.Close();
}
和
function WriteFile()
{
// Create an instance of StreamWriter to write text to a file.
sw = new StreamWriter("TestFile.txt");
// Add some text to the file.
sw.Write("This is the ");
sw.WriteLine("header for the file.");
sw.WriteLine("-------------------");
// Arbitrary objects can also be written to the file.
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
sw.Close();
}
但仍无法读取和写入数据从UI自动化仪表
可能的解决方法文件? 如果我们可以从我的ui自动化脚本执行一个终端命令,重定向到stdout。那么我们可以从脚本执行终端命令吗?
还没试过: 1.假设我们可以包含具有这些方法的库并尝试一下。
你使用的是什么样的UI自动化工具,这个脚本是在普通浏览器中执行的吗? –
@ZigmaEmpire我试图执行正常的浏览器脚本,其中我的文书脚本 –
是这个脚本目前在浏览器上运行,如谷歌浏览器,Firefox?或者是什么? –