public void TestCleanUp() { scripter.RunLine("word.close"); Process[] proc = Process.GetProcessesByName("word"); if (proc.Length != 0) { KillProcesses(); } }
public void HeigthFilterTest() { int maxHeight = 250 * 100 / 850; int minHeight = 80 * 100 / 850; int expectedRectanglesCount = 5; string imageWithRectanglesPath = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.Rectangles8), "png"); scripter.RunLine($"image.findrectangles {SpecialChars.Text}{imageWithRectanglesPath}{SpecialChars.Text} maxheight {maxHeight} minheight {minHeight}"); Assert.AreEqual(expectedRectanglesCount, scripter.Variables.GetVariableValue <List <Object> >("result").Count); }
public void OutlookCloseTest() { KillProcesses(); //System.Threading.Thread.Sleep(5000); Process[] userProcesses = Process.GetProcessesByName("outlook"); scripter.RunLine("outlook.open"); int tick = 0; int starttick = Environment.TickCount; int openingDelay = 50000; Process[] allProcesses = Process.GetProcessesByName("outlook"); while (allProcesses.Length <= userProcesses.Length && tick <= starttick + openingDelay) { allProcesses = Process.GetProcessesByName("outlook"); tick = Environment.TickCount; Thread.Sleep(10); } //int beforeCount = Process.GetProcessesByName("outlook").Length; //scripter.RunLine("outlook.open"); //System.Threading.Thread.Sleep(5000); //int runCount = Process.GetProcessesByName("outlook").Length; //Assert.IsTrue(runCount > beforeCount); Assert.IsTrue(allProcesses.Length > userProcesses.Length); List <Process> diffProcesses = new List <Process>(); foreach (var proc in allProcesses) { if (!userProcesses.Contains(proc)) { diffProcesses.Add(proc); } } scripter.RunLine("outlook.close"); //System.Threading.Thread.Sleep(25000); //int closeCount = Process.GetProcessesByName("outlook").Length; allProcesses = Process.GetProcessesByName("outlook"); Assert.AreEqual(userProcesses.Length, allProcesses.Length); //Assert.AreEqual(beforeCount, closeCount); }
public void OutlookOpenTest() { KillProcesses(); Thread.Sleep(5000); int processesCount = Process.GetProcessesByName("outlook").Length; scripter.Text = "outlook.open"; scripter.Run(); Thread.Sleep(5000); Assert.IsTrue(processesCount < Process.GetProcessesByName("outlook").Length); scripter.RunLine("outlook.close"); }
public void WaitForNotExistingImageTest() { string path = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.purpleInYellow), "bmp"); Scripter scripter = new Scripter(); Exception exception = Assert.Throws <ApplicationException>(delegate { scripter.RunLine($"waitfor.image image {SpecialChars.Text}{path}{SpecialChars.Text} timeout 1000"); }); Assert.IsInstanceOf <TimeoutException>(exception.GetBaseException()); }
public void TestCleanup() { foreach (string path in filePaths) { if (path != null) { try { scripter.RunLine("xlsx.close"); } catch { } File.Delete(path); } } }
public void WordCloseTest() { KillProcesses(); Process[] userProcesses = Process.GetProcessesByName("winword"); scripter.RunLine(@"word.open"); int tick = 0; int starttick = Environment.TickCount; int openingDelay = 20000; Process[] allProcesses = Process.GetProcessesByName("winword"); while (allProcesses.Length <= userProcesses.Length && tick <= starttick + openingDelay) { allProcesses = Process.GetProcessesByName("winword"); tick = Environment.TickCount; Thread.Sleep(10); } Assert.IsTrue(allProcesses.Length > userProcesses.Length); List <Process> diffProcesses = new List <Process>(); foreach (var proc in allProcesses) { if (!userProcesses.Contains(proc)) { diffProcesses.Add(proc); } } scripter.RunLine(@"word.close"); System.Threading.Thread.Sleep(2000); allProcesses = Process.GetProcessesByName("winword"); Assert.AreEqual(userProcesses.Length, allProcesses.Length); }
public void SharpenImageTest() { string image = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.greenRectangle), "bmp"); string image2 = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.greenInRed), "bmp"); Scripter scripter = new Scripter(); scripter.RunLine($"image.sharpen path {SpecialChars.Text}{image}{SpecialChars.Text}"); scripter.RunLine($"image.expected image1 {SpecialChars.Text}{image}{SpecialChars.Text} image2 {SpecialChars.Text}{image2}{SpecialChars.Text}"); var result = scripter.Variables.GetVariableValue <bool>("result"); Assert.AreEqual(false, result); string image3 = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.bmp"); scripter.RunLine($"image.sharpen path {SpecialChars.Text}{image2}{SpecialChars.Text} outputpath {SpecialChars.Text}{image3}{SpecialChars.Text}"); Assert.AreEqual(true, File.Exists(image3)); scripter.RunLine($"image.expected image2 {SpecialChars.Text}{image3}{SpecialChars.Text} image1 {SpecialChars.Text}{image}{SpecialChars.Text}"); result = scripter.Variables.GetVariableValue <bool>("result"); Assert.AreEqual(true, result); }
public void BadOutputPathTest() { string image = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.greenRectangle), "bmp"); paths.Add(image); string badPath = @"c:\\A(SF9\asf9j0-0\\asfk00asf0a4e9->X>"; Scripter scripter = new Scripter(); Exception exception = Assert.Throws <ApplicationException>(delegate { scripter.RunLine($"image.sharpen path {SpecialChars.Text}{image}{SpecialChars.Text} outputpath {SpecialChars.Text}{badPath}{SpecialChars.Text}"); }); Assert.IsInstanceOf <ArgumentException>(exception.GetBaseException()); }
public void PingGoogleTest() { Scripter scripter = new Scripter(); scripter.InitVariables.Clear(); scripter.InitVariables.Add("ping", new TextStructure("google.com")); try { scripter.RunLine($"ping ip {SpecialChars.Variable}ping"); int response = scripter.Variables.GetVariableValue <int>("result"); Assert.IsTrue(response >= 0); } catch { Assert.Inconclusive("We can't ping google.com, it is very unlikely"); } }
public void ExcelImportTextTest() { string twentyOne = 21.ToString(); string thirtyTwo = 32.ToString(); scripter.RunLine($@"excel.open {SpecialChars.Variable}csvPath excel.importtext path {SpecialChars.Variable}csvPath delimiter , excel.getvalue row 2 colindex 1 result {SpecialChars.Variable}result1 excel.getvalue row 3 colindex 2 result {SpecialChars.Variable}result2 excel.importtext path {SpecialChars.Variable}csvPath destination D1 delimiter , excel.getvalue row 2 colindex 4 result {SpecialChars.Variable}result3 excel.getvalue row 3 colindex 5 result {SpecialChars.Variable}result4 excel.importtext path {SpecialChars.Variable}csvPath destination (point)4,1 delimiter , excel.getvalue row 5 colindex 1 result {SpecialChars.Variable}result5 excel.getvalue row 6 colindex 2 result {SpecialChars.Variable}result6 excel.close"); Assert.AreEqual(twentyOne, scripter.Variables.GetVariableValue <string>("result1")); Assert.AreEqual(thirtyTwo, scripter.Variables.GetVariableValue <string>("result2")); Assert.AreEqual(twentyOne, scripter.Variables.GetVariableValue <string>("result3")); Assert.AreEqual(thirtyTwo, scripter.Variables.GetVariableValue <string>("result4")); Assert.AreEqual(twentyOne, scripter.Variables.GetVariableValue <string>("result5")); Assert.AreEqual(thirtyTwo, scripter.Variables.GetVariableValue <string>("result6")); }
public void FindImageOnScreenTest() { string colorCode = "00000000"; string image = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.littleWhite), "bmp"); testerApp = SDK.Tester.RunFormTester("Title TestApp"); Scripter scripter = new Scripter(); scripter.InitVariables.Clear(); scripter.RunLine("window TestApp"); scripter.InitVariables.Add(nameof(colorCode), new TextStructure(colorCode)); scripter.Text = $@"keyboard {TextChar}FocusOnControl tbColorRGB{TextChar} keyboard {SpecialChars.KeyBegin}enter{SpecialChars.KeyEnd} keyboard {TextChar}{SpecialChars.Variable}{nameof(colorCode)}{TextChar} keyboard {SpecialChars.KeyBegin}enter{SpecialChars.KeyEnd}"; scripter.Run(); scripter.Text = $"image.find image1 {SpecialChars.Text}{image}{SpecialChars.Text}"; scripter.Run(); Thread.Sleep(OneSecond * 2); }
public void ExcelSaveTest() { try { string saveDir = System.IO.Directory.GetCurrentDirectory() + @"\"; string savePath = saveDir + "test.xlsx"; FileInfo savedFile = new FileInfo(savePath); if (savedFile.Exists) { savedFile.Delete(); } scripter.InitVariables.Add("savePath", new TextStructure(savePath)); scripter.RunLine("excel.open"); scripter.RunLine("excel.addsheet test1"); scripter.RunLine("excel.activatesheet test1"); scripter.RunLine("excel.setvalue 3 row 1 colindex 1"); scripter.RunLine("excel.addsheet test2"); scripter.RunLine("excel.activatesheet test2"); scripter.RunLine("excel.setvalue 5 row 2 colindex 1"); scripter.RunLine($"excel.save {SpecialChars.Variable}savePath"); scripter.RunLine("excel.close"); scripter.RunLine($"excel.open {SpecialChars.Variable}savePath"); scripter.RunLine("excel.activatesheet test1"); scripter.RunLine("excel.getvalue row 1 colindex 1"); Assert.AreEqual(3, int.Parse(scripter.Variables.GetVariableValue <string>("result"))); scripter.RunLine("excel.activatesheet test2"); scripter.RunLine("excel.getvalue row 2 colindex 1"); Assert.AreEqual(5, int.Parse(scripter.Variables.GetVariableValue <string>("result"))); scripter.RunLine("excel.close"); } catch (Exception ex) { KillProcesses(); throw ex.GetBaseException(); } }
public void CloseTest() { int[] xlsIds = new int[filesCount]; for (int i = 0; i < filesCount; i++) { scripter.RunLine($"xlsx.open {SpecialChars.Text}{filePaths[i]}{SpecialChars.Text}"); xlsIds[i] = scripter.Variables.GetVariableValue <int>("result"); } bool gotAccessToopenedfile = true; FileStream openedFile = null; try { openedFile = File.Open(filePaths[0], FileMode.Open, FileAccess.ReadWrite); } catch { gotAccessToopenedfile = false; } finally { if (openedFile != null) { openedFile.Close(); openedFile = null; } } Assert.IsFalse(gotAccessToopenedfile, $"Access aquired to file '{filePaths[0]}' despaite it's openede by xlsx command"); scripter.RunLine($"xlsx.close id {xlsIds[0]}"); gotAccessToopenedfile = true; openedFile = null; try { openedFile = File.Open(filePaths[0], FileMode.Open, FileAccess.ReadWrite); } catch (Exception) { gotAccessToopenedfile = false; } finally { if (openedFile != null) { openedFile.Close(); openedFile = null; } } Assert.IsTrue(gotAccessToopenedfile, $"Access do not aquired to file '{filePaths[0]}' despaite it's closed by xlsx.close command"); for (int i = 1; i < filesCount; i++) { scripter.RunLine($"xlsx.close"); } for (int i = 1; i < filesCount; i++) { gotAccessToopenedfile = true; openedFile = null; try { openedFile = File.Open(filePaths[i], FileMode.Open, FileAccess.ReadWrite); } catch (Exception) { gotAccessToopenedfile = false; } finally { if (openedFile != null) { openedFile.Close(); openedFile = null; } } Assert.IsTrue(gotAccessToopenedfile, $"Access do not aquired to file '{filePaths[i]}' despaite it's closed by xlsx.close command"); } }
public void TestInit() { Language.Addon addon = Language.Addon.Load(@"G1ANT.Addon.MSOffice.dll"); scripter.RunLine($"excel.open"); }
public void ExcelCloseTest() { scripter.RunLine("excel.close"); scripter.RunLine("delay 1"); Assert.AreEqual(userProcessCount, Process.GetProcessesByName("excel").Length); }