硒作为运行在Windows服务器上的计划任务 [英] Selenium runs as scheduled task on Windows Server

查看:127
本文介绍了硒作为运行在Windows服务器上的计划任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须在这里我们使用Selenium测试框架的应用程序。该应用程序运行Windows Server 2012,并定期通过Windows任务计划程序运行。我连接到通过远程桌面服务器。



当我在计划任务设置选项设置运行用户是否登录或不时出现问题。我的应用程序将开始通过这段JavaScript代码运行正常,但随后与错误异常立即结束 - 它标记在下面的横线。如果我正常启动应用程序,一切工作正常。不幸的是,我需要做的时候没有人登录其甚至可以运行的应用程序。 ?Hasn't已经遇到了这个问题的人。



这是我的代码:

 公共位图MakeBitmap(URI URL)
{
驱动= MakeFirefoxDriver();
driver.Navigate()GoToUrl(url.AbsoluteUri)。

//在此命令中,发生异常。
driver.ExecuteScript(document.body.style.overflow ='隐藏')

的Thread.Sleep(TimeSpan.FromSeconds(休眠时间));
VAR截图= driver.GetScreenshot();
返回新位图(Image.FromStream(新的MemoryStream(screenshot.AsByteArray)));
}

私人FirefoxDriver MakeFirefoxDriver()
{
无功配置=新FirefoxProfile {EnableNativeEvents =真};
变种capabilityValue =新的List<串GT; {-width,500,-height,340};
变种能力= DesiredCapabilities.Firefox();
capabilities.SetCapability(初始,capabilityValue);
capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName,配置文件);
返回新FirefoxDriver(能力);
}



例外是这样的:

 异常日志:从服务器无响应的URL为http:在OpenQA.Selenium://本地主机:7062 /集线器/会话/ ...... 
堆栈跟踪.Remote.HttpCommandExecutor.CreateResponse(WebRequest的
要求)在OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串
driverCommandToExecute,Dictionary`2参数)在...


解决方案

我使用的Windows 7任务计划,希望它是相同的。在调度,在常规选项卡上,单击运行用户是否登录或不。使用此设置,则需要输入密码,只要你保存属性。
当它运行时什么都不会出现在屏幕上。我已阅读这些论坛上说,在这种模式下运行时,如果你试图抓住一个图像将是空白的。


We have an application where we use the Selenium test framework. The application runs on Windows Server 2012 and runs regularly through Windows Task Scheduler. I connect to the server through Remote Desktop.

The problem occurs when I set in the scheduled task set-up option "Run whether user is logged on or not". My application starts to run properly with this javascript code but then it ends immediately with error exception - it is marked on the line below. If I start the application normally, everything works fine. Unfortunately, I need to make an application which can run even when no one is logged on. Hasn´t anyone already met with this problem?

This is my code:

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 looks like this:

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

解决方案

I am using Task Scheduler on Windows 7, hopefully it's the same. In the scheduler, on the General tab, click "Run whether the user is logged on or not". With this setting, you will need to enter your password whenever you save the properties. When it runs nothing will appear on the screen. I have read on these forums that, running in this mode, if you try to grab an image it will be blank.

这篇关于硒作为运行在Windows服务器上的计划任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆