GebでSelect要素の選択が遅い
追記(2014/04/17)
解決しました。
id:kyon_mmさんがコメントで指摘くださいました。
0.9.0で修正されているらしいのでバージョンを上げればよし。
具体的には「@Grab("org.codehaus.geb:geb-core:*")」を「@Grab("org.gebish:geb-core:0.9.2")」と変更すればOK。
詳しくは別記事にも書いたので興味のある方は↓
概要
SeleniumのGroovyのラッパーであるGebを使っていたのですが、Select要素を設定すると物凄く遅い。
っというか、使い物にならないくらい遅い!!
下記のコードを実行すると、Seleniumを直で使用した場合は500ミリ秒程度ですが、Gebの方は8000ミリ秒程度もかかります。
環境
OS | Windows7 Professional 32bit |
CPU | Core2 Duo 2.93GHz |
メモリ | 4GB |
Groovy Version | 2.2.2 |
Java Version | 1.8.0 |
firefox | 27.0.1 |
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <select id="year"> <option value='-'>-</option> <option value='1900'>1900</option> <option value='1901'>1901</option> <-- 中略 --> <option value='2013'>2013</option> <option value='2014'>2014</option> </select> <select id="month"> <option value='-'>-</option> <option value='01'>01</option> <option value='02'>02</option> <-- 中略 --> <option value='11'>11</option> <option value='12'>12</option> </select> <select id="day"> <option value='-'>-</option> <option value='01'>01</option> <option value='02'>02</option> <-- 中略 --> <option value='30'>30</option> <option value='31'>31</option> </select> </body> </html>
コード
@Grapes([ @Grab("org.seleniumhq.selenium:selenium-java:*"), @Grab("org.seleniumhq.selenium:selenium-support:*"), @Grab("org.seleniumhq.selenium:selenium-firefox-driver:*"), @Grab("org.codehaus.geb:geb-core:*"), ]) import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.By import org.openqa.selenium.support.ui.Select import geb.Browser import geb.Configuration println "start" def driver = new FirefoxDriver() driver.get("http://jsbin.com/sucumuqu/2/") def now = new Date() def year = new Select(driver.findElement(By.id("year"))) year.selectByVisibleText("1950") def month = new Select(driver.findElement(By.id("month"))) month.selectByVisibleText("08") def day = new Select(driver.findElement(By.id("day"))) day.selectByVisibleText("15") println "${new Date().time - now.time}" driver.quit(); Configuration conf = new Configuration() conf.baseUrl = "." conf.driver = new FirefoxDriver() Browser.drive(conf) { go "http://jsbin.com/sucumuqu/2/" now = new Date() $("#year").value("1950") $("#month").value("08") $("#day").value("15") println "${new Date().time - now.time}" quit() } println "end"
しょうがないので、driverを取得して直接操作するとほぼ同じ時間で処理が完了する。(当たり前)
@Grapes([ @Grab("org.seleniumhq.selenium:selenium-java:*"), @Grab("org.seleniumhq.selenium:selenium-support:*"), @Grab("org.seleniumhq.selenium:selenium-firefox-driver:*"), @Grab("org.codehaus.geb:geb-core:*"), ]) import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.By import org.openqa.selenium.support.ui.Select import geb.Browser import geb.Configuration println "start" def driver1 = new FirefoxDriver() driver1.get("http://jsbin.com/sucumuqu/2/") def now = new Date() def year = new Select(driver1.findElement(By.id("year"))) year.selectByVisibleText("1950") def month = new Select(driver1.findElement(By.id("month"))) month.selectByVisibleText("08") def day = new Select(driver1.findElement(By.id("day"))) day.selectByVisibleText("15") println "${new Date().time - now.time}" driver1.quit(); Configuration conf = new Configuration() conf.baseUrl = "." conf.driver = new FirefoxDriver() Browser.drive(conf) { go "http://jsbin.com/sucumuqu/2/" now = new Date() year = new Select(driver.findElement(By.id("year"))); year.selectByVisibleText("1950"); month = new Select(driver.findElement(By.id("month"))); month.selectByVisibleText("08"); day = new Select(driver.findElement(By.id("day"))); day.selectByVisibleText("15"); println "${new Date().time - now.time}" quit() } println "end"
セレクタが遅い?ただ、テキストボックスやラジオだとそこまで遅いとは感じないのでセレクトボックス特有の原因かな?
ソース読めっていう話なんだけど。。。