1

I am trying to navigate to a specific URL as the Given statement for an automated test case and use a DateTime.Now structure to insert a required date into the URL for the browser to navigate to, unfortunately there is currently no way around navigating this way for this specific scenario.

My gherkin is:

 Scenario Outline: Search
    Given I Navigate to webpage with <date>

    Examples:
        | Variant | Date |
        | Web1    |      |
        | Web2    |      |
        | Web3    |      |
        | Web4    |      |
        | Web5    |      |  

My regex for the Given statement is as follows:

 [Binding]
    public class Search
    {
        [Given(@"I Navigate to WebPage with (.*)")]
        public void GivenINavigateToWebpageWith(int date)
        {
            DateTime localDate = DateTime.Now;
            String[] formats = { "yyyyMMdd" };
            String[] cultureNames = { "en-US" };
            DateTime date = new DateTime();
            CurrentBrowserNavigation("https://webpage.com/foo/bar/blah/blah/en-us/?startdate=" + date + "&anotherThing=1");
        }

I know this isn't correct and doesn't work currently but I'm a little lost as to how to properly construct this and was hoping to get pointed in the right direction by the community here. Hope this has enough detail!

2
  • Let me clear the picture a little bit right here. So you are trying to navigate to the URL something like this: webpage.com/foo/bar/blah/blah/en-us/?startdate=20171120&anotherThing=1 ?? Commented Nov 20, 2017 at 15:53
  • @GordonFreaman essentially yes. the startdate should ideally be formatted as 2017-11-20 but I'm not quite sure if C# accepts that.
    – Haney
    Commented Nov 20, 2017 at 15:58

1 Answer 1

1

Probably this will help as you mentioned that date format to expect is 2017-11-20:

            [Binding]
            public class Search
            {
                [Given(@"I Navigate to WebPage with (.*)")]
                public void GivenINavigateToWebpageWith(int date)
                {
                    var todayDate = DateTime.Now;
                    var localtime = todayDate.ToString("yyyy-mm-dd");                
                    CurrentBrowserNavigation("https://webpage.com/foo/bar/blah/blah/en-us/?startdate=" + localtime + "&anotherThing=1");
    }
}
1
  • Does C# not have a library to handle query params?
    – ernie
    Commented Nov 20, 2017 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.