Skip to main content

@AaronB I am tagging you on this.  You are the TestSDK guru and you might have a quick solution to this.  :-)

This is probably more of a C# question, but hopefully it is an easy answer.

I am running a large number of reports in TestSDK.  This is an example of the code I am using to run a report which works just fine.

public void APBalanceByGLAccount()
{
using (TestExecution.CreateTestStepGroup(ICSMessages.APBalancebyGLAccount))
{
AP632000APBalanceByGLAccount screen = new AP632000APBalanceByGLAccount();
screen.OpenScreen();
screen.Run();
screen.Excel();
}
}

Rather than have this code duplicated 50 times, I want to use a generic method where I just pass in the wrapper and generate the report.  When I explicitly setup the screen object above, it automatically gives me access to .Run() and .Excel().

The generic method code below runs and opens the screen for the GL Register report.  I just can’t find a way to run the report and export it to Excel.

public static void RunReport<T>()
where T : Wrapper, new()
{
Wrapper screen = new T();

screen.OpenScreen();

//how do i get a reference to pForm in the wrapper which contains the Run and Excel buttons?

//screen.Run();
//screen.Excel();
}

For the GL Register report, I call this method using:

RunReport<GL620500GLRegister>();

The code runs and opens the screen.  Yay!

This is the wrapper for this screen:

public partial class GL620500GLRegister : GL620500
{
public c__pform pForm { get; } = new c__pform("viewer_par_tab_t0_s0", "_pForm");
}

I think I need to get a reference to pForm so that the “screen” variable in my method sees the .Run and .Excel commands.  

How do I get a reference to those buttons?  Since this is being done “generically”, I cannot find a way to reference screen.Run().

 

 

 

Its great you found a unique way to use TestSDK efficiently.

I can give the advice to try using Dynamic control to select the run and Excel buttons. This will make it do a attribute/text search compared to a specific element name search as is usual.

You can also use Selenium code to press the buttons right inline with test SDK code to find a way to press the button on each report.

Hope I was able to help!


Thanks @AaronB 

This whole time I’ve been saying Wrappers.  I should have been saying Extension.  

Although, I can pass the Wrapper to the method and that still seems to work as the screen does open.

I tried about 50 things to get a reference to pForm in the Extension.  Spun my wheels for about 4 hours before crying for help.

This compiles but throws an error at runtime.

            //this throws an error
            //try to get a reference to the public pForm object in the wrapper
            var pForm = (Container)screen.DynamicControl<Container>("pForm");

I think pForm is not an “eligible” DynamicControl type since it is “Container”.  I think that is why it throws an error.

I may need to do the Selenium code, but that is a new thing I will need to learn.

The good thing is that my existing code I use to create reports will work without doing this generic approach.  But doing this will remove many thousands of lines of code.

You can imagine that block of code up above times 154 reports.  At least I am not blocked in my testing efforts.  I just don’t want to be embarrassed if someone sees the code and says OMG, you could do this with a generic method and save thousands of lines of code!  :-)

I really don’t like working with generics.


I figured out a way to do it.  Here is the code that works in case anyone ever wants to simply run and export a report using a generic method.

        public static void RunReport<W>()
            where W : Wrapper, new()
        {
            Wrapper screen = new W();

            screen.OpenScreen();

            Type t = screen.GetType();

            var runMethod = t.GetMethod("Run");
            runMethod.Invoke(screen, null);

            var excelMethod = t.GetMethod("Excel");
            excelMethod.Invoke(screen, null);
        }
 


Reply