0

For the past few months I have been developing a test automation package for a web application using Selenium in C#.

In some of the tests I need to verify the driver arrived at the expected URL. So far I have been storing the expected URLs in a .resx file, but I was told this is not a very good approach.

I'm pretty new to programming so I'm sorry if this seems trivial.

Edit:

Just to clarify I'm looking for an approach to store the URLs. I don't want them hard-coded but I don't think a .resx file is a very good option either.

orm225
  • 32
  • 5

2 Answers2

1

You could use the Page Object Pattern and have the URLs for the pages as a const string within the page object. That is the way I have been doing it in my Selenium tests.

Some more useful information in the responses to this question

You could expose the constant url through a static method on the page object, and then use that to do your assertation against the web drivers current url.

EDIT: Based on the comments above, it seems your concern is having one source of truth for the URLs

You could have a static URL factory, like so:

public static class UrlFactory
{
    public static string URL1 { get{return "www.url.com";}}
    //repeat as necessary
}

Then when you are setting up your page objects, the URL could be passed in the constructor by calling UrlFactory.Url1 and this could assign its value to a private field within the page. Then when you are testing, you would call the same for your assertation like so:

Assert.AreEqual(UrlFactory.Url1, _webDriver.Url)

Community
  • 1
  • 1
David Watts
  • 2,249
  • 22
  • 33
  • That's a great suggestion! I am using POP so I have no idea why I didn't think about this in the first place. Unfortunately it doesn't really answer my question. I'll clarify the question. – orm225 Mar 06 '15 at 10:51
  • @orm225 I've added an extra line to my answer about how to expose these URL's for your assertations. If the url you are trying to assert against is not one within your application that you have created a page for, I think resources or excpected result strings within the tests is the only way to do it. – David Watts Mar 06 '15 at 10:55
  • It's not execrably what I was searching for but you were defiantly very helpful. – orm225 Mar 06 '15 at 11:12
  • I've added some more information to help with your testing and construction of the page objects. I hope this has really helped @orm225 – David Watts Mar 06 '15 at 11:15
0

I previously stored this kind of information (when using TestComplete) in an excel file. I kid you not.

My reason was because it was easy to share input vs output with my client.