Fluentlenium導入した話
どうも、きくかわさんです。
ギョームでE2Eのテストを勝手に入れたかったので、唯一使用した事のあるFluentleniumを久々に使おうと思ったのだけど導入に5時間くらいかかった。。。
ちょっともうハマりたくない&他の人にはまって欲しくないのでメモ書き程度に収めてみる。
※注意 : 2017/8/28 時点での記事です。今後導入に取り込む場合はブラウザやドライバーのVersionに十分お気をつけください。
Fluentleniumの公式ドキュメント通りでは動きませんでしたので、公式とは差異があります。
fluentlenium.org
まず、GeckoDriverの最新を取得しておいてください。
Mac用とか、Windows用とかあるので注意。(書いてるけど)
2017/8/28日時点では、v0.18.0を使用しました。
github.com
今回使用したブラウザとVersion
・Firefox version: 55.0.3
build.gradle
group 'kiku' version '1.0-SNAPSHOT' apply plugin: 'java' apply plugin: 'idea' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { testCompile 'junit:junit:4.12' // 以下2017/8/28 時点の最新を使用してます testCompile 'org.fluentlenium:fluentlenium-junit:3.3.0' testCompile 'org.fluentlenium:fluentlenium-assertj:3.3.0' testCompile 'org.seleniumhq.selenium:htmlunit-driver:2.27' testCompile 'xml-apis:xml-apis:2.0.2' testCompile 'org.seleniumhq.selenium:selenium-firefox-driver:3.5.2' }
MyFluentTest.java
mport org.fluentlenium.adapter.junit.FluentTest; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; public class MyFluentTest extends FluentTest { @Override public String getWebDriver() { // システムのプロパティに、先ほど取得したgeckodriverを設定 System.setProperty("webdriver.gecko.driver", "src/test/resources/exe/geckodriver"); return "firefox"; } @Test public void GoogleでFluentLeniumを検索した時のタイトルがFluentLeniumになること() { goTo("https://google.com"); $("#lst-ib").fill().with("FluentLenium"); $("input[name=btnK]").click(); assertThat(window().title()).contains("FluentLenium"); } }
一応ソース
github.com
あとがき
Versionが記載のものと全く同じであれば、これで動くかと思います。
ChromeやIEを使用する場合にも、FirefoxDriverのようにWebDriverがあるはず(IEについて未確認)なので、
それを指定すれば何とかなるかもしれない。
何かとエラーが出た時に、最新にあげると治るよーって書いてたのでそれに従えば何とかなった気はする。
ただエラーログと格闘することになるので、英語に強くなりましょう。(ググってもほぼ英語)
しかし、Fluentlenium1.x系を使用する際にFirefoxの設定はデフォルトなのでいらなかったはずなのに、
なぜかいるようになってるのが、どこからかのFluentleniumのVersionが上がった時に変わったのかな?
今回、GeckoDriverっていうのも初めて知った。
でも多分、FluentleniumはSeleniumのラッパーライブラリなので、SeleniumのVersionが上がった時か。(そこらへん詳しい人教えてください)
※追記(2017/8/30)
Seleniumが3になったとき。
— irof () { ... } (@irof) 2017年8月30日
詳しい人が教えてくれました。@irofさんありがとうございます。
GitIssueとStackOverFlowにはすごく助けられた。
あと、ある人にも。