3
我試圖在我的硒測試套件中執行JavaScript,但它不工作,我沒有收到錯誤反饋。它優雅地接受我輸入的任何參數作爲執行功能並通過測試。以下是結合我曾嘗試:使用php-webdriver-bindings-0.9.0在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);
}
什麼是你期待發生什麼?會發生什麼?什麼不發生? – Arran
我希望在測試達到在瀏覽器中調用$ this-> webdriver-> execute()的點時獲得警報。 –
@ManiMuridi讓'execute'或'execute_async'工作有什麼好運?有一個令人不安的缺乏使用文件! – tester