【问题标题】:.exe starts successfully with windows scheduler but not throws error on visualcron.exe 使用 Windows 调度程序成功启动,但不会在 visualcron 上引发错误
【发布时间】:2015-02-09 21:54:53
【问题描述】:

当我登录机器运行 exe 时,脚本工作正常。但是当我在 VisualCron 上安排 .exe 时,它​​会引发异常。我在 Windows 调度程序上尝试了相同的 .exe,我能够运行该作业。

错误详情如下。我该如何解决这个问题。请帮忙。

代码:

using log4net;
using Microsoft.VisualStudio.TestTools.UITest.Common;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;


namespace SeleniumDocManager
{

    class To_Run_IE
    {
        private static ILog log;
          static void ConfigureLog4Net()
        {
            log4net.GlobalContext.Properties["applicationname"] = "Selenium";
            log4net.Config.XmlConfigurator.Configure();
            log = LogManager.GetLogger(System.Reflection.Assembly.GetExecutingAssembly().GetType());
        }

        static string CreateFileFolder()
        {
            //Environment.CurrentDirectory = "C:\\myCSharp\\mySelenium";
            Environment.CurrentDirectory = "E:\\Jobs\\Visualcron\\QA\\myInfoCenter";
            string foldername = Path.Combine(Environment.CurrentDirectory, DateTime.Now.ToString("yyyy-MM-dd"));
            if (!Directory.Exists(foldername))
            {
                Directory.CreateDirectory(foldername);
            }
            return foldername;
        }

        static void Main(string[] args)
        {
            ConfigureLog4Net();
            string todayFolder = CreateFileFolder();
            string programOutputPath = Path.Combine(todayFolder, "ProgramOutput.txt");
            IWebDriver driver = new InternetExplorerDriver();
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(programOutputPath, true))
            {
                file.WriteLine("Starting Test, page title is: " + driver.Title);
            }
            string outputpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                Console.Write ("outputpath is :" + outputpath + "        ");
            log.Debug("Starting Test, page title is: " + driver.Title);
            System.Console.WriteLine("Starting Test, page title is: " + driver.Title);
            System.Console.WriteLine("Page source is: " + driver.PageSource);
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("http://cf-qa-web01:100/Home/Attachments/B1C56889-54D6-E211-ACC3-0050569D4561");
            System.Threading.Thread.Sleep(5000);
            By byXpath = By.XPath("//select[@id='DocumentType']");
            System.Threading.Thread.Sleep(5000);
            new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists(byXpath));
            IWebElement element = driver.FindElement(byXpath);
            var selectElement = new SelectElement(element);
            int options = selectElement.Options.Count;
            System.Threading.Thread.Sleep(5000);
            Screenshot s0 = ((ITakesScreenshot)driver).GetScreenshot();
            System.Threading.Thread.Sleep(5000);
            s0.SaveAsFile(Path.Combine(todayFolder, string.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}.jpeg", "Document_Manager_Initial_Screenshot", DateTime.Now)),
                System.Drawing.Imaging.ImageFormat.Gif);
            System.Threading.Thread.Sleep(2000);

            try
            {            
                Console.WriteLine(selectElement.Options[0].Text);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(programOutputPath, true))
                {
                    file.WriteLine("Capture @ " + selectElement.Options[0].Text);
                }

                string _getssName = selectElement.Options[0].Text;
                //new SelectElement(driver.FindElement(byXpath)).SelectByIndex(0);
                Console.WriteLine("Capturing " + "Select Document Type" + " dropdown screenshot");
                System.Threading.Thread.Sleep(5000);
                Screenshot sss = ((ITakesScreenshot)driver).GetScreenshot();
                System.Threading.Thread.Sleep(5000);
                sss.SaveAsFile(Path.Combine(todayFolder, string.Format("{0}_{1}_{2:yyyy-MM-dd_HH-mm-ss}.jpeg", " Select Document Type ", "dropdown", DateTime.Now))

错误详情:

未处理的异常:OpenQA.Selenium.UnhandledAlertException:OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串 driverCommandToExecute,Dictionary`2 参数)的 OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(响应错误响应)出现模态对话框SeleniumDocManager.To_Run_IE.Main(String[] args) 处的 .Selenium.Remote.RemoteWebDriver.GetScreenshot() 任务中的异常:非零退出代码

【问题讨论】:

标签: windows cron scheduler


【解决方案1】:

默认情况下,所有任务都由 VisualCron 服务在后台执行,通常以 SYSTEM 帐户运行。如果出于某种原因,您的可执行文件试图显示一个界面,它将阻止系统,因为在后台没有桌面可以显示或与消息交互。

您可能想知道它引发错误的原因。但如果它在 VisualCron 之外工作,原因通常是你不能;

  1. 使用凭据
  2. 尚未在凭据设置中检查“加载配置文件”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多