private bool LaunchChrome() { try { ComArgs.RoLog.WriteLog(LogStatus.LInfo, "准备开启ChromeDriver服务,浏览器"); //提取超时 TimeSpan timeout = TimeSpan.FromSeconds(_launchAction.Timeout); ChromeOptions chromeOptions = new ChromeOptions(); //ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(); //chromeDriverService.HideCommandPromptWindow = true; //下载设置 chromeOptions.AddUserProfilePreference("download.default_directory", @"C:/Users/%username%/Downloads/"); chromeOptions.AddUserProfilePreference("download.prompt_for_download", false); //chromeOptions.BinaryLocation = "C:/Browser/chromedriver.exe"; //启动chrome浏览器 ComArgs.WebTestDriver = new ChromeDriver("C:/Browser", chromeOptions); ComArgs.WebTestDriver.Manage().Timeouts().PageLoad = timeout; //获取url值 ArgsIntoValue asArgsIntoValue = new ArgsIntoValue(); string url = asArgsIntoValue.BackNormalString(_launchAction.Url); ComArgs.WebTestDriver.Navigate().GoToUrl(url); ComArgs.RoLog.WriteLog(LogStatus.LDeb, $"当前的CurrentWindowHandle是:{ComArgs.WebTestDriver.CurrentWindowHandle}"); //设置长和高 //ComArgs.WebTestDriver.Manage().Window.Maximize(); ComArgs.SigTestStep.ResultStr = "成功"; ComArgs.SigTestStep.Result = true; ComArgs.SigTestStep.ExtraInfo = $"启动浏览器成功,使用浏览器为:{_launchAction.BrowserType}, 进入网址为:{url}"; return(true); } catch (Exception e) { ComArgs.SigTestStep.ResultStr = "异常"; ComArgs.SigTestStep.Result = false; ComArgs.SigTestStep.ExtraInfo = $"类:{GetType().Name}中方法:{MethodBase.GetCurrentMethod().Name}发生异常"; ComArgs.SigTestStep.Message = e.Message; ComArgs.SigTestStep.StackTrace = e.StackTrace; ComArgs.SigTestStep.FullName = e.TargetSite.DeclaringType?.FullName; return(false); } finally { ComArgs.SigTestStep.StepName = _launchAction.ActionType; ComArgs.SigTestStep.ControlId = "未使用"; _guiViewEvent.OnUiViewSteps(ComArgs.SigTestStep); } }
/// <summary> /// 元素集解析核心 /// 解析传入的元素集tci文件 /// 当运行Testsconfig的时候开始处理 /// <param name="sigconf">单个conf实体类</param> /// </summary> public ElementEntrance(ConfigurationFile sigconf) { try { //尽量使用字典来处理一堆N多的而又复杂的逻辑对应关系,初始化 ElementDic = new Dictionary <string, object>(); /* * 处理roi/tci文件的路径问题(还要考虑参数化问题) * 参数形式为${abcdef}、${abc${def}}、${${abc}def} */ string noargspath = new ArgsIntoValue().BackNormalString(sigconf.Path); //返回一个没有参数的路径 //开始查找对应的文件 FileInfo fileInfo = new FileInfo(noargspath); //如果文件存在 if (fileInfo.Exists) { WebElementAssist(sigconf, noargspath); } //如果文件不存在,说明可能就不存在,或简写为文件名,而不是全路径,也需要区别对待(暂未开发) else { if (!string.IsNullOrEmpty(ComArgs.GuiUsePath.RoiPath)) { //如果值存在 string path = $"{ComArgs.GuiUsePath.RoiPath}/{noargspath}"; //文件路径 ComArgs.RoLog.WriteLog(LogStatus.LInfo, $"ElementEntrance中当前处理的路径为:{path}"); //开始查找对应的文件 fileInfo = new FileInfo(path); //如果文件存在且是type为RoWeb if (fileInfo.Exists && sigconf.Type == "RoWeb") { WebElementAssist(sigconf, path); //使用私有方法 } } } } catch (Exception e) { ComArgs.RoLog.WriteLog(LogStatus.LExpt, "Exception入口发生异常", e.ToString()); } }
/// <summary> /// 是否不等 /// </summary> /// <param name="areInfo"></param> /// <returns></returns> private bool AreNotEqualPrvFunc(AreInfo areInfo) { bool re = true; string actV = string.Empty; try { //获取ele IWebElement ele = new FindWebElement(areInfo.ElementId, _waitUntilAction.Timeout).WebElement; if (ele == null) { ComArgs.SigTestStep.ResultStr = "失败"; ComArgs.SigTestStep.Result = false; ComArgs.SigTestStep.ExtraInfo = $"查找元素:{areInfo.ElementId}不存在,请仔细检查对应控件"; } else { //更改预期值为无参数 string expvalue = new ArgsIntoValue().BackNormalString(areInfo.ExpectedValue); List <string> actvalue = new List <string>(); //根据检索不同查询 switch (areInfo.ActualType) { case "Browser.Title": actvalue.Add(ComArgs.WebTestDriver.Title); break; case "Browser.Url": actvalue.Add(ComArgs.WebTestDriver.Url); break; case "RoWebElement.Text": //还需要区分EasyUI的部分写法,不仅是value,还有其他的 actvalue.Add(ele.GetAttribute("value")); actvalue.Add(ele.GetAttribute("innerText")); actvalue.Add(ele.GetAttribute("textContent")); actvalue.Add(ele.GetAttribute("text")); actvalue.Add(ele.Text); break; case "RoWebElement.GetAttribute": actvalue.Add(ele.GetAttribute(areInfo.Name)); break; } //结果检索 foreach (string sigvalue in actvalue) { if (sigvalue != null && sigvalue.Equals(expvalue)) { re = false; actV = sigvalue; break; } } if (re) { ComArgs.SigTestStep.ResultStr = "成功"; ComArgs.SigTestStep.Result = true; ComArgs.SigTestStep.ExtraInfo = $"控件文本预期值:{expvalue}, 实际值:{actV}, 实际类型:{areInfo.ActualType}"; } else { ComArgs.SigTestStep.ResultStr = "失败"; ComArgs.SigTestStep.Result = false; StringBuilder abc = new StringBuilder(); foreach (string one in actvalue) { abc.Append($"{one}/"); } ComArgs.SigTestStep.ExtraInfo = $"控件文本预期值:{expvalue}, 实际值:{abc}, 实际类型:{areInfo.ActualType}"; } } return(re); } catch (WebDriverTimeoutException) { ComArgs.SigTestStep.ResultStr = "失败"; ComArgs.SigTestStep.Result = false; ComArgs.SigTestStep.ExtraInfo = "RoWarlock操作超时"; return(false); } catch (Exception e) { ComArgs.SigTestStep.ResultStr = "异常"; ComArgs.SigTestStep.Result = false; ComArgs.SigTestStep.ExtraInfo = $"类:{GetType().Name}中方法:{MethodBase.GetCurrentMethod().Name}发生异常"; ComArgs.SigTestStep.Message = e.Message; ComArgs.SigTestStep.StackTrace = e.StackTrace; ComArgs.SigTestStep.FullName = e.TargetSite.DeclaringType?.FullName; return(false); } finally { ComArgs.SigTestStep.StepName = _waitUntilAction.ActionType; ComArgs.SigTestStep.ControlId = areInfo.ElementId; _guiViewEvent.OnUiViewSteps(ComArgs.SigTestStep); } }