我正在使用Selenium php端口,我正在尝试将测试结果记录到数据库中以进行进一步挖掘。
问题是,当我尝试记录例如登录按钮时:
<?php
namespace FacebookWebDriver;
include("C:/MAMP/htdocs/vendor/autoload.php");
use FacebookWebDriverRemoteDesiredCapabilities;
use FacebookWebDriverRemoteRemoteWebDriver;
$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 'FacebookWebDriverPDO' not found
in C:UsersakalDesktopQAhello.php:28
Stack trace:
#0 C:UsersakalDesktopQAhello.php(22): F
FacebookWebDrivercorrect_function()
#1 {main}
thrown in C:UsersakalDesktopQAhello.php
Fatal error: Uncaught Error: Class 'FacebookWebDriverPDO' not found in
C:UsersakalDesktopQAhello.php:28
Stack trace:
#0 C:UsersakalDesktopQAhello.php(22):
FacebookWebDrivercorrect_function()
#1 {main}
thrown in C:UsersakalDesktopQAhello.php on line 28
on line 28
据我了解,当我使用目录C:/mamp/htdocs
时,作曲家似乎正在查看C:/users/akal/desktop/qa/hello
.这是问题所在吗?
脚本尝试在FacebookWebDriver
命名空间中查找PDO
类。你需要告诉 php,这是一个全局可用的类,方法是在每个PDO
用法前面添加一个斜杠。
$conn = new PDO("mysql:host=localhost;dbname=cms", "user_test", "test123");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);