Problem with my new Project... can't run test if the code are on the different class

4 posts, 0 answers
  1. wilfredo
    wilfredo avatar
    13 posts
    Member since:
    Jun 2011

    Posted 13 Jun 2011 Link to this post

    Just create new project, TestMethods are under GeneralTest.cs while the codes or public methods are under General.cs.

    General.cs contains

    public void LoadBrowser()
    {
        Manager.LaunchNewBrowser(BrowserType.InternetExplorer); //Error on this line
    }

    GeneralTest.cs

    [TestMethod]
    public void LaunchBrowser()
    {
        General.LoadBrowser();
    }

    Running the application return object reference not set to an instace of an object.
    Am i missing some reference

    Please guide solving my first problem.. thank you
  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 16 Jun 2011 Link to this post

    Hi Wilfredo,
        this behavior is expected. The static fields belonging to BaseTest are initialized once the test starts executing. You're trying to access fields in a BaseTest class that is never executed (since you're executing GeneralTest.cs) and because of this you're getting

    Object reference not set to an instance of an object

    You'll need to pass the fields you want to use from your "main" test to the methods in the General class.
    For instance:
    public void LoadBrowser()
    {
        Manager.LaunchNewBrowser(BrowserType.InternetExplorer); 
    }
    This would work if you change the method to look like this:
    public void LoadBrowser(Manager m)
    {
        m.LaunchNewBrowser(BrowserType.InternetExplorer);
    }
    and you invoke the method from your "main" class like this:
    General temp = new General();
    temp.LoadBrowser(Manager);
    However, I recommend that you refrain from using this implementation at all.

    Best wishes,
    Stoich
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. wilfredo
    wilfredo avatar
    13 posts
    Member since:
    Jun 2011

    Posted 20 Jun 2011 Link to this post

    Thank you. I tried something that i've seen around in the forum..

    Instead of passing this way:

    public void LoadBrowser(Manager m)
    {
        m.LaunchNewBrowser(BrowserType.InternetExplorer); 
    }

    I did pass it to the whole class.

    public class General
    {
    private Manager Manager;
    public General(Manager manager)
    {
    Manager = manager;
    }
      
    public void LoadBrowser()
    {
    Manager.LaunchNewBrowser.......
    }
    }
    which works also for me...

    By the way, what do you recommend for such approach. While using the Test Studio, i noticed that all fo the declaration of controls are inside the Pages.cs if we convert it to code. What were trying to do is to separate modules. Is there any possible related approach for this or some tweaking on the settings inside the test suite.

    Regards 

  4. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 27 Jun 2011 Link to this post

    Hi wilfredo,

    That approach for passing the Manager object looks like it will work well.

    Our Pages class is auto-generated from the contents of Elements Explorer. We designed it to be a "one stop shopping" place for all your elements used by all your tests to be stored. There is no setting or options for breaking this up. The only way to break it up is to create multiple tests projects. Each test project will then have it's own Pages class.

    Greetings,
    Cody
    the Telerik team
    Register today for a live 'What's New in Test Studio R1 2011 SP2' event on Tuesday, July 19 at 2pm EST!

    Have you looked at the new Online User Guide for Telerik Test Studio?
Back to Top