Best FlaUI code snippet using FlaUI.Core.Capturing.InfoOverlay.Draw
InfoOverlay.cs
Source: InfoOverlay.cs
1using System;2using System.Drawing;3using System.Text.RegularExpressions;4using FlaUI.Core.Tools;5namespace FlaUI.Core.Capturing6{7 /// <summary>8 /// Overlay with various information about the system.9 /// </summary>10 public class InfoOverlay : OverlayBase11 {12 /// <summary>13 /// Creates a <see cref="InfoOverlay"/> object for the current captured image.14 /// </summary>15 /// <param name="captureImage">The captured image.</param>16 /// <returns>The created object.</returns>17 public InfoOverlay(CaptureImage captureImage) : base(captureImage)18 {19 }20 /// <summary>21 /// The string to use for the overlay. Has some variables which are automatically replaced.22 /// The variables are:23 /// - dt: The current systems datetime, can additionally be followed with a .net format string.24 /// - rt: The timespan since the recording started See also <see cref="RecordTimeSpan"/>.25 /// - name: The machine name of the current system.26 /// - cpu: The cpu usage.27 /// - mem.p.tot: The physical total memory.28 /// - mem.p.free: The physical free memory.29 /// - mem.p.used: The physical used memory.30 /// - mem.p.free.perc: The physical free memory in percent.31 /// - mem.p.used.perc: The physical used memory in percent.32 /// - mem.v.tot: The virtual total memory.33 /// - mem.v.free: The virtual free memory.34 /// - mem.v.used: The virtual used memory.35 /// - mem.v.free.perc: The virtual free memory in percent.36 /// - mem.v.used.perc: The virtual used memory in percent.37 /// </summary>38 public string OverlayStringFormat { get; set; } = "{dt:yyyy-MM-dd HH:mm:ss.fff} / {name} / CPU: {cpu} / RAM: {mem.p.used}/{mem.p.tot} ({mem.p.used.perc})";39 /// <summary>40 /// The position of the overlay.41 /// </summary>42 public InfoOverlayPosition OverlayPosition { get; set; } = InfoOverlayPosition.TopLeft;43 /// <summary>44 /// The color of the overlay background (can also have an alpha for semi transparent).45 /// </summary>46 public Color OverlayBackgroundColor { get; set; } = Color.FromArgb(100, Color.Black);47 /// <summary>48 /// The color of the overlay text.49 /// </summary>50 public Color OverlayTextColor { get; set; } = Color.White;51 /// <summary>52 /// The font of the overlay text.53 /// </summary>54 public Font OverlayTextFont { get; set; } = new Font("Consolas", 10f);55 /// <summary>56 /// The timespan for the recorded time.57 /// </summary>58 public TimeSpan RecordTimeSpan { get; set; } = TimeSpan.Zero;59 /// <inheritdoc />60 public override void Draw(Graphics g)61 {62 const int textOffsetToBg = 2;63 var overlayString = FormatOverlayString(OverlayStringFormat);64 var font = OverlayTextFont;65 var bgBrush = new SolidBrush(OverlayBackgroundColor);66 var fontBrush = new SolidBrush(OverlayTextColor);67 var textSize = g.MeasureString(overlayString, font);68 // Calculate background size and position69 var bgHeight = textSize.Height + 2 * textOffsetToBg;70 var bgWidth = CaptureImage.OriginalBounds.Width;71 var bgPosX = 0;72 var bgPosY = IsPositionTop() ? 0 : CaptureImage.OriginalBounds.Height - bgHeight;73 // Calculate text position74 var textPosY = bgPosY + textOffsetToBg;75 float textPosX = textOffsetToBg;76 if (IsPositionRight())77 {78 textPosX = bgWidth - textSize.Width - textOffsetToBg;79 }80 else if (IsPositionCenter())81 {82 textPosX = bgWidth / 2 - textSize.Width / 2 - textOffsetToBg / 2;83 }84 // Draw the background85 g.FillRectangle(bgBrush, bgPosX, bgPosY, bgWidth, bgHeight);86 // Draw the text87 g.DrawString(overlayString, font, fontBrush, textPosX, textPosY);88 }89 private string FormatOverlayString(string overlayString)90 {91 SystemInfo.RefreshAll();92 // Replace the simple values93 overlayString = overlayString94 .Replace("{name}", $"{Environment.MachineName}")95 .Replace("{cpu}", $"{SystemInfo.CpuUsage,5:##.00}%")96 .Replace("{mem.p.tot}", $"{StringFormatter.SizeSuffix(SystemInfo.PhysicalMemoryTotal, 2),7}")97 .Replace("{mem.p.free}", $"{StringFormatter.SizeSuffix(SystemInfo.PhysicalMemoryFree, 2),7}")98 .Replace("{mem.p.used}", $"{StringFormatter.SizeSuffix(SystemInfo.PhysicalMemoryUsed, 2),7}")99 .Replace("{mem.p.free.perc}", $"{SystemInfo.PhysicalMemoryFreePercent,5:##.00}%")100 .Replace("{mem.p.used.perc}", $"{SystemInfo.PhysicalMemoryUsedPercent,5:##.00}%")101 .Replace("{mem.v.tot}", $"{StringFormatter.SizeSuffix(SystemInfo.VirtualMemoryTotal, 2),7}")...
Draw
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using FlaUI.Core;7using FlaUI.Core.Capturing;8using FlaUI.Core.Capturing.ImageFormats;9using FlaUI.Core.Definitions;10using FlaUI.Core.Tools;11using FlaUI.UIA3;12using System.Drawing;13{14 {15 static void Main(string[] args)16 {17 var app = FlaUI.Core.Application.Launch("notepad.exe");18 var automation = new UIA3Automation();19 var window = app.GetMainWindow(automation);20 window.SetForeground();
Check out the latest blogs from LambdaTest on this topic:
Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
Sometimes, in our test code, we need to handle actions that apparently could not be done automatically. For example, some mouse actions such as context click, double click, drag and drop, mouse movements, and some special key down and key up actions. These specific actions could be crucial depending on the project context.
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!