public void cleanup() { var status = TestContext.CurrentContext.Result.Outcome.Status; var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace) ? "" : string.Format("<pre>{0}</pre>", TestContext.CurrentContext.Result.Message); LogStatus logstatus; switch (status) { case TestStatus.Failed: logstatus = LogStatus.Fail; string screenName = ScreenshotHelper.TakeScreenshot(); string screenshotPath = TestLog.AddScreenCapture("screenshots//" + screenName); TestLog.Log(LogStatus.Fail, "Screenshot on Fail", screenshotPath); break; case TestStatus.Inconclusive: logstatus = LogStatus.Warning; TestLog.Log(LogStatus.Warning, "Warning"); break; case TestStatus.Skipped: logstatus = LogStatus.Skip; break; default: logstatus = LogStatus.Pass; break; } TestLog.Log(logstatus, "Test ended with <b>" + logstatus + stacktrace); ReportLog.EndTest(TestLog); ReportLog.Flush(); }
public async Task ShouldRunInParallel() { await using (var page = await Context.NewPageAsync()) { await page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); await page.GoToAsync(TestConstants.ServerUrl + "/grid.html"); var tasks = new List <Task <byte[]> >(); for (var i = 0; i < 3; ++i) { tasks.Add(page.ScreenshotDataAsync(new ScreenshotOptions { Clip = new Clip { X = 50 * i, Y = 0, Width = 50, Height = 50 } })); } await Task.WhenAll(tasks); Assert.True(ScreenshotHelper.PixelMatch("grid-cell-1.png", tasks[0].Result)); } }
private void Awake() { if (_instance == null) { _instance = this; } }
//Close Window with fade out animation private async void CloseSnap(bool result, int delay = 0, string errorMessage = null) { await this.AnimateAsync(OpacityProperty, Opacity, 0, 150, delay); try { if (result) { await ScreenshotHelper.FinishGif(SelectionStream, HwndName); try { DialogResult = true; } catch { // not dialog } return; } if (Error) { await Statics.ShowNotificationAsync(string.Format(strings.uploadingErrorGif, errorMessage), NotificationWindow.NotificationType.Error); } } catch { // could not finish screenshot } try { DialogResult = false; } catch { // not dialog } }
public TestScreenshot() { var now = DateTime.Now; Name = ScreenshotHelper.GetScreenName(now); Date = now; }
public async Task ShouldWorkForOffscreenClip() { using (var page = await Browser.NewPageAsync()) { await page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); await page.GoToAsync(TestConstants.ServerUrl + "/grid.html"); var screenshot = await page.ScreenshotDataAsync(new ScreenshotOptions { Clip = new Clip { X = 50, Y = 600, Width = 100, Height = 100 } }); Assert.True(ScreenshotHelper.PixelMatch("screenshot-offscreen-clip.png", screenshot)); } }
public override void OnInspectorGUI() { ScreenshotHelper helper = (ScreenshotHelper)target; DrawDefaultInspector(); if (GUILayout.Button("Take Screenshot")) { Rect lRect = new Rect(0f, 0f, 2f * Screen.width, Screen.height); if (helper.capturedImage) { Destroy(helper.capturedImage); } helper.capturedImage = zzTransparencyCapture.capture(lRect); Sprite image = Sprite.Create(helper.capturedImage, lRect, new Vector2(0.5f, 0.5f), 100f); helper.preview.sprite = image; zzTransparencyCapture.saveScreenshot(helper.capturedImage, helper.dir + "\\" + DateTime.Now.ToString("hmmss_ddmmyy") + ".png"); helper.count++; } }
internal async Task Run(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { WindowHelper.Restore(_hWnd); WindowHelper.SetForegroundWindow(_hWnd); OnReport("Capture screen"); var screenshot = ScreenshotHelper.GetScreenBitmap(_hWnd); var targetIsSelected = await SelectGoodTarget(cancellationToken, screenshot); if (!targetIsSelected && !_timer.Enabled) { _timer.Start(); } if (targetIsSelected) { await FightTarget(cancellationToken); } else { await TurnScreen(cancellationToken); } await Task.Delay(TimeSpan.FromSeconds(0.5), cancellationToken); } }
public async Task ShouldTakeIntoAccountPaddingAndBorder() { await Page.SetViewportAsync(new Viewport { Width = 500, Height = 500 }); await Page.SetContentAsync(@" <div style=""height: 14px"">oooo</div> <style>div { border: 2px solid blue; background: green; width: 50px; height: 50px; } </style> <div id=""d""></div>"); var elementHandle = await Page.QuerySelectorAsync("div#d"); byte[] screenshot = await elementHandle.ScreenshotAsync(); Assert.True(ScreenshotHelper.PixelMatch("screenshot-element-padding-border.png", screenshot)); }
public async Task ShouldWorkWithFile() { var outputFile = Path.Combine(BaseDirectory, "output.png"); var fileInfo = new FileInfo(outputFile); await using (var page = await Context.NewPageAsync()) { await page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); await page.GoToAsync(TestConstants.ServerUrl + "/grid.html"); if (fileInfo.Exists) { fileInfo.Delete(); } await page.ScreenshotAsync(outputFile); fileInfo = new FileInfo(outputFile); Assert.True(new FileInfo(outputFile).Length > 0); Assert.True(ScreenshotHelper.PixelMatch("screenshot-sanity.png", outputFile)); if (fileInfo.Exists) { fileInfo.Delete(); } } }
void OnApplicationQuit() { ScreenshotHelper myTarget = (ScreenshotHelper)target; SSHPreset sshPreset = new SSHPreset(); sshPreset.Save(myTarget); }
public async Task ShouldScrollElementIntoView() { await Page.SetViewportAsync(new Viewport { Width = 500, Height = 500 }); await Page.SetContentAsync(@" <div style=""height: 14px"">oooo</div> <style>div.above { border: 2px solid blue; background: red; height: 1500px; } div.to-screenshot { border: 2px solid blue; background: green; width: 50px; height: 50px; } </style> <div class=""above""></div> <div class=""to-screenshot""></div>"); var elementHandle = await Page.QuerySelectorAsync("div.to-screenshot"); byte[] screenshot = await elementHandle.ScreenshotAsync(); Assert.True(ScreenshotHelper.PixelMatch("screenshot-element-scrolled-into-view.png", screenshot)); }
public void Save(string fileName, ScreenshotHelper ssh) { if (string.IsNullOrEmpty(fileName)) { return; } if (ssh.shotInfo.Count <= 0) { var tempDelegate = ssh.DefaultsSet; ssh.DefaultsSet = null; ssh.SetDefaults(); ssh.DefaultsSet = tempDelegate; } sizes = ssh.shotInfo; orientation = ssh.orientation; lastSavePath = ssh.savePath; keyToPress = ssh.keyToPress; keyToHold = ssh.keyToHold; buildPathRoot = ssh.buildSavePathRoot; buildPathExtra = ssh.buildSavePathExtra; textureFormat = ssh.SSHTextureFormat; var serializer = new XmlSerializer(typeof(SSHPreset)); using (var stream = new FileStream(fileName, FileMode.Create)) serializer.Serialize(stream, this); }
private void SortSizes() { ScreenshotHelper myTarget = (ScreenshotHelper)target; List <ShotSize> shotSizes = myTarget.shotInfo; List <string> fileNames = new List <string>(); for (int i = 0; i < shotSizes.Count; i++) { fileNames.Add(myTarget.GetScreenShotName(shotSizes[i])); } fileNames.Sort(); ShotSize[] tempShotSizes = new ShotSize[shotSizes.Count]; for (int i = 0; i < fileNames.Count; i++) { for (int j = 0; j < shotSizes.Count; j++) { if (myTarget.GetScreenShotName(shotSizes[j]) == fileNames[i]) { tempShotSizes[i] = shotSizes[j]; } } } myTarget.shotInfo = new List <ShotSize>(); for (int i = 0; i < tempShotSizes.Length; i++) { myTarget.shotInfo.Add(tempShotSizes[i]); } }
private bool LoadPresetFile(string fileName, ScreenshotHelper ssh) { if (string.IsNullOrEmpty(fileName)) { return(false); } if (!File.Exists(fileName)) { return(false); } SSHPreset sshPreset = SSHPreset.Load(fileName); if (sshPreset != null) { if (sshPreset.sizes.Count > 0) { ssh.shotInfo = sshPreset.sizes; ssh.savePath = sshPreset.lastSavePath; ssh.orientation = sshPreset.orientation; return(true); } } return(false); }
void Awake() { if (_instance == null) { _instance = this; DontDestroyOnLoad(this); } else { if (this != _instance) { Destroy(this.gameObject); } } /* #if UNITY_EDITOR * if (string.IsNullOrEmpty(savePath)) * savePath = System.IO.Directory.GetCurrentDirectory() + "/screenshothelper"; */ #if !UNITY_EDITOR savePath = BuildSaveLocation(); #endif maxRes = new ShotSize(Screen.currentResolution.width, Screen.currentResolution.height); }
public async Task ShouldCaptureFullElementWhenLargerThanViewport() { await Page.SetViewportAsync(new Viewport { Width = 500, Height = 500 }); await Page.SetContentAsync(@" something above <style> div.to-screenshot { border: 1px solid blue; width: 600px; height: 600px; margin-left: 50px; } ::-webkit-scrollbar{ display: none; } </style> <div class='to-screenshot'></div>" ); var elementHandle = await Page.QuerySelectorAsync("div.to-screenshot"); byte[] screenshot = await elementHandle.ScreenshotAsync(); Assert.True(ScreenshotHelper.PixelMatch("screenshot-element-larger-than-Viewport.png", screenshot)); Assert.Equal(new[] { 500, 500 }, await Page.EvaluateAsync <int[]>("[window.innerWidth, window.innerHeight]")); }
public async Task ShouldClipScale() { await using (var page = await Context.NewPageAsync()) { await page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); await page.GoToAsync(TestConstants.ServerUrl + "/grid.html"); var screenshot = await page.ScreenshotDataAsync(new ScreenshotOptions { Clip = new Clip { X = 50, Y = 100, Width = 150, Height = 100, Scale = 2 } }); Assert.True(ScreenshotHelper.PixelMatch("screenshot-clip-rect-scale.png", screenshot)); } }
public async Task ShouldCaptureFullElementWhenLargerThanViewportInParallel() { await Page.SetViewportAsync(new Viewport { Width = 500, Height = 500 }); await Page.SetContentAsync(@" <div style=""height: 14px"">oooo</div> <style> div.to-screenshot { border: 1px solid blue; width: 600px; height: 600px; margin-left: 50px; } ::-webkit-scrollbar{ display: none; } </style> <div class=""to-screenshot""></div> <div class=""to-screenshot""></div> <div class=""to-screenshot""></div> "); var elementHandles = await Page.QuerySelectorAllAsync("div.to-screenshot"); var screenshotTasks = elementHandles.Select(e => e.ScreenshotAsync()); await Task.WhenAll(screenshotTasks); Assert.True(ScreenshotHelper.PixelMatch("screenshot-element-padding-border.png", screenshotTasks.ElementAt(2).Result)); }
private IEnumerator ExportLayers <T>(List <T> layers, ScreenshotHelper screenshot, Progress progress, string exportPath) where T : PatchMapLayer { // Export each individual layer int size = layers.Count; for (int i = 0; i < size; ++i) { string name = layers[i].name; if (layers[i].PatchData.patch != null) { name = layers[i].PatchData.patch.DataLayer.Name; } if (!progress.Update("Exporting layer (" + (i + 1) + "/" + size + "): " + name + " ...")) { yield break; } layers[i].Show(true); var filename = exportPath + name + "_" + imgSize.ToString() + ".png"; yield return(screenshot.TakeScreenshot(filename, exportWidth, exportHeight, false)); layers[i].Show(false); } }
void Update() { if (Input.GetKeyDown(KeyCode.S)) { TakeScreenshot(); } if (Input.GetKeyDown(KeyCode.F)) { ScreenshotHelper.iCaptureScreen((texture2D) => { // Clear the old texture if exist. if (m_CubeMeshRenderer.material.mainTexture != null) { Texture.Destroy(m_CubeMeshRenderer.material.mainTexture); } // Set the new (captured) screenshot texture to the cube renderer. m_CubeMeshRenderer.material.mainTexture = texture2D; string savePath = new FilePathName().SaveTextureAs(texture2D); Debug.Log("Result - Texture resolution: " + texture2D.width + " x " + texture2D.height + "\nSaved at: " + savePath); }); } }
public async Task ShouldAllowMockingBinaryResponses() { await Page.SetRequestInterceptionAsync(true); Page.Request += async(sender, e) => { var imageData = File.ReadAllBytes("./Assets/pptr.png"); await e.Request.RespondAsync(new ResponseData { ContentType = "image/png", BodyData = imageData }); }; await Page.EvaluateFunctionAsync(@"PREFIX => { const img = document.createElement('img'); img.src = PREFIX + '/does-not-exist.png'; document.body.appendChild(img); return new Promise(fulfill => img.onload = fulfill); }", TestConstants.ServerUrl); var img = await Page.QuerySelectorAsync("img"); Assert.True(ScreenshotHelper.PixelMatch("mock-binary-response.png", await img.ScreenshotDataAsync())); }
public static bool Snip() { FindMultiScreenSize(); Bitmap bmp = null; try { bmp = new Bitmap(snipBounds.MaxRight - snipBounds.MinX, snipBounds.MaxBottom - snipBounds.MinY, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); } catch (Exception e) { } Graphics gr = Graphics.FromImage(bmp); Graph = gr; gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; BitmapSize = bmp.Size; using (var snipper = new SnippingTool(bmp)) { snipper.Location = new Point(snipBounds.MinX, snipBounds.MinY); if (snipper.ShowDialog() == DialogResult.OK) { ScreenshotHelper.SaveScreenshotToCache(snipper.Image); return(true); } } return(false); }
private void GetScreenshot(object sender, WaitWindowEventArgs e) { DirectoryInfo directory = new DirectoryInfo(Constants.CacheLocation); FileSystemInfo[] files = directory.GetFileSystemInfos(); ScreenshotHelper.CombineScreenshot(files, e); }
public async Task ShouldCaptureFullElementWhenLargerThanViewport() { await Page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); await Page.SetContentAsync(@" something above <style> div.to-screenshot { border: 1px solid blue; width: 600px; height: 600px; margin-left: 50px; } ::-webkit-scrollbar{ display: none; } </style> <div class='to-screenshot'></div>" ); var elementHandle = await Page.QuerySelectorAsync("div.to-screenshot"); var screenshot = await elementHandle.ScreenshotDataAsync(); Assert.True(ScreenshotHelper.PixelMatch("screenshot-element-larger-than-viewport.png", screenshot)); Assert.Equal(JToken.FromObject(new { w = 500, h = 500 }), await Page.EvaluateExpressionAsync("({ w: window.innerWidth, h: window.innerHeight })")); }
public async Task ShouldTakeIntoAccountPaddingAndBorder() { await Page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); await Page.SetContentAsync(@" something above <style> div { border: 2px solid blue; background: green; width: 50px; height: 50px; } </style> <div></div> "); var elementHandle = await Page.QuerySelectorAsync("div"); var screenshot = await elementHandle.ScreenshotDataAsync(); Assert.True(ScreenshotHelper.PixelMatch("screenshot-element-padding-border.png", screenshot)); }
public async Task ShouldScrollElementIntoView() { await Page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); await Page.SetContentAsync(@" something above <style> div.above { border: 2px solid blue; background: red; height: 1500px; } div.to-screenshot { border: 2px solid blue; background: green; width: 50px; height: 50px; } </style> <div class='above'></div> <div class='to-screenshot'></div> "); var elementHandle = await Page.QuerySelectorAsync("div.to-screenshot"); var screenshot = await elementHandle.ScreenshotDataAsync(); Assert.True(ScreenshotHelper.PixelMatch("screenshot-element-scrolled-into-view.png", screenshot)); }
public void downloadCSV() { driver.FindElement(By.CssSelector("img[alt='Download as Spreadsheet (.csv)']")).Click(); Thread.Sleep(6000); ScreenshotHelper.TakeScreenshotReport(driver); Thread.Sleep(1000); }
//Funcional public HomeLogadaPage Logar(string email, string senha, TestContext test) { txtEmail.SendKeys(email); txtSenha.SendKeys(senha); test.AddResultFile(ScreenshotHelper.TiraPrint("Campos Preenchidos", driver)); btnSignIn.Click(); return(new HomeLogadaPage(driver)); }
public void TakeScreenshotTest() { Driver.Url = "https://www.google.com"; var name = $"screenshot-{DateTime.Now.Second}"; ScreenshotHelper.TakeScreenshot(Driver, screenshotFileName: name); Assert.IsTrue(File.Exists($"C:\\Users\\james\\Desktop\\Screenshots\\{name}.png"), "The screenshot doesn't exist in the specified file location."); }