This is a migrated thread and some comments may be shown as answers.

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

3 Answers 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
wilfredo
Top achievements
Rank 1
wilfredo asked on 14 Jun 2011, 01:12 AM
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

3 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 16 Jun 2011, 12:21 PM
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
0
wilfredo
Top achievements
Rank 1
answered on 21 Jun 2011, 04:08 AM

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 

0
Cody
Telerik team
answered on 27 Jun 2011, 09:57 PM
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?
Tags
General Discussions
Asked by
wilfredo
Top achievements
Rank 1
Answers by
Stoich
Telerik team
wilfredo
Top achievements
Rank 1
Cody
Telerik team
Share this question
or