php - 硒和 php
问题描述
我一直在尝试测试此代码,取自此页面:https ://help.crossbrowsertesting.com/selenium-testing/getting-started/php/ 我想要做的就是创建一个浏览器堆栈帐户并使用一些简单的测试硒。
#Insert opening PHP tag
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedConditions;
use PHPUnit\Framework\TestCase;
class ToDoTest extends TestCase {
protected $driver;
static private $username = "YOUR_USERNAME";
static private $authkey = "YOUR_AUTHKEY";
static private $sessionId = NULL;
public function setScore($score) {
print "Setting the score to ". $score. "\n";
$url = "https://crossbrowsertesting.com/api/v3/selenium/" . self::$sessionId;
$options = array('action'=>'set_score', 'score'=>$score);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, self::$username . ":" . self::$authkey);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($options));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$info = curl_exec($ch);
curl_close ($ch);
}
public function takeSnapshot(){
$url = "https://crossbrowsertesting.com/api/v3/selenium/" . self::$sessionId . "/snapshots";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, self::$username . ":" . self::$authkey);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$info = curl_exec($ch);
curl_close($ch);
}
public function setUp() {
$capabilities = array("name"=> "Selenium Test Example PHP",
"build"=> "1.0",
"browser_api_name"=> "Chrome76",
"os_api_name"=> "Win10",
"record_video"=> "true",
"record_network"=> "false",);
$host = "http://" . self::$username . ":" . self::$authkey . "@hub.crossbrowsertesting.com:80/wd/hub";
$this->driver = RemoteWebDriver::create($host, $capabilities );
}
public function testToDos() {
try {
self::$sessionId = $this->driver->getSessionId();
print "this is the session id: " . self::$sessionId;
print "\nNavigating to URL\n";
$this->driver->get("http://crossbrowsertesting.github.io/todo-app.html");
$this->takeSnapshot();
sleep(3);
$this->assertEquals("Todo App - CrossBrowserTesting.com",$this->driver->getTitle());
// if we've made it this far, assertions have passed and we'll set the score to pass.
$this->setScore('pass');
} catch (Exception $ex) {
// if we caught an exception along the way, an assertion failed and we'll set the score to fail.
$this->setScore('fail');
print "Caught Exception: " . $ex->getMessage();
}
}
public function tearDown() {
$this->driver->quit();
}
}
?>
它显示的是这个错误:
Argument 1 passed to Facebook\WebDriver\Remote\DesiredCapabilities::__construct() must be of the type array, null given, called in
我一直在尝试解决它,但没有找到我应该怎么做的方法。有什么建议吗?谢谢
解决方案
推荐阅读
- ios - 使用文件管理器新目录不起作用
- colors - Y 到 CbCr 的转换
- angular - How to achieve required in select box in Angular 5?
- php - 在WordPress的用户元数组中按键删除值
- excel - 无法合并不同的日志文件
- android - 我正在单击按钮更改视图的宽度和高度,但我想在第二次单击时切换到默认视图
- android - How to make pagination work for firestore in realtime on Android?
- android - 触摸的窗口尚未完成某些输入事件的处理(我经常崩溃。我完全不知道)
- node.js - 如何在 Vue.js 2 中发送 JSON 数据作为响应?
- java - SpringBoot thymeleaf 给出 TemplateInputException,当模板不存在时