Forum Discussion

mwa's avatar
mwa
New Contributor
14 years ago

Integration with TeamCity from JetBrains

We use TeamCity from JetBrains as our integration server and are quite happy with it.



Is there a way to integrate TestComplete with it?
  • mmkumaram's avatar
    mmkumaram
    Occasional Contributor
    Mark,



    I was referring to starting the Teamcity agent services manually from command prompt, Usually when you install teamcity agent on a test machine, it installs a Build Agent(mandatory) and Windows service(optional). Once the agent is installed, you need to start the service in order to interact with the server, the Agent can can started either through windows services or manually from command prompt.



    Follow the below steps to start agent from command prompt rather than from windows service.



    1. If you have selected Windows Service while installing teamcity agent, Stop/disable the Teamcity service from windows services

    2. Open Command prompt(run as administrator on windows vista/7)

    3. Change directory to teamcity install folder(by default it would be c:\BuildAgent).

    4. Change directory to  C:\BuildAgent\bin folder.

    5. Run Agent.bat file with a parameter start.(eg:C:\BuildAgent\bin\>agent.bat start)

    6. Teamcity agent service should start.



    Thanks,

    Muthu
  • mark_k92's avatar
    mark_k92
    Occasional Contributor
    When I start the build agent service via command line, the TeamCity Build Agent Dos Console pops up and starts show many lines of code with many errors. Doing this also creates another issue, all build configurations are now incompatible with this agent for this reason:

    Missing VCS plugins on agent:

    • Subversion


    Have you any idea why that is happening or how to solve the issue?
  • mark_k92's avatar
    mark_k92
    Occasional Contributor
    Ignore my previous comment, I have managed to sort those problems out.

    Now it working that you very much!

    I Have one question I have found a document on-line showing the results of a test-complete test feeding results into teamcity like shown in my image attached. 

    Any idea on how to achieve this?



    Thanks,



    Mark.
  • mmkumaram's avatar
    mmkumaram
    Occasional Contributor
    Good to know that its working now.



    Regarding results, While we run the test from test complete we output two type of test results

    1. A text/xml file which contains the total number of test passed and failed, which is then used in msbuild to post results in Teamcity build summary. Below is the MSbuild code that reads the text file and prints results in teamcity.

     <Target Name="SummarizeResults">
        <ItemGroup>
          <NbTestsFailedFile Include="$(MSBuildProjectDirectory)\..\..\Reports\TotalNbTestsFailed.txt"/>
          <NbTestsAbortedFile Include="$(MSBuildProjectDirectory)\..\..\Reports\TotalNbTestsAborted.txt"/>
          <NbTestsPassedFile Include="$(MSBuildProjectDirectory)\..\..\Reports\TotalNbTestsPassed.txt"/>
          <BuildDateFile Include="$(MSBuildProjectDirectory)\..\..\Reports\BuildDate.txt"/>
        </ItemGroup>
        <ReadLinesFromFile
         File="@(NbTestsFailedFile)" ContinueOnError='true'>
          <Output
              TaskParameter="Lines"
              ItemName="testsFailed"
    />
        </ReadLinesFromFile>
        <ReadLinesFromFile
        File="@(NbTestsAbortedFile)" ContinueOnError='true'>
          <Output
              TaskParameter="Lines"
              ItemName="testsAborted"
    />
        </ReadLinesFromFile>
        <ReadLinesFromFile
        File="@(NbTestsPassedFile)" ContinueOnError='true'>
          <Output
              TaskParameter="Lines"
              ItemName="testsPassed"
    />
        </ReadLinesFromFile>
        <ReadLinesFromFile
        File="@(BuildDateFile)" ContinueOnError='true'>
          <Output
              TaskParameter="Lines"
              ItemName="buildDate"
    />
        </ReadLinesFromFile>
      </Target>

      <Target Name="TestLogging">
        <TeamCitySetStatus Status="FAILURE" Text="Tests Failed:@(testsFailed), Passed:@(testsPassed), Aborted:@(testsAborted); Build:@(buildDate)" Condition ="'@(testsFailed)' != '0' And '@(testsFailed)' != ''"/>
        <TeamCitySetStatus Status="ERROR" Text="Tests Failed:@(testsFailed), Passed:@(testsPassed), Aborted:@(testsAborted); Build:@(buildDate)" Condition ="'@(testsFailed)' == '' Or  '@(testsAborted)' != '0'"/>
        <TeamCitySetStatus Status="ERROR" Text="Tests Failed:@(testsFailed), Passed:@(testsPassed), Aborted:@(testsAborted); Build:@(buildDate)" Condition = "'@(testsFailed)' == '0' And  '@(testsAborted)' == '0' And  '@(testsPassed)' == '0'"/>
        <TeamCitySetStatus Status="SUCCESS" Text="Tests Failed:@(testsFailed), Passed:@(testsPassed), Aborted:@(testsAborted); Build:@(buildDate) " Condition ="'@(testsFailed)' == '0' And  '@(testsAborted)' == '0' And  '@(testsPassed)' != '0'"/>
        <Error Text = "FAILED" Condition =" '@(testsFailed)' != '0' And '@(testsFailed)' != ''"/>
        <Warning Text = "ABORTED" Condition =" '@(testsFailed)' == '' Or  '@(testsAborted)' != '0'"/>
        <Warning Text = "ABORTED" Condition =" '@(testsFailed)' == '0' And  '@(testsAborted)' == '0' And  '@(testsPassed)' == '0'"/>
        <Message Text = "PASSED" Condition =" '@(testsFailed)' == '0' And  '@(testsAborted)' == '0' And  '@(testsPassed)' != '0'"/>
      </Target>



    2. Html result file which contains the test steps and its results.These html files are copied to teamcity build artifacts and then displayed on the Test Summary Page. Refer :http://confluence.jetbrains.net/display/TCD5/Including+Third-Party+Reports+in+the+Build+Results to find out how to set up custom build report tabs in teamcity.



    Hope this is useful.



    Thanks,

    Muthu








  • mark_k92's avatar
    mark_k92
    Occasional Contributor
    Just wondering how you export your results into an xml/txt or html file? In one of my scripts I have added the line: Log.SaveResultsAs("c:\\MyResultLog.xml",0) sure enough it creates the file but this is all it is:




    <?xml version="1.0" encoding="UTF-8"
    standalone="no" ?>

      <!DOCTYPE Nodes
    (View Source for full doctype...)
    >



    - <Nodes version="1">





    - <Node name="root">





      <Prp name="completed"
    type="B"
    value="-1"
    />




      <Prp name="status"
    type="I"
    value="0"
    />




      <Prp name="test type"
    type="S"
    value="Scriptname" />




      <Prp name="computer name"
    type="S"
    value="bingo-bu" />




      <Prp name="root logdata name"
    type="S"
    value=""
    />




      <Prp name="error count"
    type="I"
    value="0"
    />




      <Prp name="user name"
    type="S"
    value="teamcity" />




      <Prp name="warning count"
    type="I"
    value="0"
    />




      <Prp name="root file name"
    type="S"
    value="RootLogData.dat" />




      <Prp name="start time"
    type="D"
    value="40807.6073301042" />




      <Prp name="stop time"
    type="D"
    value="40807.6076827431" />


      </Node>



      </Nodes>


     Although it does jnot contain any elements described like " testspassed" "testsaborted" etc.Sorry if this seems silly to ask but I haven't had much experience with testcomplete, could you show me how you produced the 
    TotalNbTestsFailed.txt files and all of those.
  • mmkumaram's avatar
    mmkumaram
    Occasional Contributor
    Well, these are custom files that we create manually while running the test. We have a framework that creates these files. Below is an example of a simple test that ouputs test summary file with pass count and fail count;



    Assume, you have a function called Login(username,password) and you want to call this five time with different values and report results.

    First i would create a data file called  LoginTest.txt which contains below test data.

    Login("user1","pwd1")

    Login("user2","pwd1")

    Login("user3","pwd1")

    Login("user4","pwd1")

    Login("user5","pwd1")



    In testcomplete I would create test function called Login(username,password) and a main function to call this.



    function Login(username,password){

    ...<your test here>

    if ("passed"){

    return true

    }

    return false

    }




        



    function main(){





      var TestsFileName ="LoginTest.txt"; #provide full path 

      var FailedTests=0;

      var PassedTests=0;


     var ForReading = 1;

       var ForWriting = 8;




      var fso = new ActiveXObject("Scripting.FileSystemObject");   

      if (fso.FileExists(TestsFileName) == true) {   

      var TestNameFromFile = TestsFileName.split("\\"); 

      TestNameFromFile = TestNameFromFile[TestNameFromFile.length - 1];

      var  TestName=TestNameFromFile ;

      TestsFileName = fso.OpenTextFile(TestsFileName, ForReading);    

      var TestFunction,result,TestCount ;

    TestCount =0;



      while (!TestsFileName.AtEndOfStream) {

         TestFunction = TestsFileName.ReadLine();

         result = eval(TestFunction);

         if ((result == "Failed") || (result == false) ) {

            FailedTests++;

            result = "Failed";

         }

         else{

            PassedTests++;

            result = "Passed";

         } 

         TestCount++;

       }

        var TestSetResultFile = "TestSummaryResults.txt";

        TestSetResultFile = fso.OpenTextFile(TestSetResultFile,ForWriting,true);

         TestSetResultFile.WriteLine(TestName+","+PassedTests+","+FailedTests+","+TestCount);

        TestSetResultFile.Close();

      }





    }



    here running the main function would create summary result file with test name, passed count, fail count etc of the test.. similarly you could create html and other files as well.





    Thanks,

    Muthu
  • mmkumaram's avatar
    mmkumaram
    Occasional Contributor
    here is another way to post results back to Teamcity from Test Complete, this solution updates test results in the default Test Tab similar to unit test. 



    Logging TeamCity readable
    results from TestComplete


    In TestComplete, while creating script for a test we output
    whether test results (passed/failed) to log. Along with this, we could output the
    result to a text file which could be recognized by TeamCity. Here is an example
    of running a test from TestComplete and logging results that could be read by
    TeamCity.


     


    function mainTest(){


    UpdateTeamCityResult("##teamcity[testStarted name='LoginTest']");

    var stepResult = LoginTest(); //returns passed if test is successful


    if (stepResult == "Passed"){


        UpdateTeamCityResult("##teamcity[testFinished name='LoginTest']"); 


       }


     
    else{


        UpdateTeamCityResult("##teamcity[testFailed name='LoginTest' message='test failed' details='Login test
    failed"+ stepResult+"']");


        UpdateTeamCityResult("##teamcity[testFinished name='LoginTest']");


      }


    }


    function UpdateTeamCityResult(data){


           
    var
    fso = new ActiveXObject("Scripting.FileSystemObject");


            
    var
    ForWriting=8;


            
    var TestSetResultFile
    =  "..\\Reports\\DetailedTestResults\\TeamCityResults.txt";


            
    TestSetResultFile = fso.OpenTextFile(TestSetResultFile,ForWriting,true);


            
    TestSetResultFile.WriteLine(data);


            
    TestSetResultFile.Close();


           
    return true;


    }


     


    Printing Teamcity Results
    from msbuild


    In msbuild script, after running a test, open the
    TeamCityResults.txt file and print it to build log, which is then read by
    TeamCity automatically.  Below is an example where we call the targets for
    set of tests and after running test it prints the TeamCity results.


     


     <Target Name="RunTest"   Outputs="%(TestFiles.Identity)" >


        <Message Text = "%(TestFiles.Identity)"/>


        <Exec ContinueOnError="true" Command="$(ProgramFiles) (x86)\Automated QA\TestExecute 8\Bin\TestExecute.exe&quot; $(MSBuildProjectDirectory)\..\..\Tests\TestRunner\TestRunner.pjs /run /project:TestRunner /SilentMode /ns /exit %(TestFiles.Identity)" />


          <PropertyGroup>



          <TeamCityResultFile>"$(MSBuildProjectDirectory)\..\..\Reports\DetailedTestResults\TeamCityResults.txt"</TeamCityResultFile>


        </PropertyGroup>


        <Exec ContinueOnError="true" Command="type $(TeamCityResultFile)"/> this line prints the test status
    to build log and TeamCity picks this up automatically and updates tests tab


      </Target>





    Thanks,

    Muthu

  • Mr Kumaran, I see that you are well versed with TeamCity and its integration with Testcomplete. I am facing similar issues. I was wondering if you could suggest me something.

    Looking forward to your reply
  • Oferv's avatar
    Oferv
    Super Contributor
    Hi Alex/anyone who knows,



    I have a build process that launch testcomplete and run my project now,i want to create a tab report the same as under this link: http://confluence.jetbrains.net/display/TCD5/Including+Third-Party+Reports+in+the+Build+Results but i followed the instructions of how to create this tab and i ran the build but,i can't see any tab created.



    what can be my problem here?i think my problem is with the "Base path" declaration.i'm generating a report and  save it by using Log["SaveResultsAs"](FileName, 2) is this is the file that i should point teamcity to?



    thanks
  • We just started using TeamCity for our software build process and already use TestComplete for automation. By reading the thread, I can see that it is possible to integrate the two which is great and I saw the attachments on how. I have a relatively easy question. We own a single build agent license for TeamCity, does anyone know if I have to buy additional licenses to run automation tests? I read the attachments to the thread but I am confused as to whether the automation environments count as agents or not. Note: This may be a better question for a TeamCity forum, but figured I would ask here just in case.