Forum Discussion
11 Replies
Hi Andrei,
You can re-execute a test item if there were errors during its execution. Here is an example:
function Test() {
var ErrCount = Log.ErrCount;
...
// Your test's code
...
// If the execution log contains errors, re-execute the routine
if (Log.ErrCount > ErrCount) {
Test();
}
}- tarleaaContributor
Thanks, that works .
But I was actually looking something like:Run a project, after the project is complete analyze the log, and then re-execute failed tests.
Can this be done as easily as re-executing a single test?
Hi Andrei,
You can declare a global array which will store the failed routine calls and a global integer variable which will store the current number of failed routines. In the last test item, you will need to check whether the number is greater than zero. If it is, you will need to call the eval function to call the failed routines again. For example:
var a = new Array();
var totalFailed = 0;
...function LastTestItem() {
var ErrCount = Log.ErrCount;
...
// Your test's code
...
// If the execution log contains errors, save the routine call
if (Log.ErrCount > ErrCount) {
a[totalFailed] = "Test();"
totalFailed++
}
// Check whether there were errors
if (totalFailed > 0) {
for (var i = 0; i < totalFailed; i++) {
eval(a); // Call each of the failed routines
}
}
}- tarleaaContributor
Hello,
if I do Log.ErrCount > ErrCount in the body of the last test, doesn't this compare only the last test item's log with ErrCount variable, leaving the previous tests not checked?
Thank you,
Andrei
Hi Andrei,
That is correct. That is why, you also need to add the following code to each of the problematic routines:
function SomeTestItem() {
var ErrCount = Log.ErrCount;
...
// Your test's code
...
// If the execution log contains errors, save the routine call
if (Log.ErrCount > ErrCount) {
a[totalFailed] = "Test();"
totalFailed++
}
}Pay attention to the difference between this code and the code for the last test item provided in my previous message.
- tarleaaContributor
Hello,
I get a "Function Expected" error when the execution reaches eval(a). Any idea how I can fix this?
Thank you,
Andrei
Hi Andrei,
I guess, you have specified an incorrect routine call as a string parameter of the eval function. Make sure that a contains a valid function name. The following sample code works perfectly for me:
function Test1()
{
Log.Message("test");
}
function Test2()
{
eval("Test1();");
}- tarleaaContributor
Hello,
And what if the functions are in two different test items? I've tried the following code and could not get the eval function to work:
// TestItem_1:
var a = new Array();
var totalFailed = 0;
function Test1()
{
a[totalFailed] = "Test1();";
Log.Message("a[" + totalFailed + "] = " + a[totalFailed]);
totalFailed++;
}//TestItem_2:
//USEUNIT TestItem_1
function Test2()
{
Log.Message(a[0]); // No message is displayed
eval(a[0]);
}Thank you,
Andrei
Hi Andrei,
JScript does not support multiple units natively, so, this can be the cause of the problem indeed. We'll look into this. In the meantime, you can try using project variables instead of global variables (see the "Project and Project Suite Variables" help topic ( http://www.automatedqa.com/support/viewarticle.aspx?aid=2537 ) for more information).
- tarleaaContributor
Hello,
Is there a way to clear the current test item log from script, before test run is completed? Why do I need this? By using the first re-execution script on this page, the log comes back with errors even if on the second execution the test ran without errors, because the log also keeps the logs for the first execution of the test, which contained errors. Am I making sense? Can I somehow fix this?
Thank you,
Andrei
Related Content
Recent Discussions
- 21 hours agodhundley