Using Data Dictionary in c# to get Forms between scripts

Hi,

I switched from c++ to c# for a project. I’m just trying to figure out an easy way to share a Form between scripts.

I previously used the c++ eggPlant Performance setCurrentForm() / getCurrent() Form functions to do this. I don’t see any alternative in c# API documentation.

I tried using Set();/Get(); but this seems to change the Form type to an object so after I Get the form back I can’t use it to set a Form variable as the type is Object.

Thanks,
Paul.

Hi Paul!

Glad to hear you made the switch to C#! Are you using an IDE at all for your script development?

The reason why setCurrentForm and getCurrentForm are not in the new API is mainly because they were rather limited in functionality, in other words only allowing you to store a single form object. Instead, it is now possible to store arbitrary Types in the Data Dictionary using the Set() and Get() methods, or even Set and Get (where T is an object type). So you were very close with what you suggested!

The syntax would look like this for a Form:


Form myForm = response1.ExtractForm("loginForm");

// using Set - here we don't need to specify the Type
Set("form1", myForm);

// using Set<T> - more explicit way of setting it:
Set<Form>("form1", myForm);

// using Get - here we need to explicitly cast the object to a Form:
Form myForm = (Form)Get("form1");

// using Get<T>
Form myForm = Get<Form>("form1");

Or perhaps for a list of strings:


List<string> dropdownOptions = response1.ExtractList("<option>", "<");

Set("dropDownList", dropdownOptions);

// in any script:
List<string> items = Get<List<string>>("dropDownList");

foreach (string item in items)
{
    WriteMessage("item name: "  + item);
}

I hope that answers your question. Let me know if you need anything else!

Regards,
Tom

By the way, are you using the latest version of ePP, namely 5.4? This contains a lot of new functionality for web scripting that you might be interested in. Specifically, our Generation Rules feature has had a major revamp and recordings have been separated from scripts, allowing you to create multiple scripts from a single recording. When you do this (e.g. to split out Login, repeated steps and Logout transactions), you will notice that any cross-script forms will be automatically handled by Generation Rules using the same API as I mentioned in my previous post.

Hi Tom,

Thanks for the reply (i missed out the casting!)

I am currently using the Scite Editor for coding. In terms of version number we are still using ePP 5.1 although i am planning to upgrade this when we get a windows 2008 server built.

The new generation rules sound pretty usefull, i think this is one of the features I will be looking at when we implement 5.4.

The splitting of scripting and recording also sounds pretty powerfull, I am sure this will save me a lot of time.

Regards,
Paul.