【问题标题】:php script on windows server starts selenium and calls phpunitWindows 服务器上的 php 脚本启动 selenium 并调用 phpunit
【发布时间】:2017-09-08 05:47:44
【问题描述】:

我希望有人可以帮助解决这个问题,这让我发疯。我在 Windows Server 2008 R2 上安装了以下内容: - 硒服务器 - PHP - phpunit

我可以启动 selenium 服务器并手动执行 phpunit 脚本,一切正常。他们工作得很好。但我正在尝试自动化整个过程并在 php 脚本中完成所有这些。所以,我制作了:

<?php
    /* 
        Start the Selenium server with the chrome browser driver in a separate cmd window
        /k =  execute the cmd and then return to initial CMD prompt
    */
echo "\nStart the Selenium Server and pass the Chrome browser as an argument";
    $startSeleniumWithChrome = 'start cmd /k java -Dwebdriver.chrome.driver="C:\Users\*\Automation\requiredFiles\chromedriver.exe" -jar "C:\Users\*\Automation\requiredFiles\selenium-server-standalone-3.0.1.jar"';
echo "\nBefore startSeleniumWithChrome";
    exec($startSeleniumWithChrome);
echo "\nAfter startSeleniumWithChrome";

echo "\nBefore START phpunit";
    $executePhpunitCmd = 'start cmd /k phpunit -c phpunit.xml'; 
    exec($executePhpunitCmd);
echo "\nAfter START phpunit";
?>

我的问题: exec($startSeleniumWithChrome);上面似乎挂了。脚本不会超过这一点。有谁知道我如何看到导致脚本挂起的原因? 谢谢 康纳

【问题讨论】:

    标签: php selenium selenium-webdriver phpunit


    【解决方案1】:

    问题是exec() 会等待进程结束,然后返回输出。由于 selenium 将运行无头浏览器会话,因此它不会结束,而是在后台运行。这也记录在“注释”部分:

    如果使用此函数启动程序,为了使其继续在后台运行,程序的输出必须重定向到文件或另一个输出流。否则会导致 PHP 挂起,直到程序执行结束。

    在 Linux 上,您可以将输出通过管道传输到 /dev/null。这将为您提供即时反馈,但该进程将继续在后台运行(忽略输出):

    exec($startSeleniumWithChrome . ' /dev/null 2>&1 &');
    

    我不确定这是否适用于 Windows,如果没有,您可以试试这个:

    exec($startSeleniumWithChrome . ' &');
    

    如果您想从正在运行的进程中获取一些输出,您也可以尝试使用 popen()/pclose()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-03
      • 2023-04-02
      • 1970-01-01
      • 2012-11-22
      • 2015-07-04
      • 2019-01-15
      相关资源
      最近更新 更多