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