doue9730 2018-05-07 12:12 采纳率: 100%
浏览 78
已采纳

php驱动程序报告事件(PDO问题)

I'm using selenium php port and I'mm trying to log the results of the tests into a database for further mining.

Problem is, when I try to record for example the login button:

<?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";
}

I'm getting the below error:

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

To my understanding, while I'm using directory C:/mamp/htdocs it seems that composer is looking at C:/users/akal/desktop/qa/hello. Is this the issue?

  • 写回答

1条回答 默认 最新

  • dqcwl02022 2018-05-07 12:24
    关注

    Your script tries to find the PDO class in the Facebook\WebDriver namespace. You need to tell php, that this is a global available class, by adding a slash \ in front of every PDO usage.

    $conn = new \PDO("mysql:host=localhost;dbname=cms", "user_test", "test123");
    $conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料