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

Access MVC Areas in Seleno UI Testing #257

Open Kalyan-Basa opened 7 years ago

Kalyan-Basa commented 7 years ago

I have two modules in our Application and we have setup two areas for each of the module.

Ex: Area1

Similarly for Area2

The following are the routes

Using Seleno, I'm able to access routes without the Areas. i.e., /Apply/ActionMethod

But I want to integrate Areas as well in the Seleno UI Functional testing project.

While initiating SelenoHost, I have configured routes as below

Instance.Run("ProjectName", portNumber,
                config => config.WithRouteConfig(RouteConfig.RegisterRoutes)
                );

Thanks in Advance.

mwhelan commented 7 years ago

Hi @Kalyan-Basa . Assuming your areas are registered in the RegisterRoutes method, there is an overload of NavigateToInitialPage that takes a dictionary of route values. This can be used to populate the area value.

var routeValues = new Dictionary<string, object> { { "area", "Area1" } };
SUT.NavigateToInitialPage<TestController, TestPage>(c => c.Details(23), routeValues);

Thanks

Kalyan-Basa commented 7 years ago

Hi @mwhelan , I have tried the above approach but this how my URL is getting formed (Got this from browser Developer Tools.)

http://localhost:519/Test/Details?area=Area1

whereas, I wanted it to be

http://localhost:519/Area1/Test/Details

Thanks

mwhelan commented 7 years ago

Not sure if 'area' should be case sensitive? Try

var routeValues = new Dictionary<string, object> { { "Area", "Area1" } };
SUT.NavigateToInitialPage<TestController, TestPage>(c => c.Details(23), routeValues);
Kalyan-Basa commented 7 years ago

No, it doesn't help.

mwhelan commented 7 years ago

Do you have the areas registered in RegisterRoutes method?

Kalyan-Basa commented 7 years ago

Yes, I've my areas registered in MVC application like the below.

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
            routes.MapRoute(
                name: "Area1",
                url: "Area1/{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
            routes.MapRoute(
                name: "Area2",
                url: "Area2/{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }