2017-04-12 51 views
0

我希望有人可以幫助解決這個問題,這讓我瘋狂。我已經安裝了下面的Windows Server 2008 R2: - 硒服務器 - PHP - PHPUnit的在windows服務器上的php腳本啓動硒並呼叫phpunit

我可以啓動硒服務器,並手動執行PHPUnit的腳本,一切都OK。他們工作很好。但我試圖自動化整個過程,並在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);上面似乎掛起。該腳本不會超越這一點。有沒有人有任何想法如何我可以看到是什麼導致腳本掛起? 謝謝 Conor

回答

0

問題是,exec()將等待進程結束,然後返回輸出。由於硒將運行一個無頭瀏覽器會話,它不會結束,但在後臺運行。這也記錄在註釋部分:

如果一個程序是用這個函數啓動的,爲了讓它在後臺繼續運行,程序的輸出必須被重定向到一個文件或另一個輸出流。否則會導致PHP掛起,直到程序執行結束。

在Linux上,您可以將輸出傳輸到/dev/null。這會給你即時反饋,但這一過程將繼續在後臺運行(與輸出被忽略):

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

我不知道這是否適用於Windows,如果不是你可能只是試試這個:

exec($startSeleniumWithChrome . ' &'); 

或者你可以嘗試使用POPEN()/ pclose函數(),如果你想從運行過程中的一些輸出。