Geb Automation Skill
TestMu AIクラウド実行については、reference/cloud-integration.md および shared/testmu-cloud-reference.md を参照してください。
コアパターン
基本テスト(Spock)
import geb.spock.GebSpec
class LoginSpec extends GebSpec {
def "有効な認証情報でログイン"() {
when:
to LoginPage
emailInput.value("[email protected]")
passwordInput.value("password123")
loginButton.click()
then:
at DashboardPage
welcomeMessage.text().contains("Welcome")
}
def "無効な認証情報でログインエラー表示"() {
when:
to LoginPage
emailInput.value("[email protected]")
passwordInput.value("wrong")
loginButton.click()
then:
at LoginPage
errorMessage.displayed
errorMessage.text().contains("Invalid")
}
}
ページオブジェクト
class LoginPage extends geb.Page {
static url = "/login"
static at = { title == "Login" }
static content = {
emailInput { $("#email") }
passwordInput { $("#password") }
loginButton { $("button[type='submit']") }
errorMessage(required: false) { $(".error") }
}
}
class DashboardPage extends geb.Page {
static url = "/dashboard"
static at = { $(".dashboard").displayed }
static content = {
welcomeMessage { $(".welcome") }
userName { $(".user-name") }
}
}
ナビゲーターAPI
$("css-selector")
$("div", class: "active")
$("input", name: "email")
$("div.items li", 0) // 最初の一致
$("div.items li").size() // 件数
// アクション
element.click()
element.value("テキスト")
element << "テキスト" // テキスト追加
element.text()
element.displayed
element.@href // 属性
クラウド:driver = new RemoteWebDriver(new URL(gridUrl), caps)
セットアップ:geb-spock と selenium-support 依存関係を含むGradle
TestMu AIでのクラウド実行
環境変数を設定します:LT_USERNAME、LT_ACCESS_KEY
// GebConfig.groovy
environments {
lambdatest {
driver = {
def ltOptions = [
user: System.getenv("LT_USERNAME"),
accessKey: System.getenv("LT_ACCESS_KEY"),
build: "Geb Build",
name: "Geb Test",
platformName: "Windows 11",
video: true,
console: true,
network: true,
]
def caps = new ChromeOptions()
caps.setCapability("LT:Options", ltOptions)
new RemoteWebDriver(
new URL("https://hub.lambdatest.com/wd/hub"), caps)
}
}
}
実行:./gradlew test -Dgeb.env=lambdatest
実行:./gradlew test
高度なパターン
本番品質のパターンについては reference/playbook.md を参照してください:
| セクション | 内容 |
|---|---|
| §1 プロジェクトセットアップ | build.gradle、GebConfig.groovy、環境、待機設定 |
| §2 ページオブジェクト | Content DSL、atチェック、再利用可能コンポーネントのモジュール |
| §3 スペックテスト | Spock統合、@Unrollを使ったデータ駆動、@Stepwiseフロー |
| §4 待機と非同期 | 待機プリセット、JavaScript操作、アラート/確認ダイアログ |
| §5 高度なパターン | ファイルアップロード/ダウンロード、ウィンドウ、フレーム、カスタム拡張 |
| §6 APIテスト | Groovy JsonSlurperを使用したREST APIスペック |
| §7 CI/CD統合 | ヘッドレスChromeを使用したGitHub Actions、Gradleキャッシュ |
| §8 デバッグ表 | 12の一般的な問題とその原因および修正方法 |
| §9 ベストプラクティス | 14項目のGebテストチェックリスト |