php-webdriver-bindings を使用して、PHP で Selenium を使用したテストをセットアップしています。プロジェクトホームの例で次の問題に遭遇した人はいますか?
サンプル テストを実行すると、サーバーは ExecutionException をスローします。Java から同じ手順を実行すると、問題なく機能します。(セッション機能の決定時に例外が発生するため、手順はおそらくそれほど重要ではありません)
PHP コード:
<?php
require_once "phpwebdriver/WebDriver.php";
/*require("phpwebdriver/LocatorStrategy.php");*/ /*already included*/
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
$element->sendKeys(array("selenium google code" ) );
$element->submit();
$webdriver->close();
?>
Java コード:
package asdfjkl.selenium.test;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Sel2Test2 {
public static void main(String[] args) {
URL url = null;
try {
url = new URL("http://localhost:4444/wd/hub");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
WebDriver driver = new RemoteWebDriver(
url, DesiredCapabilities.firefox());
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("selenium google code");
element.submit();
driver.quit();
}
}
PHP テストの実行時のサーバー出力 (例外がスローされます):
May 29, 2012 11:57:55 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
11:57:56.537 INFO - Java: Sun Microsystems Inc. 20.0-b11
11:57:56.539 INFO - OS: Linux 2.6.18-308.1.1.el5 i386
11:57:56.554 INFO - v2.21.0, with Core v2.21.0. Built from revision 16552
11:57:57.774 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
11:57:57.775 INFO - Version Jetty/5.1.x
11:57:57.776 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
11:57:57.777 INFO - Started HttpContext[/selenium-server,/selenium-server]
11:57:57.777 INFO - Started HttpContext[/,/]
11:58:01.141 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@90cb03
11:58:01.141 INFO - Started HttpContext[/wd,/wd]
11:58:01.145 INFO - Started SocketListener on 0.0.0.0:4444
11:58:01.145 INFO - Started org.openqa.jetty.jetty.Server@af8358
11:59:57.941 INFO - Executing: [new session: {javascriptEnabled=true, browserName=firefox, nativeEvents=false, version=}] at URL: /session)
12:00:11.527 INFO - Done: /session
12:00:11.531 INFO - Executing: org.openqa.selenium.remote.server.handler.GetSessionCapabilities@134263a at URL: /session/1338285476985)
12:00:11.531 INFO - Done: /session/1338285476985
12:00:11.532 INFO - WebDriver remote server: Fatal, unhandled exception: /session/1338285476985: java.util.concurrent.ExecutionException: java.lang.NullPointerException
12:00:11.532 WARN - EXCEPTION
javax.servlet.ServletException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:603)
at org.openqa.selenium.remote.server.DriverServlet.doGet(DriverServlet.java:539)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:520)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
at java.util.concurrent.FutureTask.get(FutureTask.java:83)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:158)
at org.openqa.selenium.remote.server.handler.WebDriverHandler.execute(WebDriverHandler.java:90)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:240)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:597)
... 16 more
Caused by: java.lang.NullPointerException
at org.openqa.selenium.remote.server.renderer.ForwardResult.render(ForwardResult.java:39)
at org.openqa.selenium.remote.server.rest.ResultConfig$1.call(ResultConfig.java:233)
at org.openqa.selenium.remote.server.rest.ResultConfig$1.call(ResultConfig.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:151)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
12:00:11.533 WARN - /wd/hub/session/1338285476985:
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
at java.util.concurrent.FutureTask.get(FutureTask.java:83)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:158)
at org.openqa.selenium.remote.server.handler.WebDriverHandler.execute(WebDriverHandler.java:90)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:240)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:597)
at org.openqa.selenium.remote.server.DriverServlet.doGet(DriverServlet.java:539)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:520)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: java.lang.NullPointerException
at org.openqa.selenium.remote.server.renderer.ForwardResult.render(ForwardResult.java:39)
at org.openqa.selenium.remote.server.rest.ResultConfig$1.call(ResultConfig.java:233)
at org.openqa.selenium.remote.server.rest.ResultConfig$1.call(ResultConfig.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:151)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
12:00:11.540 INFO - Executing: [get: http://google.com] at URL: /session/1338285476985/url)
12:00:12.664 INFO - Done: /session/1338285476985/url
12:00:12.666 INFO - Executing: [find element: By.name: q] at URL: /session/1338285476985/element)
12:00:12.956 INFO - Done: /session/1338285476985/element
12:00:12.961 INFO - Executing: [send keys: 0 org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement@13472277, [selenium google code]] at URL: /session/1338285476985/element/0/value)
12:00:13.096 INFO - Done: /session/1338285476985/element/0/value
12:00:13.097 INFO - Executing: [submit: 0 org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement@13472277] at URL: /session/1338285476985/element/0/submit)
12:00:13.227 INFO - Done: /session/1338285476985/element/0/submit
12:00:13.228 INFO - Executing: [delete session: 1338285476985] at URL: /session/1338285476985)
12:00:13.304 INFO - Done: /session/1338285476985
Java テストの実行時のサーバー出力 (例外はスローされません):
May 29, 2012 12:02:26 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
12:02:26.682 INFO - Java: Sun Microsystems Inc. 20.0-b11
12:02:26.684 INFO - OS: Linux 2.6.18-308.1.1.el5 i386
12:02:26.695 INFO - v2.21.0, with Core v2.21.0. Built from revision 16552
12:02:26.816 INFO - RemoteWebDriver instances should connect to: http://127.0.0. 1:4444/wd/hub
12:02:26.818 INFO - Version Jetty/5.1.x
12:02:26.818 INFO - Started HttpContext[/selenium-server/driver,/selenium-server /driver]
12:02:26.819 INFO - Started HttpContext[/selenium-server,/selenium-server]
12:02:26.819 INFO - Started HttpContext[/,/]
12:02:26.842 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@288051
12:02:26.842 INFO - Started HttpContext[/wd,/wd]
12:02:26.846 INFO - Started SocketListener on 0.0.0.0:4444
12:02:26.846 INFO - Started org.openqa.jetty.jetty.Server@af8358
12:04:02.749 INFO - Executing: [new session: {platform=ANY, browserName=firefox version=}] at URL: /session)
12:04:04.910 INFO - Done: /session
12:04:04.949 INFO - Executing: org.openqa.selenium.remote.server.handler.GetSes ionCapabilities@134263a at URL: /session/1338285746744)
12:04:04.950 INFO - Done: /session/1338285746744
12:04:04.991 INFO - Executing: [get: http://www.google.com] at URL: /session/13 8285746744/url)
12:04:05.624 INFO - Done: /session/1338285746744/url
12:04:05.658 INFO - Executing: [find element: By.name: q] at URL: /session/1338 85746744/element)
12:04:05.919 INFO - Done: /session/1338285746744/element
12:04:05.988 INFO - Executing: [send keys: 0 org.openqa.selenium.support.events EventFiringWebDriver$EventFiringWebElement@4175a8c3, [selenium google code]] at URL: /session/1338285746744/element/0/value)
12:04:06.095 INFO - Done: /session/1338285746744/element/0/value
12:04:06.124 INFO - Executing: [submit: 0 org.openqa.selenium.support.events.Ev ntFiringWebDriver$EventFiringWebElement@4175a8c3] at URL: /session/133828574674 /element/0/submit)
12:04:06.247 INFO - Done: /session/1338285746744/element/0/submit
12:04:06.274 INFO - Executing: [delete session: 1338285746744] at URL: /session 1338285746744)
12:04:06.346 INFO - Done: /session/1338285746744
誰もこれに出くわしましたか?Selenium が正式に PHP をサポートしていないことは知っています。しかし、そのようにサーバーに接続を失敗させるべきではないと思います。また、サンプル コードが php-webdriver-bindings のホームページに目立つように表示されているにもかかわらず、明らかに誰も気付いていないことも不思議です。私は何を間違っていますか?