9. Groovy の文法を 1 時間でマスターする
• 世界最小の一文から
セミコロンはいらない (あっても動作す
る)
かっこ()もいらない (あっても動作す
る)
‘’ さすがに はないと 下記の Exception を吐く
。
println 'Hello'
Exception thrown
groovy.lang.MissingPropertyException: No such property:
Hello for class: Helllo
at Helllo.run(Helllo.groovy:1)
10. Groovy の文法を 1 時間でマスターする
• 世界最小の一文から
Java Class
Groovy Script
println 'Hello'
public class Main {
public static void main(String[] args) {
System.out0.println("Hello");
}
}
11. Groovy の文法を 1 時間でマスターする
• 型宣言
型宣言はいらない ( 動的型つけ言語)
Java の型はそのまま使える。型を宣言してもよ
い
s = 'Hello'
println s
String s = 'Hello'
println s
def s = 'Hello'
println s
38. PageObject パターンとは
Seleniumの公式サイトに記載してあるPageObjectパターンの原則を紹介
・The public methods represent the services that the page offers
(publicメソッドは、ページが提供するサービスを表す)
・Try not to expose the the internals of the page
(ページの内部を公開しないこと)
・Generally don’t make assertions
(原則としてassertionを行わないこと)
・Methods return other PageObjects
(メソッドは他のPageObjectsを返す)
・Need not represent an entire page
(ページ全体を表す必要はない)
・Different results for the same action are modelled as different as different methods
(同じアクションに対して異なる結果となる場合には異なるメソッドとしてモデル化する)
45. Geb でも PageObject パターン
先ほどとは違うGebページオブジェクトパターンの例
GoogleHomePage ( Google の検索ページ用 PageObject )
class GoogleResultsPage extends Page {
static at = { waitFor { title.endsWith("Google Search") } }
static content = {
//"wait"オプションによって、Googleの検索結果ページに
//$("li.g")が表示されるまで一定時間待つことができる。
//もし、表示されなかった場合は"RequiredPageContentNotPresent" 例外が
//発生する
results(wait: true) { $("li.g") }
result { index -> results[index] }
resultLink { index -> result(index).find("a") }
}
}
46. Geb を使った Web システムのテスト
つべこべ言わずにいきなり体験してみましょう。
1. https://github.com/geb/geb-example-gradle
2. 上記を clone して gradlew コマンドを実行
./gradlew.bat chromeTest
./gradlew.bat firefoxTest
./gradlew.bat phantomJsTest
To run with all, you can run:
./gradlew.bat test
47. Spock をもちいた記述の仕方
class LoginSpec extends GebSpec {
def "ID とパスワードを組み合わせてログインす
る "() {
setup:
to "http://www.example.com/login"
when :
$("#loginId").value("user01")
$("#password").value("pass01")
$("#login").click()
then :
at "http://www.example.com/home/"
cleanup:
}
}
ブロックを使ってテストケースを記述する