使用php-webdriver-bindings-0.9.0在selenium中执行javascript

使用php-webdriver-bindings-0.9.0在selenium中执行javascript,php,selenium,Php,Selenium,我试图在我的selenium测试套件中执行JavaScript,但它不起作用,而且我没有收到错误反馈。它优雅地接受我作为参数输入到execute函数并通过测试。以下是我尝试过的组合: class TestingStuff extends PHPUnit_Framework_TestCase { protected function setUp() { $this->webdriver = new WebDriver("localhost", 4444); $this-&g

我试图在我的selenium测试套件中执行JavaScript,但它不起作用,而且我没有收到错误反馈。它优雅地接受我作为参数输入到execute函数并通过测试。以下是我尝试过的组合:

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”类中的函数:

看看

这就是你想要达到的目标吗

我正在使用,并且有一个类似的问题:

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() 
   }
}

(来源)

你期望发生什么?发生了什么事?什么事情没有发生?我希望在测试到达我在浏览器中调用$this->webdriver->execute()的点时得到一个警报。@ManiMuridi在运行
execute
execute\u async
时运气好吗?令人不安的是,它们的使用缺乏文档!
public function testExecute() {
    $this->webdriver->get(TEST_URL);
    $result = $this->webdriver->executeScript("return sayHello('unitTest')", array());
    $this->assertEquals("hello unitTest !!!", $result);
}
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() 
   }
}