2010年7月2日金曜日

Seleniumについて

Seleniumについて調べてみる。
まずはSeleniumとは何か?Introducing Seleniumから抜粋しつつオレオレ翻訳をしてみる。

Introducing Selenium

Seleniumの紹介

Selenium is a robust set of tools that supports rapid development of test automation for web-based applications. Selenium provides a rich set of testing functions specifically geared to the needs of testing of a web application. These operations are highly flexible, allowing many options for locating UI elements and comparing expected test results against actual application behavior.

SeleniumはWEBアプリの自動化テストを高速につくるための堅牢なツールのセットです。WEBアプリテストに特化したリッチなテスト機能を提供します。非常に柔軟なテストが可能で、UI要素の位置を特定したり、期待する動きと実際のアプリケーションの動きを比較するいろいろな方法を提供します。

One of Selenium’s key features is the support for executing one’s tests on multiple browser platforms.

Seleniumの特筆すべき機能は同一のテストを複数のブラウザプラットフォームで実行できる点でしょう。

Seleniumは主にSelenium-IDE, Selenium-RC, Selenium-Gridから構成され、それぞれ用途が異なるらしい。そのうち、Selenium-RCはJUnitと同様にプログラムでテストを実行できるため、ある程度複雑なテストやビルド時に実行したり、毎晩自動実行させたりといった方法で業務に使えそうだ。

Selenium-RC (Remote Control)

Selenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logic. For instance, if the application under test returns a result set, and if the automated test program needs to run tests on each element in the result set, the programming language’s iteration support can be used to iterate through the result set, calling Selenium commands to run tests on each item.

Selenium-RCは最大限に柔軟で拡張性の高いテストロジックを構築できるよう、プログラミング言語を使ったテスト自動化が可能です。例として、テスト対象のアプリケーションが計算結果の一覧を返し、自動化テストが一覧の各要素をテストしなければいけない場合でも、プログラミング言語のループ構文を使って一覧の各要素に対してSeleniumコマンドを呼び出すことで、一覧全てをテストすることができます。

Selenium-RC provides an API (Application Programming Interface) and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby. This ability to use Selenium-RC with a high-level programming language to develop test cases also allows the automated testing to be integrated with a project’s automated build environment.

Selenium-RCはサポート対象の言語(HTML, Java, C#, Perl, PHP, Python, Ruby)に対してAPIとライブラリーを提供します。プログラミング言語からSelenium-RCを使えるため、ビルド環境に自動化テストを統合することも可能です。

2010年6月22日火曜日

uniq

業務で頻繁にExcelを使うが、未だに慣れない。でもExcelの内容をコピー&ペーストするとTSVになるのでExcel→Emacsとコピペして加工、Emacs→Excelとコピペし直すと大変便利。

つい最近は、重複が含まれるURLの一覧から重複を除去するためにUNIXのuniqコマンド相当の自作elispを使った。
まずはURL一覧をEmacsにコピーし、M-% /index.html /する。次に以下の内容をロードした状態でM-x sort-linesM-x uniqで重複がなくなる。

(require 'cl)

(defmacro* narrow-if-needed (&body body)
  "transient-mark-modeだった場合はbodyのオペレーションがリージョン内に制限される"
  `(lexical-let ((needed (and transient-mark-mode mark-active))
   result)
     (if needed (narrow-to-region (region-beginning) (region-end)))
     (setq result (progn ,@body))
     (if needed (widen))
     result))

(defun* uniq ()
  "uniqコマンドに相当する。transient-mark-modeだった場合はリージョンに対してのみ作用する"
  (interactive)
  (narrow-if-needed
   (beginning-of-buffer)
   (while (re-search-forward "\\(.*\n\\)\\1+" nil t)
     (replace-match "\\1" nil nil))))