我正在使用 selenium php 端口,并且正在尝试将测试结果记录到数据库中以进行进一步挖掘。
问题是,当我尝试记录例如登录按钮时:
<?php
namespace Facebook\WebDriver;
include("C:/MAMP/htdocs/vendor/autoload.php");
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
$host = 'http://127.0.0.1:9515/';
$driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome(), 50000);
#Novibet.gr login test
$driver->get('http://www.example.com/');
$Login_element = $driver->findElement(WebDriverBy::className('login'))->click();
$driver->findElement(WebDriverBy::name('Username'))->click();
$username_element= $driver->getKeyboard()->sendKeys('username');
$driver->findElement(WebDriverBy::name('Password'))->click();
$username_element= $driver->getKeyboard()->sendKeys('password');
if ($element = $driver->findElement(WebDriverBy::cssSelector('#user .login #login input[type=submit]'))->click()){
correct_function();}
function correct_function(){
$timestamp = date("Y-m-d H:i:s");
$conn = new PDO("mysql:host=localhost;dbname=cms", "user_test", "test123"); //LINE 28
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO tests (id, Test_name, Test_description, Severity, Status , Timestamp_of_test)
VALUES ('Login_test', 'Click to login button', 'critical','$timestamp')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
我收到以下错误:
PHP Fatal error: Uncaught Error: Class 'Facebook\WebDriver\PDO' not found
in C:\Users\akal\Desktop\QA\hello.php:28
Stack trace:
#0 C:\Users\akal\Desktop\QA\hello.php(22): F
Facebook\WebDriver\correct_function()
#1 {main}
thrown in C:\Users\akal\Desktop\QA\hello.php
Fatal error: Uncaught Error: Class 'Facebook\WebDriver\PDO' not found in
C:\Users\akal\Desktop\QA\hello.php:28
Stack trace:
#0 C:\Users\akal\Desktop\QA\hello.php(22):
Facebook\WebDriver\correct_function()
#1 {main}
thrown in C:\Users\akal\Desktop\QA\hello.php on line 28
on line 28
据我了解,当我使用目录C:/mamp/htdocs
时,似乎作曲家正在查看C:/users/akal/desktop/qa/hello
. 这是问题吗?