public static bool CompareStates(DeviceConfig cref, DeviceConfig cn, bool compareTextSimilarity, bool compareScreenshotSimilarity, bool compareScreenshotOCRSimilarity, out string msg) { bool ok = false; msg = ""; if (CheckDeviceConfigCompatibility(cref, cn, out msg)) { int qtd = cn.Events.Count; for (int i = 0; i < qtd; i++) { Support.MyNode.CompareStates(cref.Events[i], cn.Events[i], compareTextSimilarity, compareScreenshotSimilarity, compareScreenshotOCRSimilarity); } ok = true; } return(ok); }
public static string CompareStatesGenerateOutPut(DeviceConfig cref, DeviceConfig cn, bool compareTextSimilarity, bool compareScreenshotSimilarity, bool compareScreenshotOCRSimilarity) { string html = File.ReadAllText("Resources/template2.html"); string templateNodes = @"<div class=""connector""></div> <div class=""event""> <div class=""eventId"">{0}</div> </div>"; string templateComparisonNodes = @"<div class=""connector""></div> <div class=""event eventComparison""> <div class=""titleCriteria""> COMPATIBILITY CRITERIA </div> <b>*TSHWVC:</b> {0}% <br> <b>*TST:</b> {1}% <br> <b>*SS:</b> {2}% <br> <b>*SOCRS:</b> {3}% <br> <b>*Runtime:</b> {4}% ({5} is faster) <br> <br> <div class=""titleCriteria""> EQUIVALENCE CRITERIA </div> <b>*ENP:</b> {6} <br> </div>"; List <string> nodes = new List <string>(); int i = 0; html = html.Replace("@deviceName1", MyNode.ExtractDeviceId(cref)); nodes.Clear(); i = 0; //device2 vs device1 foreach (MyNode n in cn.Events) { string eventName = n.EventName; if (string.IsNullOrEmpty(eventName)) { eventName = "unnamed"; } if (eventName.Length > 20) { eventName = eventName.Substring(0, 20); } nodes.Add(string.Format(templateNodes, eventName)); i++; } html = html.Replace("@deviceName2", MyNode.ExtractDeviceId(cn)); html = html.Replace("@devicesModel", string.Join(Environment.NewLine, nodes.ToArray())); #region Comparasion device 2 vs device 1 List <string> nodesCompare = new List <string>(); foreach (MyNode n in cn.Events) { string textSimilarityHybridPercentage = "-"; string textSimilarityTotalPercentage = "-"; string guiScreenshotSimilarityPercentage = "-"; string guiScreenshotOCRSimilarityPercentage = "-"; string runtimeDifferencePercentage = "-"; string runtimeFaster = "-"; string elementNegativelyPositioning = "-"; if (compareTextSimilarity) { textSimilarityHybridPercentage = Math.Round(n.ExecutationState.VerificationStateCriteria.CompatibilityCriteriaTextSimilarityHybridPercentage, 2).ToString(); textSimilarityTotalPercentage = Math.Round(n.ExecutationState.VerificationStateCriteria.CompatibilityCriteriaTextSimilarityTotalPercentage, 2).ToString(); } if (compareScreenshotSimilarity) { guiScreenshotSimilarityPercentage = Math.Round(n.ExecutationState.VerificationStateCriteria.CompatibilityCriteriaGUIScreenshotSimilarityPercentage, 2).ToString(); } if (compareScreenshotOCRSimilarity) { guiScreenshotOCRSimilarityPercentage = Math.Round(n.ExecutationState.VerificationStateCriteria.CompatibilityCriteriaGUIScreenshotOCRSimilarityPercentage, 2).ToString(); } if (n.ExecutationState.VerificationStateCriteria.CompatibilityCriteriaRuntimeFaster) { runtimeFaster = "Cn"; } else { runtimeFaster = "Cref"; } runtimeDifferencePercentage = Math.Round(n.ExecutationState.VerificationStateCriteria.CompatibilityCriteriaRuntimeDifferencePercentage, 2).ToString(); elementNegativelyPositioning = n.ExecutationState.VerificationStateCriteria.EquivalenceCriteriaElementNegativelyPositioning.ToString(); nodesCompare.Add(string.Format(templateComparisonNodes, textSimilarityHybridPercentage, textSimilarityTotalPercentage, guiScreenshotSimilarityPercentage, guiScreenshotOCRSimilarityPercentage, runtimeDifferencePercentage, runtimeFaster, elementNegativelyPositioning)); } html = html.Replace("@comparison2vs1", string.Join(Environment.NewLine, nodesCompare.ToArray())); #endregion string dirOutPut = Path.GetDirectoryName(Application.ExecutablePath) + @"\output"; if (!Directory.Exists(dirOutPut)) { Directory.CreateDirectory(dirOutPut); } string output = dirOutPut + @"\" + DateTime.Now.ToString("yyyy-MM-dd HHmss") + ".html"; TextWriter tw = new StreamWriter(output, true); tw.WriteLine(html); tw.Close(); return(output); }
public static bool CheckDeviceConfigCompatibility(DeviceConfig cref, DeviceConfig cn, out string msg) { msg = ""; if (ExtractDeviceId(cref).Trim() == "" || ExtractDeviceId(cn).Trim() == "") { msg = "Devices not configured."; return(false); } if (cn.Events == null) { msg = ExtractDeviceId(cn) + " sequence event not defined."; return(false); } if (cref.Events == null) { msg = ExtractDeviceId(cref) + " sequence event not defined."; return(false); } if (cn.Events == null) { msg = ExtractDeviceId(cn) + " sequence event not defined."; return(false); } if (cref.Events.Count != cn.Events.Count) { msg = "The amount of events is incompatible."; return(false); } foreach (MyNode n in cref.Events) { if (n.ExecutationState.Equals(null)) { msg = "Executation state undefined. Run test (" + ExtractDeviceId(cref) + ")."; return(false); } } foreach (MyNode n in cn.Events) { if (n.ExecutationState.Equals(null)) { msg = "Executation state undefined. Run test (" + ExtractDeviceId(cn) + ")."; return(false); } } int qtd = cref.Events.Count; for (int i = 0; i < qtd; i++) { if (cref.Events[i].EventName != cn.Events[i].EventName) { msg = "EventName " + (i + 1) + " - '" + cref.Events[i].EventName + "' and '" + cn.Events[i].EventName + "' are different."; return(false); } else if (cref.Events[i].SendClick != cn.Events[i].SendClick) { msg = "SendClick " + (i + 1) + " - '" + cref.Events[i].EventName + "' and '" + cn.Events[i].EventName + "' are different."; return(false); } else if (cref.Events[i].SendKeysText != cn.Events[i].SendKeysText) { msg = "SendKeysText " + (i + 1) + " - '" + cref.Events[i].EventName + "' and '" + cn.Events[i].EventName + "' are different."; return(false); } else if (cref.Events[i].WaitElementBySecond != cn.Events[i].WaitElementBySecond) { msg = "WaitElementBySecond " + (i + 1) + " - '" + cref.Events[i].EventName + "' and '" + cn.Events[i].EventName + "' are different."; return(false); } } return(true); }
public static bool CheckDeviceConfigCompatibility(DeviceConfig cref, DeviceConfig cn, out string msg) { msg = ""; if (ExtractDeviceId(cref).Trim() == "" || ExtractDeviceId(cn).Trim() == "") { msg = "Devices not configured."; return(false); } if (cref.AppName.Trim() != cn.AppName.Trim()) { msg = "App Name isn't equal."; return(false); } if (cref.AppActivity.Trim() != cn.AppActivity.Trim()) { msg = "AppActivity Name isn't equal."; return(false); } if (cref.TestCaseName.Trim() == "" || cn.TestCaseName.Trim() == "") { msg = "Test Case Name is required."; return(false); } if (cref.TestCaseName.Trim() != cn.TestCaseName.Trim()) { msg = "Test Case Name isn't equal."; return(false); } if (cn.Events == null) { msg = ExtractDeviceId(cn) + " sequence event not defined."; return(false); } if (cref.Events == null) { msg = ExtractDeviceId(cref) + " sequence event not defined."; return(false); } if (cn.Events == null) { msg = ExtractDeviceId(cn) + " sequence event not defined."; return(false); } if (cref.Events.Count != cn.Events.Count) { msg = "The amount of events is incompatible."; return(false); } int qtd = cref.Events.Count; for (int i = 0; i < qtd; i++) { if (cref.Events[i].EventName != cn.Events[i].EventName) { msg = "EventName " + (i + 1) + " - '" + cref.Events[i].EventName + "' and '" + cn.Events[i].EventName + "' are different."; return(false); } else if (cref.Events[i].SendClick != cn.Events[i].SendClick) { msg = "SendClick " + (i + 1) + " - '" + cref.Events[i].EventName + "' and '" + cn.Events[i].EventName + "' are different."; return(false); } else if (cref.Events[i].SendKeysText != cn.Events[i].SendKeysText) { msg = "SendKeysText " + (i + 1) + " - '" + cref.Events[i].EventName + "' and '" + cn.Events[i].EventName + "' are different."; return(false); } else if (cref.Events[i].WaitElementBySecond != cn.Events[i].WaitElementBySecond) { msg = "WaitElementBySecond " + (i + 1) + " - '" + cref.Events[i].EventName + "' and '" + cn.Events[i].EventName + "' are different."; return(false); } } return(true); }
public static string GenerateScriptMethodTest(DeviceConfig deviceConfigAndroid, DeviceConfig deviceConfigIOS, TpLocatorEstrategy locatorEstrategy, XPathSelector.XPathType individualExpressionType, bool staticMethod, string appiumDriverName, out string functionCall, out string appiumConfig) { functionCall = ""; appiumConfig = ""; #region validation string msg = ""; if (!Support.MyNode.CheckDeviceConfigCompatibility(deviceConfigAndroid, deviceConfigIOS, out msg)) { return(msg); } #endregion StringBuilder scriptCallFunction = new StringBuilder(); List <string> functionList = new List <string>(); List <string> scriptList = new List <string>(); StringBuilder appiumConfigList = new StringBuilder(); string elementName = "e"; int qtdEvents = deviceConfigAndroid.Events.Count; for (int i = 0; i < qtdEvents; i++) { MyNode nAndroid = deviceConfigAndroid.Events[i]; MyNode nIOS = deviceConfigIOS.Events[i]; string scriptFunction = GenerateScriptMethodTest(nAndroid, nIOS, locatorEstrategy, individualExpressionType, staticMethod, elementName, appiumDriverName, out functionCall); if (!functionList.Contains(functionCall)) { functionList.Add(functionCall); scriptList.Add(scriptFunction); scriptCallFunction.AppendLine(_tab3 + functionCall); } } #region appium config appiumConfigList.AppendLine(); if (!EnabledEvaluation) { appiumConfigList.AppendLine(_tab3 + "_locator = new LocatorStrategy(_driver, null);"); appiumConfigList.AppendLine(); } else { #region Evaluation string strategy = locatorEstrategy.ToString(); if (locatorEstrategy == TpLocatorEstrategy.IndividualExpression) { strategy += individualExpressionType.ToString(); } appiumConfigList.AppendLine(_tab3 + "Exec.Create(\"" + deviceConfigAndroid.AppName + "\", ProjectConfig.OutputDeviceID, \"" + deviceConfigAndroid.TestCaseName + "\", " + deviceConfigAndroid.Events.Count + ",\"" + strategy + "\", ProjectConfig.OutputPath);"); appiumConfigList.AppendLine(_tab3 + "Exec.Instance.Start();"); #endregion appiumConfigList.AppendLine(); appiumConfigList.AppendLine(_tab3 + "_locator = new LocatorStrategy(_driver, Exec.Instance);"); appiumConfigList.AppendLine(); } #endregion scriptCallFunction.AppendLine(); scriptCallFunction.AppendLine(_tab3 + "Exec.Instance.EndSuccefull();"); functionCall = scriptCallFunction.ToString(); appiumConfig = appiumConfigList.ToString(); return(string.Join("\n", scriptList.ToArray())); }
public static string GenerateVisualStudioProjectTest(DeviceConfig deviceConfigAndroid, DeviceConfig deviceConfigIOS, TpLocatorEstrategy locatorEstrategy, XPathSelector.XPathType individualExpressionType) { string dirProjectTemplate = Path.GetDirectoryName(Application.ExecutablePath) + @"\Resources\UnitTestProjectTemplate"; string dirOutPut = Path.GetDirectoryName(Application.ExecutablePath) + @"\output"; if (!Directory.Exists(dirOutPut)) { Directory.CreateDirectory(dirOutPut); } string output = dirOutPut + @"\UnitTestProject-" + DateTime.Now.ToString("yyyy-MM-dd HHmmss"); if (_onlyTestClass) { output += "-TestClass"; } string appTestName = deviceConfigAndroid.TestCaseName.Replace(".", "").Replace("-", "").Replace(" ", ""); string appTest = ""; StringBuilder script = new StringBuilder(); string nl = Environment.NewLine; string functionCall; string appiumConfig; string nameSpace = appTestName; string className = appTestName + locatorEstrategy.ToString(); if (locatorEstrategy == TpLocatorEstrategy.IndividualExpression) { className += individualExpressionType.ToString(); } if (!_onlyTestClass) { Utils.DirectoryCopy(dirProjectTemplate, output); File.Move(output + @"\Properties\AssemblyInfo.txt", output + @"\Properties\AssemblyInfo.cs"); appTest = File.ReadAllText(output + @"\AppTest.txt"); string unitProjectTest = File.ReadAllText(output + @"\UnitTestProject.csproj"); string projectConfig = File.ReadAllText(output + @"\ProjectConfig.txt"); string locatorStrategy = File.ReadAllText(output + @"\LocatorStrategy.txt"); unitProjectTest = unitProjectTest.Replace("@AppTest", className + ".cs"); File.WriteAllText(output + @"\ProjectConfig.cs", projectConfig); File.Delete(output + @"\ProjectConfig.txt"); unitProjectTest = unitProjectTest.Replace("AppTest", appTestName); File.WriteAllText(output + @"\UnitTestProject.csproj", unitProjectTest); File.WriteAllText(output + @"\LocatorStrategy.cs", locatorStrategy); File.Delete(output + @"\LocatorStrategy.txt"); } else { appTest = File.ReadAllText(dirProjectTemplate + @"\AppTest.txt"); Directory.CreateDirectory(output); } script.AppendLine(ScriptGenerate.GenerateScriptMethodTest(deviceConfigAndroid, deviceConfigIOS, locatorEstrategy, individualExpressionType, false, "_driver", out functionCall, out appiumConfig)); appTest = appTest.Replace("@Namespace", nameSpace); appTest = appTest.Replace("@ClassName", className); appTest = appTest.Replace("/*REPLACE: appium config*/", appiumConfig); appTest = appTest.Replace("/*REPLACE: call sequence*/", functionCall); appTest = appTest.Replace("/*REPLACE: script*/", script.ToString()); File.WriteAllText(output + @"\" + className + ".cs", appTest); File.Delete(output + @"\AppTest.txt"); return(output); }