2012-08-14 89 views
2

我們有一個應用程序,我們使用Selenium測試框架。該應用程序在Windows Server 2012上運行,並通過Windows任務計劃程序定期運行。我通過遠程桌面連接到服務器。Selenium按計劃在Windows服務器上運行

當我在計劃任務設置選項「運行用戶是否已登錄」中設置時,會出現問題。我的應用程序開始使用此JavaScript代碼正確運行,但隨即立即以錯誤異常結束 - 它在下面的行中標記。如果我正常啓動應用程序,一切正常。不幸的是,我需要創建一個即使沒有人登錄也能運行的應用程序。沒有人遇到過這個問題嗎?

這是我的代碼:

public Bitmap MakeBitmap(Uri url) 
{ 
    driver = MakeFirefoxDriver(); 
    driver.Navigate().GoToUrl(url.AbsoluteUri); 

    // In this command, an exception occurs. 
    driver.ExecuteScript("document.body.style.overflow = 'hidden'") 

    Thread.Sleep(TimeSpan.FromSeconds(SleepTime)); 
    var screenshot = driver.GetScreenshot(); 
    return new Bitmap(Image.FromStream(new MemoryStream(screenshot.AsByteArray))); 
} 

private FirefoxDriver MakeFirefoxDriver() 
{ 
    var profile = new FirefoxProfile { EnableNativeEvents = true }; 
    var capabilityValue = new List<string> { "-width", "500", "-height", "340" }; 
    var capabilities = DesiredCapabilities.Firefox(); 
    capabilities.SetCapability("initial", capabilityValue); 
    capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile); 
    return new FirefoxDriver(capabilities); 
} 

異常看起來是這樣的:

Exception log: No response from server for url http://localhost:7062/hub/session/...... 
StackTrace: at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest 
request) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String 
driverCommandToExecute, Dictionary`2 parameters) at ... 

回答

1

我在Windows 7上使用任務計劃,希望它是相同的。在日程安排程序中的常規選項卡上,單擊「運行用戶是否已登錄」。使用此設置,每次保存屬性時都需要輸入密碼。 當它運行時什麼都不會出現在屏幕上。我已經閱讀過這些論壇,在這種模式下運行,如果你試圖抓取一張圖片,它將是空白的。

相關問題