Home > Back-end >  Selenium C#, Runing multiple test with predefined parameters
Selenium C#, Runing multiple test with predefined parameters

Time:12-28

I am looking for a way to predefine some parameters (URL's) and then run a selenium test for each of them in C#.

  • Where should I specify those URL's?
  • How to implement reading of those parameters in my code?
    [Test]
    public void Test(string URLParameter)
    {
        driver.Navigate().GoToUrl(URLParameter);
    }  
  • And how should I run those tests?

CodePudding user response:

If you are looking for a way to run the same test with a different set of test data i.e: a different URL in your case and If you are using

Either Nunit or xUnit

Please note all built-in attributes allow for data to be provided programmatically, but NUnit does not have any attributes that fetch the data from a file or other external source.

You can make use of

[TestCaseSource]

attribute

Please read more about it from Nunit Documentation

References:

CodePudding user response:

There are several ways to predefine and keep such test data.

  1. You can keep it in some external file. It can be JSON, XML or plain text formatted file.
  2. It may be kept in some resource C# class file inside the project.
  3. It can be kept in some kind of DB etc.
    Actual implementation of how to read this data will vary according to the way you decided to keep the test data, according to your project structure etc. There are several best practices how to do that, not only one way to do that.
    There are also several ways to run such tests. You can learn about these best practices on many online tutorials and other resources.

CodePudding user response:

For that purpose you should use multiple different ways to keep test data.

1- Kept in the resources folder of the project for example in
   properties file. 
2- Kept data in DB and read from there while
   needed.  
3- Kept in some external sources and read/retrieve if from
   there.

Note: Should use that method which will be convenient for you later on.

  • Related