TestStack / TestStack.Seleno

Seleno helps you write automated UI tests in the right way by implementing Page Objects and Page Components and by reading from and writing to web pages using strongly typed view models.
http://teststack.github.com/TestStack.Seleno/
MIT License
180 stars 60 forks source link

MVC strongly typed partial view example #177

Closed beterthanlife closed 9 years ago

beterthanlife commented 9 years ago

Im trying to test strongly typed partial views which are requested through ajax and embedded into an existing page. I cant get my head around how to define the view models for the partial views when there are so many which ultimately exist on the same page.

Can you provide an example in the TestStack repo which shows how to achieve this?

robdmoore commented 9 years ago

Are you able to post a little sample of what you are referring to exactly?

Off the top of my head it sounds like the sort of thing you want to get a component for, but can provide more guidance if I know how it looks.

Thanks

beterthanlife commented 9 years ago

Consider a page which has a link to launch a wizard. The wizard is loaded via ajax and rendered inside a div which resides on the main page. The wizard has several screens and each screen has a different view model.

Take the following sudo code as an example of how I would structure these test pages.

public class MainPage : Page
{
    public WizardComponent Wizard
    {
        get { return GetComponent< RuleWizardComponent >(); }
    }
}
public class WizardComponent : UiComponent<WizardIntroModel>
{
    public WizardComponent EnterIntroSettings()
    {
        Input.Model(new WizardIntroModel());
        return this;
    }
    public WizardComponent EnterSummarySettings()
    {
        Input.Model(new WizardSummaryModel());
        return this;
    }
}

The problem is that WizardComponent class is bound to the display model WizardIntroModel, so I cant call Input.Model() and pass in a different display model. Is there a way to achieve this without making components for every screen in the wizard?

MehdiK commented 9 years ago

What about a generic WizardComponent?

public class MainPage : Page
{
    public WizardComponent<TWizardViewModel> WizardStepFor<TWizardViewModel>()
    {
        return GetComponent<TWizardViewModel>();
    }
}
public class WizardComponent<TWizardViewMode> : UiComponent<TWizardViewModel>
{
    public WizardComponent<TWizardViewModel> Input(TWizardViewModel vm)
    {
        Input.Model(vm);
        return this;
    }
}
robdmoore commented 9 years ago

Did the generic wizard component help mate?

On 27 Oct 2014, at 11:43 pm, Adam notifications@github.com wrote:

Closed #177.

— Reply to this email directly or view it on GitHub.