Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "I navigated to the (.+) page" page navigation step should use the PageNavigationAttribute Url value and not UrlTemplate since no parameters were specified #171

Open
icnocop opened this issue Sep 4, 2018 · 2 comments · May be fixed by #204

Comments

@icnocop
Copy link
Contributor

icnocop commented Sep 4, 2018

Hi.

The "I navigated to the (.+) page" page navigation step should use the PageNavigationAttribute Url value and not UrlTemplate since no parameters were specified.

For example, given the page:

[PageNavigation("/Account/Login", UrlTemplate = "/Account/Login?ReturnUrl={ReturnUrl}")]
public class LoginPage
{
}

When the following step is executed

Given I navigated to the Login page

Then I expected the step to navigate to the Url "/Account/Login".

Instead, it navigates to the Url "/Account/Login?ReturnUrl={ReturnUrl}" which is unexpected.

Thank you.

@dpiessens
Copy link
Collaborator

I think you might have the template wrong here, it should be /Account/Login?ReturnUrl={0} and then a parameter in the given step. Are you trying to specify the return URL dynamically or do something else?

@icnocop
Copy link
Contributor Author

icnocop commented Sep 4, 2018

I'm basically trying to re-use a page for the following steps that appear in different scenarios:

Given I navigated to the Login page
Given I navigated to the Login page with parameters
    | ReturnUrl             |
    | /WebApplication/Users |

In the case where the page is defined as

[PageNavigation("/Account/Login", UrlTemplate = "/Account/Login?ReturnUrl={ReturnUrl}")]
public class LoginPage
{
}

Then the step from scenario 2 works as expected. The UrlTemplate is correct as SpecBind uses RegEx.Replace and matches the parameter keys with regex group names to replace values.

Another example of the UrlTemplate can be found in https://github.com/dpiessens/specbind/wiki/Page-Navigation-Binding

A sample attribute value for the URL (http://mysite.com/products/1) would be "/products/{Id}".

The step from scenario 1 also uses the path specified in the UrlTemplate but without replacements so I get a 404 error after logging into my web application because the web application tries to redirect to user to the literal url "{ReturnUrl}" which doesn't exist.

Currently I have to work-around this by creating two similar classes:

    [PageNavigation("/Account/Login")]
    public class LoginPage
    {
    }
    [PageNavigation("/Account/Login", UrlTemplate = "/Account/Login?ReturnUrl={ReturnUrl}")]
    public class LoginWithReturnUrlPage : LoginPage
    {
    }

And use the following steps instead
1.

Given I navigated to the Login page
Given I navigated to the Login with return url page with parameters
    | ReturnUrl             |
    | /WebApplication/Users |

@icnocop icnocop linked a pull request Feb 21, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants