Ask a Question

Executing a project from within a script.

SOLVED
clay
Contributor

Executing a project from within a script.

Is it possible to execute a the current project from JavaScript?  We have a scenario where we would like to execute a project, or a project folder/subfolder depending upon certain test conditions.  Something like...

 

switch(testCondition)

{

    case type1 : RunKeywordTestOnly(); break;

    case type2:  RunProjectFolderA(); break;

    case type3:  RunProjectFolderB(); break;

    default: RunProject(); break;

}

 

I don't see any Project object methods to do this.  It looks like one can only run keyword tests programmatically.

 

If the solution is to loop through the Project folders and subfolders to execute the tests, then how does one distinguish between a fold test item and a KWT test item in the hierarchy??

 

Thanks.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Marsha_R
Community Hero

Re: Executing a project from within a script.

https://support.smartbear.com/testcomplete/docs/working-with/managing-projects/in-scripts.html

Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

View solution in original post

tristaanogre
Community Hero

Re: Executing a project from within a script.


@cunderw wrote:

So the Project.TestItems, and TestItems object as mentioned in documentation do not have methods to run them. Only properties about the test item. There are a number of ways though you can control which ones to run.

 

What is your end goal though? Test items themselves are used to group and run in sequence different tests, so by trying to control this by a script in your project you're kind of defeating the purpose of the Test Items. 


If you want to control flow, customize test runs via code, etc., the best way to do so is to construct some sort of structure by which you feed in from some data source what test cases you want to run.  It could be something as simple as a single column CSV file with the names of each KeywordTest you want to execute.  A basic loop would then be something like:

 

var testRun = DDT.CSVFile('C:\\MyDir\\MyFile.csv');
while (!testRun.EOF) {
    KeywordTests[testRun.Value('TestName')].Run();
    testRun.Next();

}

Then, every time you want to build a different sequence of tests to execute, you just drop a different version of MyFile.CSV into the directory and click "Run".


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

10 REPLIES 10
karkadil
Valued Contributor

Re: Executing a project from within a script.

Hi clay,

 

It is not clear, where exactly do you run this code from? The code where you have this switch block.

Because it looks like you are looking for a way to run your tests from command line.

https://support.smartbear.com/testcomplete/docs/working-with/automating/command-line-and-exit-codes/...

clay
Contributor

Re: Executing a project from within a script.

To clarify - I am trying to run a script within TestComplete itself.  We are using JavaScript.

 

Thanks.

Marsha_R
Community Hero

Re: Executing a project from within a script.

This link may be helpful:

 

https://support.smartbear.com/testcomplete/docs/scripting/calling-project-items.html

Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
clay
Contributor

Re: Executing a project from within a script.

We are able to run KWT from script.  But what we are really looking for is the capability to run a project folder test item from a script as well as an entire project.

 

Thanks for the link.

Marsha_R
Community Hero

Re: Executing a project from within a script.

Sometimes you have to look farther on a page than just the title.  😉

 

I drilled down a little farther through the links on that page and subsequent pages and found this:

https://support.smartbear.com/testcomplete/docs/working-with/managing-projects/project-items/organiz...

 

which says

Addressing from scripts

Folders do not affect the way project items are addressed in scripts. For instance, if you organize elements of the Stores | XML project collection into several folders, you can still address them through the XML object.

 

Your project folders are really display only.  Only the TC folders (Stores, NameMapping, KeywordTests, etc.) are actual objects.

 

Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
clay
Contributor

Re: Executing a project from within a script.

If I understand what you are saying, Marsha, then we are talking about different folders.  I am speaking specifically of the folders one finds in the "Test Items" tab of the project - the ones with the checkboxes.  I am looking for a capability that allows me to execute by folder name within a script a folder from this list.  I know I can navigate through this folder hierarchy to find a folder and its descendant Keyword Tests, so I may have to write something myself.  It would sure be nice, however, if I could do this with just a simple call to a TestComplete object method.

Marsha_R
Community Hero

Re: Executing a project from within a script.

https://support.smartbear.com/testcomplete/docs/working-with/managing-projects/in-scripts.html

Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

View solution in original post

cunderw
Community Hero

Re: Executing a project from within a script.

So the Project.TestItems, and TestItems object as mentioned in documentation do not have methods to run them. Only properties about the test item. There are a number of ways though you can control which ones to run.

 

What is your end goal though? Test items themselves are used to group and run in sequence different tests, so by trying to control this by a script in your project you're kind of defeating the purpose of the Test Items. 


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
tristaanogre
Community Hero

Re: Executing a project from within a script.


@cunderw wrote:

So the Project.TestItems, and TestItems object as mentioned in documentation do not have methods to run them. Only properties about the test item. There are a number of ways though you can control which ones to run.

 

What is your end goal though? Test items themselves are used to group and run in sequence different tests, so by trying to control this by a script in your project you're kind of defeating the purpose of the Test Items. 


If you want to control flow, customize test runs via code, etc., the best way to do so is to construct some sort of structure by which you feed in from some data source what test cases you want to run.  It could be something as simple as a single column CSV file with the names of each KeywordTest you want to execute.  A basic loop would then be something like:

 

var testRun = DDT.CSVFile('C:\\MyDir\\MyFile.csv');
while (!testRun.EOF) {
    KeywordTests[testRun.Value('TestName')].Run();
    testRun.Next();

}

Then, every time you want to build a different sequence of tests to execute, you just drop a different version of MyFile.CSV into the directory and click "Run".


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: