当我登录到机器时运行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中的OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(响应errorResponse)中的Open模式对话框OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2参数) .Selenium.Remote.RemoteWebDriver.GetScreenshot()在SeleniumDocManager.To_Run_IE.Main(String [] args)任务中的异常:非零退出代码
答案 0 :(得分:0)
默认情况下,VisualCron服务在后台执行所有任务,通常作为SYSTEM帐户运行。如果由于某种原因,您的可执行文件试图显示一个界面,它将阻止系统,因为后台没有桌面可以显示或与消息交互。
您可能想知道它抛出错误的原因。但如果它在VisualCron之外工作,原因通常是你不是;