我想在我的運行過程中識別一些屬性,並形成一個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?或者是什麼? –