public void SnapshotHelper_CaptureTempSnapshot() { AutomationElement element = TestUtility.GetCalculatorButton1Element(); string token = null; SnapshotHelper.CaptureTempSnapshot(element, out token); Assert.IsNotNull(token); TestUtility.ExitWindowCalculator(); try { SnapshotHelper.CaptureTempSnapshot(element, out token); Assert.Fail("element not available, should throw ElementNotAvailableException"); } catch (ElementNotAvailableException) { Assert.IsTrue(true); //succeed } }
public void AddObjectsWindow_CaptureTempSnapshot() { ObjectDescriptor descriptor = ObjectDescriptor.FromJson(@" { ""ntype"": ""uia"", ""nname"": ""Window: Calculator"", ""identifyProperties"": { ""type"": ""Window"", ""className"": ""QWidget"", ""title"": ""Calculator"" } }"); UIATestObject testObject = (UIATestObject)descriptor.GetObject(); AutomationElement element = testObject.AutomationElement; string elementInfo = UIAUtility.DumpAutomationElement(element); Debug.WriteLine(elementInfo); AddObjectsWindow window = new AddObjectsWindow(null); string token; SnapshotHelper.CaptureTempSnapshot(element, out token); CacheHandler handler = new CacheHandler(AppEnvironment.CurrentDirectory); string targetPath = Path.Combine(Environment.CurrentDirectory, "calculator.png"); handler.MoveCachedItemToFile(token, targetPath); Assert.IsTrue(File.Exists(targetPath)); Image image = Image.FromFile(targetPath); Assert.AreEqual(302 + 20, image.Size.Width); Assert.AreEqual(317 + 20, image.Size.Height); }