Forum Discussion

Krishna_Kumar's avatar
Krishna_Kumar
Contributor
5 years ago
Solved

Project Variable

Hi Team, i am trying to Create a object at run time and pass the same object for all other script. for example, in Method1 - i have created an excel object(Excel.Applilcation) in Method2 - i ...
  • Mr_Bro's avatar
    Mr_Bro
    5 years ago

    Hi Krishna_Kumar ,

     

    initialize all your required objects in the OnStartTest Event handler and assign the same objects to a project variable in the same time, 

    and after that were ever you want you van use the required object by assigning a new temperory variable,

     

    please refer the below code snippet for your reference and let me know if your problem is solved.

    //Event Handler
    function GeneralEvents_OnStartTest(Sender){
        if(Project.Variables.VariableExists("MyObject"))
           Project.Variables.RemoveVariable("MyObject") 
        Project.Variables.AddVariable("MyObject", "Object");
        Project.Variables.MyObject = Sys.OleObject("Excel.Application")
    }
    
    //Accessing the Project Variable in different script Routine
    function testingprojectVariable()
    {
      excelApp = Project.Variables.VariableByName("MyObject")
      excelApp.Workbooks.Open("C:\\Users\\sathishkumark\\Desktop\\Source.xlsx")
      excelApp.DisplayAlerts = true
    ////Your Excel Operations...
    .............. }