使用php-webdriver-bindings-0.9.0在selenium中执行javascript
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用php-webdriver-bindings-0.9.0在selenium中执行javascript,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2423字,纯文字阅读大概需要4分钟。
内容图文
![使用php-webdriver-bindings-0.9.0在selenium中执行javascript](/upload/InfoBanner/zyjiaocheng/744/008b14d7fa4f4b238963dafaec46b3ee.jpg)
我正在尝试在我的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);
}
解决方法:
看一下
https://github.com/scopium/Work/blob/master/php-webdriver-bindings-0.9.0/test/PHPWebdriverTest.php
public function testExecute() {
$this->webdriver->get(TEST_URL);
$result = $this->webdriver->executeScript("return sayHello('unitTest')", array());
$this->assertEquals("hello unitTest !!!", $result);
}
这是你想要实现的目标吗?
我正在使用phpunit-selenium并遇到类似的问题:
class MyTestClass extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://yourdomain.tld');
}
public function testScript()
{
$this->url('./');
$this->execute(array('script' => "alert('Hello');", 'args' => array()));
sleep(3); // Just to see the alert()
}
}
(来自https://github.com/sebastianbergmann/phpunit-selenium/issues/160)
内容总结
以上是互联网集市为您收集整理的使用php-webdriver-bindings-0.9.0在selenium中执行javascript全部内容,希望文章能够帮你解决使用php-webdriver-bindings-0.9.0在selenium中执行javascript所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。