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 ...