Ask a Question

Incrementing Project.Variables from command line test execute

SOLVED
TestQA1
Frequent Contributor

Incrementing Project.Variables from command line test execute

Hi,

 

I have the below test structure but the variable not getting value from the command line.

 

Variable page -> Temporary 

I have a var called count which has 0 as default value

I have a command line in which I have added TestComplete.exe "C:\Work\My Projects\MySuite.pjs" /run /pv:count=%x%

here %x% = 0,1,2,.... (increments each time command line executes) depends on the test run 1,2,3,4....

 

I have a After Feature hook that stores:

var count = Project.Variables.count;

Log.Message(count);

 

The problem is that count is always 0.

 

 

17 REPLIES 17
rraghvani
Trusted Contributor

Can we see the full command/parameter that you are using please? I want to see how %x% is populated

 

 

TestQA1
Frequent Contributor

setlocal enableextensions enabledelayedexpansion
set /a "x = 0"
set /a "timeout = 1"
:while1
echo top
if %x% leq 1 (
Call %loc6%\abc.bat
goto Other
:middle
set /a "i = x + 1"
echo x: %x%, timeout: %timeout%, i: %i%
%loc0%\testexecute.exe "%loc3%" /r /p:%project% /t:ProjectTestItem%i% /PrjVar:count=%x% /DoNotShowLog /timeout:%timeout% 
echo %x%
if ERRORLEVEL 4 (goto timeout)
if ERRORLEVEL 3 (goto generalfail)
goto closesoftware
goto exitsoftware
:bottom
set /a "x = x + 1"
goto :while1
)
goto Exit

..........................................................

The count variable type is 'Integer' in the Variables page.

rraghvani
Trusted Contributor

Here's an example: TC Project

rraghvani_1-1679588064927.png

Batch file,

 

echo off
setlocal enableextensions enabledelayedexpansion
set /a x = 1

:loop
if %x% leq 5 (
	echo x: %x%
	"c:\Program Files (x86)\SmartBear\TestComplete 15\x64\Bin\TestComplete.exe" "c:\Sandbox\ALT\TestComplete\Number\Number.pjs" /run /exit /project:Number /prjvar:Var1=%x% /donotshowlog
	set /a x = x + 1
	goto :loop
)

:end
echo finished

 

It will loop 5 times, calling TC and passing the appropriate variable %x%

 

Try write something simple, and get it to work.

TestQA1
Frequent Contributor

@rraghvani Thanks for your reply!

 

The %x% increments in my code with every run, don't know why it doesn't update the variable though.

Because, I am using test execute, will that also update the variable like you have done with test complete.exe? 

rraghvani
Trusted Contributor

Yes, it will update. 

 

Note that parameter /exit

TestQA1
Frequent Contributor

Tried everything, no luck! I'm totally stuck. Really need to get it working. I got test complete 14, is that something to worry about?

Also, the command line arguments depends too much on when the text execute exits/stops. When exactly I need to stop the test execute if I want to pass the project variable value? In my test, I exit the test execute in Error handler as well.

rraghvani
Trusted Contributor

If you were to call the command (amend for TestExecute) and pass the variable,

"c:\Program Files (x86)\SmartBear\TestComplete 15\x64\Bin\TestComplete.exe" "c:\Sandbox\ALT\TestComplete\Number\Number.pjs" /run /exit /project:Number /prjvar:Var1=100 /donotshowlog

Does it show the number you passed, in the log file?

 

 

TestQA1
Frequent Contributor

echo off
setlocal enableextensions enabledelayedexpansion
set /a x = 1

:loop
if %x% leq 5 (
echo x: %x%
start /wait "C:\Program Files (x86)\SmartBear\TestComplete 14\x64\Bin\TestComplete.exe" "C:\Users\test\Documents\TestComplete 14 Projects\ProjectSuiteTest\ProjectSuiteTest.pjs" /run /e /p:TestProjecttt /t:ProjectTestItem1 /prjvar:count=%x% /donotshowlog /ExportLog:"C:\Users\test\Documents\TestComplete 14 Projects\TestLog.mht"
set /a x = x + 1
goto :loop
)

:end
echo finished

 

TestQA1_0-1679659334479.pngTestQA1_1-1679659365716.png

 

TestQA1_2-1679659397520.png

I also tried your code, but still getting zero.

rraghvani
Trusted Contributor

Can you create this project,

rraghvani_0-1679660672609.png

and call the command line,

 

"C:\Program Files (x86)\SmartBear\TestComplete 14\x64\Bin\TestComplete.exe" "C:\Users\test\Documents\TestComplete 14 Projects\Number\Number.pjs" /run /exit /project:Number /prjvar:Var1=100 /donotshowlog

 

To run the project in TestComplete please.

 

Then, open the project in TestComplete and look at the log file. What does the output show?

cancel
Showing results for 
Search instead for 
Did you mean: