Forum Discussion

TestQA1's avatar
TestQA1
Frequent Contributor
2 years ago

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.

 

 

    • TestQA1's avatar
      TestQA1
      Frequent Contributor

      Great thanks rraghvani I managed to fix it using the ini file using Storages. 

      The only thing I noticed that when I used the below code, it creates the section "Settings" from scratch and not just updated the field "Type". 

       

      function TestProc()
      {
        var w, Section;
        w = Storages.INI("C:\\testini.ini");
        Section = w.GetSubSection("Settings");
        Section.SetOption("Type", 6);
        w.Save(); }

       

      Let's suppose the content of the files is:

      [Root]

      [Settings]
      Access=ReadWrite
      Type=1

      [Temp]
      Mask=*.log

  • rraghvani's avatar
    rraghvani
    Champion Level 3

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

     

     

    • TestQA1's avatar
      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's avatar
    rraghvani
    Champion Level 3

    Here's an example: TC Project

    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's avatar
      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? 

    • TestQA1's avatar
      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's avatar
    rraghvani
    Champion Level 3

    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's avatar
      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

       

       

      I also tried your code, but still getting zero.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Can you create this project,

    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?

  • TestQA1's avatar
    TestQA1
    Frequent Contributor

    Ok I will create the same.

     

    Meanwhile, is there any way I can keep the last value from one feature to the next in a Project variable in test complete.

    Let's say I have a variable count which is 1 during feature 1 run

    When I run the next feature, it should still be 1 not 0 (default value).

    I tried both temp and persistent variables but they initialize back to 0 after each feature run.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Temp is like a traditional variable but stored on the project level and, as you note, is cleared from memory after each run.

      Persistent is stored with the variable in the project file.  However, note that, because it's stored in the MDS, anytime you replace the MDS (like retrieving the latest version of the code), you'll reset the value back to what is in the MDS.

      So, Temp is more like a true variable while persistent is more like a constant.

      • TestQA1's avatar
        TestQA1
        Frequent Contributor

        Thank you tristaanogre  for the explanation, it is very useful.

        I'm sorry I wrote Temp instead of Type which I have now corrected in my previous post.

        So the code above where it updates the value of 'Type' , writes the Settings section all over again, so it also moves the root section at the bottom which changes my current ini structure. 

        So I was looking for a code that only updates 'Type' value and doesn't write the Settings section again.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The value of the persistent variable will remain, during the execution of tests, but not during opening & closing instances of TestComplete. If you want to save the value, then store the value to a file.

     

    Have you thought about using Execution Plan Editor to run your tests?

    • TestQA1's avatar
      TestQA1
      Frequent Contributor

      I'm only using Exe. plan editor and it runs in batch file.

       

      Storing the value to a file, could you please give me a brief scenario.

  • TestQA1's avatar
    TestQA1
    Frequent Contributor

    Also, I still have to try your project where it updates the variables. So, in future, I don't face the same issue.

     

    Thanks again!