Skip to content

Access MVC Areas in Seleno UI Testing #257

Open

Description

@Kalyan-Basa

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

Ex:
Area1

  • Apply
  • Accepted
  • Rejected

Similarly for Area2

  • Apply
  • Accepted
  • Rejected

The following are the routes

  • Area1/Apply/ActionMethod
  • Area2/Accepted/ActionMethod

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.

Activity

  1. mwhelan commented on Mar 23, 2017

    @mwhelan
    Member

    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

  2. Kalyan-Basa commented on Mar 23, 2017

    @Kalyan-Basa
    Author

    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

  3. mwhelan commented on Mar 23, 2017

    @mwhelan
    Member

    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);
    
  4. Kalyan-Basa commented on Mar 23, 2017

    @Kalyan-Basa
    Author

    No, it doesn't help.

  5. mwhelan commented on Mar 23, 2017

    @mwhelan
    Member

    Do you have the areas registered in RegisterRoutes method?

  6. Kalyan-Basa commented on Mar 23, 2017

    @Kalyan-Basa
    Author

    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 }
                );
            }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions