2016-07-18 12 views
0

私は現在、ユーザーのリスト(2人のユーザー、1人の管理者、1人の正規ユーザー)を含むVisual Studioのコード化されたUIテストに接続したCSVを持っています。C#Data Driven Testing Logic

CSV(つまり、両方のユーザー)のすべてのレコードに対して実行するテストがいくつかあります。しかし、いくつかのテストでは、私はCSVのレコードの1つのために実行したいだけです。

私のテストメソッド/データソースにそれを設定する方法はありますか?

これはデータ駆動型テストを初めて作成するため、newb質問をお詫び申し上げます。

+0

これはセレンにはまったく関係していないようです。必要なのは、単一のレコードだけを読み取るReadCSVを実装することです。フィクスチャ/カテゴリレベル以上のテストセットアップでReadCSVを呼び出し、複数回呼び出されることはありません。 – kurakura88

答えて

0

これはかなり簡単です。すべてのレコードに対してテストケースを実行する場合は、CSV内のすべてのレコードをループし、各レコードでテキストを実行します。特定のユーザーを名前または役割で識別するためのコードもいくつかあります。 Recordクラスを拡張して、必要なすべての属性を持つ必要があります。

namespace Selenium 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      IWebDriver Driver = new FirefoxDriver(); 
      Driver.Manage().Window.Maximize(); 
      Driver.Navigate().GoToUrl("<some url>"); 
      List<Record> records = readCSV(); 

      // this is for using all records 
      foreach (Record record in records) 
      { 
       // execute the test case using the current record 
       // do something with record.name and record.role 
      } 

      // this is for using only admins 
      foreach (Record record in records) 
      { 
       if (record.role == Record.Role.admin) 
       // if (Record.Role.name == "John Smith") // use something like this for a particular user name 
       { 
        // execute the test case using the current record 
        // do something with record.name and record.role 
       } 
      } 
     } 

     static List<Record> readCSV() 
     { 
      // START loop over each line in the CSV 
      List<Record> records = new List<Record>(); 
      string name = ""; // code that pull the user's name from the CSV 
      string role = ""; // code that pull the user's role from the CSV 
      records.Add(new Record(name, role)); 
      // END loop over each line in the CSV 

      return records; 
     } 
    } 

    class Record 
    { 
     public string name; 
     public Role role; 

     public Record(string name, string role) 
     { 
      this.name = name; 
      this.role = (Role)Enum.Parse(typeof(Role), role); 
     } 

     public enum Role 
     { 
      admin, regular 
     }; 
    } 
} 
+0

ありがとう、しかし私はTestCategoryとTestMethodの文脈で意味しました。今のところ、Microsoftはcsv [TestCategory( "Web")]のすべてのレコードをループします。 [DataSource( "Microsoft.VisualStudio.TestTools.DataSource.CSV"、 "C:\\ SourceControl \\\\public void ValidateLinks_CINavBar_Admin() {// Logic} – KillerSmalls

+0

あなたの質問を明確にし、上記のコメントにコードを追加する必要があります。質問そのもの。 – JeffC