I have been trying to test this code, taken from this page:https://help.crossbrowsertesting.com/selenium-testing/getting-started/php/ All I want to do is create a browserstack account and make some simple tests using selenium.
#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();
}
}
?>
What it shows is this error:
Argument 1 passed to Facebook\WebDriver\Remote\DesiredCapabilities::__construct() must be of the type array, null given, called in
I have been trying to solve it , but am not finding a way what should I do. ANy suggestion guys? Thank you
Aucun commentaire:
Enregistrer un commentaire