WinAppDriverを介した自動テスト
ReoGrid では UIAutomation WinAppDriver のインターフェイスに対応しているため、UIAutomation を利用し自動テストを行うことができます。
以下のオプションを true に設定して WinAppDriver を有効化できます。
unvell.ReoGrid.ReoGridControl.EnableUIAutomation = true;
このオプションは ReoGrid のグローバルオプションなため、1つの目の ReoGrid のインスタンスを初期化する前に実行してください。
サポートする要素
WinAppDriver を介して取得/操作できる要素は、以下の通りです。
- 全てのセル(見えないセルも含む)
- 行ヘッダー、列ヘッダー
- アウトラインの部、アウトラインのボタンなど
- セルのコントロール(チェックボックス、ドロップダウンリストなど)
サンプル/使用例
var reoGridControl = session.FindElementByClassName("ReoGridControl");
if (reoGridControl != null)
{
reoGridControl.Click(); // get focus
var worksheet = reoGridControl.FindElementByName("DefaultWorksheet");
if (worksheet != null)
{
... // テストを実行
}
...
}
セルとセルのデータ
セルの行列インデックスを指定してセルオブジェクトを取得できます(インデックスは0ベースです)。 セルは行オブジェクトに格納されているため、まず行オブジェクトを取得する必要があります。
Worksheet
Cell Row 0
Cell 0,0 / Cell 0,1 / Cell 0,2 / Cell 0,3
Cell Row 1
Cell 1,0 / Cell 1,1 / Cell 1,2 / Cell 1,3
// 0行
var cellRow0 = worksheet.FindElementByName("CellRow[0]");
if (cellRow0 != null)
{
// 0行 6列
var cell = cellRow0.FindElementByName("Cell[0,6]");
if (cell != null)
{
Debug.WriteLine(cell.Text);
}
}
### チェックボックスの選択/未選択
```cs
var cellRow1 = worksheet.FindElementByName("CellRow[1]");
if (cellRow1 != null)
{
var cell = cellRow1.FindElementByName("Cell[1,0]");
if (cell != null)
{
// before send keys to cell, ReoGrid control must be keyboard focused, perform a click before this.
cell.SendKeys(Keys.Space);
}
}
ドロップダウンの選択
var cellRow5 = worksheet.FindElementByName("CellRow[5]");
if (cellRow5 != null)
{
var cell = cellRow5.FindElementByName("Cell[5,3]");
if (cell != null)
{
cell.SendKeys("760");
}
}
列ヘッダーと列ヘッダーのメニュー
var columnHeaderCollection = worksheet.FindElementByName("ColumnHeaderCollection");
if (columnHeaderCollection != null)
{
var columnHeader3 = columnHeaderCollection.FindElementByName("ColumnHeader[3]"); // first row starts at index 0
if (columnHeader3 != null)
{
// Select a column
columnHeader3.Click();
}
var columnHeader5 = columnHeaderCollection.FindElementByName("ColumnHeader[5]"); // first row starts at index 0
if (columnHeader5 != null)
{
// Right click to show context menu
var actions = new Actions(session);
actions.ContextClick(columnHeader5);
actions.Perform();
}
}
行ヘッダーと行ヘッダーの選択
var rowHeaderCollection = worksheet.FindElementByName("RowHeaderCollection");
if (rowHeaderCollection != null)
{
var rowHeader3 = rowHeaderCollection.FindElementByName("RowHeader[3]"); // first row starts at index 0
if (rowHeader3 != null)
{
rowHeader3.Click();
}
var rowHeader5 = rowHeaderCollection.FindElementByName("RowHeader[5]"); // first row starts at index 0
if (rowHeader5 != null)
{
// Multiple selection by Ctrl + Mouse
var actions = new Actions(session);
actions.KeyDown(null, Keys.Control); // keep target element to null
actions.Click(rowHeader5);
actions.KeyUp(Keys.Control);
actions.Perform();
}
var rowHeader9 = rowHeaderCollection.FindElementByName("RowHeader[9]"); // first row starts at index 0
if (rowHeader9 != null)
{
// Multiple selection by Ctrl + Mouse
var actions = new Actions(session);
actions.KeyDown(null, Keys.Control); // keep target element to null
actions.Click(rowHeader9);
actions.KeyUp(Keys.Control);
actions.Perform();
}
}
アウトライン
アウトラインの格納形式は以下の通りです。
Outlines represented in a tree structure
Worksheet
Outline Collection
Outline Group 1 - The most left side outline group (largest category)
Outline 1
Outline 2 - naming: RowOutline[StartRow,RowCount]
...
Outline Group 2
Outline Group 3
var outlineCollection = worksheet.FindElementByName("RowOutlineCollection");
if (outlineCollection != null)
{
var outlineGroup = outlineCollection.FindElementByName("RowOutlineGroup[1]");
if (outlineGroup != null)
{
outlineGroup.Click();
}
var outline = outlineCollection.FindElementByName("RowOutline[6,5]");
if (outline != null)
{
outline.Click();
}
}