Step that adds child steps automatically when test plan run is initiated

I have an ITestPlanImportCustomDialog that imports test plans from Excel. Many of my users use it exclusively, they rarely directly open TapPlan files. To simplify their workflow, I set about to eliminate the Import process by creating an alternative “Excel Test Plan” test step. The step just has one string property, the path to the Excel test plan.

In the setter of the step’s Excel file property, the Excel file is automatically imported as child steps. Then I can successfully run the test plan, so far so good.

But here’s where things get tricky. When the user initiates a test plan run, I am checking whether the Excel file has been modified, and if it has, I would like to re-import it, thereby modifying ChildTestSteps. But OpenTap doesn’t allow this, TestStep.ChildTestSteps.Add throws an exception when TestPlan.IsRunning == true.

Any thoughts? Is there a better way to approach this? Is this all just a bad idea? :wink:

2 Likes

Hi @david-wsd , thanks for your question.

First, to make sure my understanding of your problem is correct, you represent a TestPlan using Excel and you dynamically generate a TestPlan based on that (by adding child Steps to a parent step that points to the Excel file). That in itself is a valid use case.

However, modifying the TestPlan once it is in ‘running’ state is not allowed. There are a couple of ways I can think of that will let you can get around it:

  1. This is applicable if you are using the OpenTAP API. When the user ‘initiates’ run, in the button handler, you could first detect a change in your Excel file, generate the new TestPlan again then run it. All of this can be done programmatically.
  2. You could implement a FileSystemWatcher for the target Excel file and automatically regenerate a TestPlan upon file modification. For better performance, it may be preferable to just notify the user of a changed file (e.g. use Rules and show a red exclamation mark next to the FilePath or in your custom UI element, you could disable the button that lets the user move forward, ensuring they will reload the latest Excel file before running the TestPlan.

Let me know if any of the approaches above seem feasible for your use case and I’d be happy to discuss further. Also, do let me know a bit more about the host GUI application (is it KS8400 or a custom GUI?).

1 Like

Hi @navjodh_dhillon, thanks for the response.

For the GUI I’m using the standard KS8400 Editor. I need to work on item #1 in your last comment. I’m already doing something similar to what you describe in item #2.

You mentioned OpenTAP API, can you please provide some specifics?

1 Like

@navjodh_dhillon

When the user ‘initiates’ run, in the button handler

I’m using KS8400, is there a way to access that button event? Wouldn’t that be more of a hack?

1 Like

@david-wsd:

I’m using KS8400, is there a way to access that button event? Wouldn’t that be more of a hack?

Point 1 in my answer was assuming you’re using a custom GUI that calls into the OpenTAP API, and possibly has a button to initiate TestPlan execution, I didn’t mean the KS8400A run button.

OpenTAP API has well defined calls to generate/load and run a TestPlan. In that case it’s much easier to generate or modify a TestPlan just before you run it

1 Like

@david-wsd: KS8400A does not provide access to the Run button invoke event. And calling OpenTAP API to run a TestPlan from within a TestStep doesn’t make sense. So the best bet would be to identify changes to the Excel file and do something about it before pressing the Run button. Which is what point 2 above refers to. Looks like you’re doing something like that.

What you can do after the Run button is pressed is, have the Parent Step check Excel file modification status and display a dialog to inform the user and then abort the TestPlan. Probably not ideal.

What would be a solution you’d prefer? Based on that I can suggest what’s possible as of today and if we need to think of adding some capabilities to KS8400A to make it work.

1 Like

@navjodh_dhillon:

have the Parent Step check Excel file modification status and display a dialog to inform the user and then abort the TestPlan. Probably not ideal.

Thanks, this is exactly what I’m doing. It’s not ideal as you say, but it’s not too bad. The user simply has to click a “Load Test Plan” button every time they modify the Excel test plan file.

My preferred solution would be to eliminate the need for users to click “Load Test Plan” themselves. But it appears that solution would require a new OpenTAP feature, like a new interface that executes methods prior to a test plan run. This isn’t critical, as my existing solution just requires an extra button click. But I appreciate any further ideas about how to inch closer to the preferred solution.

SendKeys? :crazy_face:

2 Likes

Okay, @david-wsd. I agree, outside of a FileWatcher to automate regeneration of TestPlan, a new capability would be required. I’ve filed a feature request internally for the ability to have access to a modifiable instance of the TestPlan before locking it down for execution.

You may be able to get close to an automated way to do it with a FileWatcher though and you mentioned you were using that. You can set up and place the handler for FileSystemWatcher.Changed event in the parent Step and when that handler is invoked (upon file modification), you can regenerate the ChildSteps. But performance may be a factor to consider if the file is changed frequently.

SendKeys, isn’t that like the ‘GOTO statement’ of GUI development? :grinning:

2 Likes

SendKeys, isn’t that like the ‘GOTO statement’ of GUI development? :grinning:

ha! for sure!

I think it’s best to regenerate the child steps only when a plan run is initiated, not every time the Excel is modified. The event idea is an interesting alternative though. I think it would have a few issues though, including performance as you said.

1 Like

Hi @david-wsd

I have almost similar situation, difference is ,I don’t want to display child steps in the GUI, just run the steps is enough for me.

I used the below method to run the external steps.

public override void Run()
        {
            if (!(this.ChildTestSteps.Count > 0))
            {
                TestStepList macroStep = null; // Load Tap Steps 
                foreach (var item in macroStep)
                {
                    item.PlanRun = this.PlanRun;
                    item.StepRun = this.StepRun;
                    item.Run();
                }
            }
            else
            {
                this.RunChildSteps();
            }

            this.UpgradeVerdict(Verdict.Pass);
        }

Note : Not a fully tested solution , :slight_smile:

2 Likes

Yes, that is a good option. If I don’t need to display the child steps, or can make the display optional, then my problem statement no longer applies. Thanks @justin_c_i

1 Like