Forum Discussion
maximojo
12 years agoFrequent Contributor
Here's the function if anyone is keen. Not super advanced. Also there are a TON of parameters to tidy.exe which you should look at and customize for your use.
The TimeHelper object is a custom thing I wrote to help wait for X amount of time. I can post the faux jscript class if anyone wants it.
There are probably more errors I'm not handling but... well there you are :)
function CleanHTML_HTMLTidy(html)
{
var WshShell = new ActiveXObject("WScript.Shell");
if(WshShell == null)
{
Log.Error("CleanHTML - error creating WshShell object! Aborting!");
return false;
}
var filePath = Project.Path + "tempHTML.html";
if(!aqFile.WriteToTextFile(filePath, html, aqFile.ctUTF8, true))
{
Log.Error("CleanHTML - error writing temp file! Cleaning failed!")
return false;
}
var runObj = Runner.CallObjectMethodAsync(WshShell, "Run",
"U:\\Resources\\TestComplete\\SharedFiles\\html_tidy\\tidy.exe -m --tidy-mark no " + filePath, 1, false);
// wait for 10 seconds max
TimeHelper.Init(10000);
while(!runObj.Completed && !TimeHelper.TimeElapsed())
Delay(500);
if(TimeHelper.TimeElapsed())
{
Log.Error("CleanHTML - Timeout waiting for file to be processed! Aborting!");
return false;
}
var cleanHTML = aqFile.ReadWholeTextFile(filePath, aqFile.ctUTF8);
if(aqString.GetLength(cleanHTML) < 1)
{
Log.Error("CleanHTML - Cleaned file has 0 size! Aborting!");
return false;
}
return cleanHTML;
}
The TimeHelper object is a custom thing I wrote to help wait for X amount of time. I can post the faux jscript class if anyone wants it.
There are probably more errors I'm not handling but... well there you are :)
function CleanHTML_HTMLTidy(html)
{
var WshShell = new ActiveXObject("WScript.Shell");
if(WshShell == null)
{
Log.Error("CleanHTML - error creating WshShell object! Aborting!");
return false;
}
var filePath = Project.Path + "tempHTML.html";
if(!aqFile.WriteToTextFile(filePath, html, aqFile.ctUTF8, true))
{
Log.Error("CleanHTML - error writing temp file! Cleaning failed!")
return false;
}
var runObj = Runner.CallObjectMethodAsync(WshShell, "Run",
"U:\\Resources\\TestComplete\\SharedFiles\\html_tidy\\tidy.exe -m --tidy-mark no " + filePath, 1, false);
// wait for 10 seconds max
TimeHelper.Init(10000);
while(!runObj.Completed && !TimeHelper.TimeElapsed())
Delay(500);
if(TimeHelper.TimeElapsed())
{
Log.Error("CleanHTML - Timeout waiting for file to be processed! Aborting!");
return false;
}
var cleanHTML = aqFile.ReadWholeTextFile(filePath, aqFile.ctUTF8);
if(aqString.GetLength(cleanHTML) < 1)
{
Log.Error("CleanHTML - Cleaned file has 0 size! Aborting!");
return false;
}
return cleanHTML;
}