0

GEBテストの初心者である私は、Intellijで簡単なログインプログラムを実行しようとしています。Intellijでこのテストを実行するのを手伝ってもらえますか?私の質問は、構成の編集ページでどのような選択を行う必要があるかということです。助けてください。この例は、gebの本からのものです。

import geb.Browser

Browser.drive {
  go "http://google.com/ncr"

  // make sure we actually got to the page
  assert title == "Google"

  // enter wikipedia into the search field
  $("input", name: "q").value("wikipedia")

  // wait for the change to results page to happen
  // (google updates the page dynamically without a new request)
  waitFor { title.endsWith("Google Search") }

  // is the first link to wikipedia?
  def firstLink = $("li.g", 0).find("a.l")
  assert firstLink.text() == "Wikipedia"

  // click the link 
  firstLink.click()

  // wait for Google's javascript to redirect to Wikipedia
  waitFor { title == "Wikipedia" }
}
4

2 に答える 2

2

これをIntelliJで実行している場合は、これをJUnitテスト(ctrl + F10)として実行できるはずです。これがクラス内およびメソッド内にあることを確認してください。

構文を簡単にするために、BDDフレームワークとしてSpockを使用することをお勧めします(プロジェクトにライブラリを含めます。Mavenを使用する場合は、サイトのガイドに従いますが、Spock0.7-groovy-2.0およびGeb0.9.0-RCに更新します。 -最新のライブラリの場合は-1

ストレートJUnitからSpockに切り替えたい場合(JUnitをサイレントライブラリとして使用する必要があることに注意してください)、テストケースは次のようになります。

  def "show off the awesomeness of google"() {
    given:
    go "http://google.com/ncr"

    expect: "make sure we actually got to the page"
    title == "Google"

    when: "enter wikipedia into the search field"
    $("input", name: "q").value("wikipedia")

    then: "wait for the change to results page to happen and (google updates the page dynamically without a new request)"
    waitFor { title.endsWith("Google Search") }
    // is the first link to wikipedia?
    def firstLink = $("li.g", 0).find("a.l")

    and:
    firstLink.text() == "Wikipedia"

    when: "click the link"
    firstLink.click()

    then: "wait for Google's javascript to redirect to Wikipedia"
    waitFor { title == "Wikipedia" }
}

Ctrl + F10(IntelliJでのテストに最適なキーショートカット!)

于 2013-01-11T06:51:50.977 に答える
0

上記は近いですが、いわば葉巻はありません。

Intellij内からバルク標準Gebishテストを実行したい場合は、2つのことを試しました。

  1. Spock/Gebテストのテスト/リソースにgeckodriver.exeを追加しました
  2. 私は文字通り与えられたもので:私のSpok /Gebテストの一部は次のことをしました:

        given:  
    System.setProperty("webdriver.gecko.driver", "C:\\repo\\geb-example-gradle\\src\\test\\resources" + "\\geckodriver.exe");
    
    1. 失敗した
    2. 成功

さて、答えの通常の扱いは、誰かが何かを書き、あなたがそれを試して、それから失敗するということです。したがって、うまくいかなかった場合は、Githubで参照Geb / Spockプロジェクトを次のように使用し、intellijにインポートします(新しいプロジェクトを覚えておいて、gradle.buildスクリプトを見つけると、intellijがうまくインポートします)...また、ビルドを開始するので、びっくりしないでください。

  1. https://github.com/geb/geb-example-gradle
  2. ドライバーをダウンロードします: https ://github.com/mozilla/geckodriver/releases そしてそれをtest/groovyの下にインポートしたリファレンスプロジェクトのtest/resourceフォルダーに移動します...(画像を参照)

次に、上記のgived 句をGebishOrgSpec Sock/Gebテストに 追加します。Spock/Gebテストでgeckodriver.exeを構成します

テストはIntellij内からうまく実行されます。ブラウザが開いていて、テストが実行されていることを証明します。

ここに画像の説明を入力してください

LOVELY JOBBLY:=)

于 2018-04-28T16:12:47.070 に答える