3

Selenium テスト スイートで JavaScript を実行しようとしていますが、動作せず、エラー フィードバックもありません。実行関数へのパラメーターとして入力したものをすべて適切に受け入れ、テストに合格します。以下は私が試した組み合わせです:

class TestingStuff extends PHPUnit_Framework_TestCase {

protected function setUp() {
    $this->webdriver = new WebDriver("localhost", 4444);
    $this->webdriver->connect("firefox");
}

protected function tearDown() {
    $this->webdriver->close();
}

public function testSomething() {
    $this->webdriver->get('http://localhost/testdir/');
    // Here is the execute function
    $this->webdriver->execute('alert', 'Hello');

$this->webdriver->get('http://127.0.0.1/testdir/');
// Here is the execute function
$this->webdriver->execute('alert("Hello")', '');

$this->webdriver->get('http://127.0.0.1/testdir/');
// Here is the execute function
$this->webdriver->execute('javascript:alert("Hello")', '');

$this->webdriver->get('http://localhost/testdir/');
// Here is the execute function
$this->webdriver->execute('alert()', 'Hello');
}

}

これは、「WebDriver」クラスの関数です。

/**
Inject a snippet of JavaScript into the page for execution in the context of the currently   selected frame.
* The executed script is assumed to be synchronous and the result of evaluating the script
* is returned to the client.
* @return Object result of evaluating the script is returned to the client.
*/
public function execute($script, $script_args) {
    $request = $this->requestURL . "/execute";
    $session = $this->curlInit($request);
    $args = array('script' => $script, 'args' => $script_args);
    $jsonData = json_encode($args);
    $this->preparePOST($session, $jsonData);
    $response = curl_exec($session);
    return $this->extractValueFromJsonResponse($response);
}
4

1 に答える 1