現在、確認ダイアログ ボックスをうまくサポートしていない Selenium 2 を使用してプロジェクトを実装しています。
この制限には回避策があります。window.confirm を上書きして、特定のテスト ケースに対して返す必要がある値を返すだけです。
次の文字列を設定して実行できます。
public static final String CONFIRM_DIALOG_BOX =
"window.confirm = function(msg) { return true; }";
public static final String CANCEL_DIALOG_BOX =
"window.confirm = function(msg) { return false; }";
これはテンプレート メソッドとしては非常に簡単に思えますが、同じページ オブジェクトに複数のテスト ケースがあり、ページを操作した後に確認/拒否する必要があります。したがって、これらすべてのテストを一度に実行する単一のメソッドを持つことはできません。
テスト メソッドに実行するコマンドを挿入することは理にかなっている可能性がありますが、ここでの私の最終的な目標は、技術力の低いスタッフが XML にいくつかの文字列を書き込んでから Spring Expression Language で実行することでテストを作成できるようにすることです。これにより、テストを書く際の「容易さ」がいくらか失われます。
主な注意点は、このテスト スイートは実際には要件によるアプリケーションであり、個別に実行される一連のテスト ケースではないということです。小さなテスト ケースであれば、抽象的なテスト ケースを拡張して同じセットアップ ルーチンと分解ルーチンを利用できるので、はるかに簡単です。
私が最終的に探しているのは、このテンプレート メソッドに沿ったものですが、1 つのページ オブジェクトで複数のテスト ケースをサポートできる必要があります。
public final void executeTest(boolean confirmDialogBoxResponse) {
// store normal functionality and allow us to return
// window.confirm to normal state upon completion of test.
prepare(confirmDialogBoxResponse);
testMethod(); // What about params to these methods?
/* Adding an interface to the method would be nice, but
* would make things a bit more cumbersome for our
* less technical staff, which would allow me to replace
* the above with this:
*
* executeTest(TestCommand command, confirmDialogResponse);
* command.execute(); // Still have params issue
*/
// restore window.confirm to normal state -- if we cancel we stay
// on same page, and need to restore things as they were, the majority
// of our confirm cases take you to new pages whereby window.confirm
// will be restored for us
if (!confirmDialogResponse) {
restore();
}
}