Select Page
Test Automation

White Framework Cheat Sheet

In this blog article, we would like to share useful White framework methods with examples.

White Framework Cheat Sheet

Everyone is aware of automating rich client applications using White framework. As a software testing service provider, sharing our experience and knowledge is one of the success factors for Codoid. In this blog article, we would like to share useful White framework methods with examples.

Launch an Application
Application application = Application.Launch("C:\Windows\System32\calc.exe");
  
Attaching an existing Application
//Attach by process id
Application application=Application.Attach(10628);

//Attach by process name
 Application application = Application.Attach("calc");
  
Attach or Launch
//Attaches to the process, if it is running or launches a new process
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "calc.exe";
Application application = Application.AttachOrLaunch(startInfo);
  
Get Windows
//Get Window by title
 Window window =application.GetWindow("Calculator");

//Search a window with criteria
Window window = application.GetWindow(SearchCriteria.ByText("Testing services Companies"), TestStack.White.Factory.InitializeOption.NoCache);

//Returns a list of all main windows in belonging to an application. It doesn't return modal windows.
List<Window> windows = application.GetWindows(); 
  
Speed up window search performance

You can store window’s position in White-framework cache xml file by providing identification string in GetWindow method. For the very first run, it will store the window position. And for the subsequent executions, it accesses the cache xml and identifies your window quickly. For more details, refer the following link: Speed up performance by Position based search

Application application = Application.Attach("notepad");

Window window =application.GetWindow("Codoid-A Test Automation company - Notepad", TestStack.White.Factory.InitializeOption.NoCache.AndIdentifiedBy("Notepad"));

application.ApplicationSession.Save();
  
Desktop Windows
//Returns a list of all main windows on the desktop. It doesn't return modal windows.
List<Window> windows = Desktop.Instance.Windows();
  
Get Modal windows
//Get list of all the modal windows belong to the window.
List<Window> modalWindows = mainWindow.ModalWindows();

//Get modal window with title
Window childWindow = mainWindow.ModalWindow("child");
  
Get Tool tip
string message = window.ToolTip;
  
Take Screenshot
//Takes a screenshot of the entire desktop, and saves it to disk
Desktop.TakeScreenshot("C:\white-framework.png", System.Drawing.Imaging.ImageFormat.Png);

//Captures a screenshot of the entire desktop, and returns the bitmap
Bitmap bitmap = Desktop.CaptureScreenshot();
  
Button
//Find
 Button button=window.Get<Button>(SearchCriteria.ByText("Calculate"));

//Click
button.Click();

//Double Click
button.DoubleClick();

//Right Click
button.RightClick();
button.RightClickAt(new Point(5, 5));

//Is Enabled
bool isEnabledButton=button.Enabled;

//Take screenshot
Bitmap bitmap = button.VisibleImage;
bitmap.Save("C:\button.png", System.Drawing.Imaging.ImageFormat.Png);
  
ComboBox
ComboBox combobox=window.Get<ComboBox>(SearchCriteria.ByAutomationId("261"));

//Select by index
combobox.Select(1);

//Select by text
combobox.Select("Purchase price");
  
Radiobutton
RadioButton radioButton = window.Get<RadioButton>(SearchCriteria.ByAutomationId("322"));

//Select
radioButton.Select();

//Is selected
bool isSelected = radioButton.IsSelected;
  
Textbox
SearchCriteria searchCriteria = SearchCriteria.ByClassName("TextBox").AndIndex(1);

TextBox textBox = window.Get<TextBox>(searchCriteria);

//Clear and enter text. Use BulkText to set value in textbox for better performance.
textBox.BulkText = "QA Services";

//Click center of text box
textBox.ClickAtCenter();
  
Mouse
 Mouse mouse = Mouse.Instance;

//Click
mouse.Click();

//Click with Point
mouse.Click(textBox.ClickablePoint);

//Right Click
mouse.RightClick(textBox.ClickablePoint);

//Double Click
mouse.DoubleClick(textBox.ClickablePoint);

//Get cursor location
System.Windows.Point location = mouse.Location;
  
Checkbox
CheckBox checkbox = window.Get<CheckBox>(SearchCriteria.ByAutomationId("3213482"));

//Check
checkbox.Select();

//Uncheck
checkbox.UnSelect();

//Is checked
bool isChecked=checkbox.Checked;
  
Menubar
//Menu bar
MenuBar menubar = window.MenuBar;

//Selecting menu items
menubar.MenuItem("Tools", "Change language", "Polski (Polish)").Click();

//Searching and selecting menu items
menubar.MenuItemBy(SearchCriteria.ByText("Tools"), SearchCriteria.ByText("Change language")).Click();
  
Listbox
//Check an item
listBox.Check("QA Consultants");

//Uncheck an item
listBox.UnCheck("Quality Assurance");

//Get all the items
ListItems items = listBox.Items;

//Select an item
listBox.Select("Testing and QA Services");

//Get selected item
ListItem listItem = listBox.SelectedItem;
  
Tree
//Select a node
tree.Node("Codoid", "Services").Select();

//Expand a node
tree.Node("Codoid", "Products").Expand();

//Collapse node
tree.Node("Codoid", "Automation Testing").Collapse();
  
Wait Till using Delegate

Using the below technique, you can make your script to wait until a certain condition matches.


    class Program
    {
        public static TextBox textbox = null;

        static void Main(string[] args)
        {
            
            Application application = Application.Attach("calc");

            Window window = application.GetWindow("Calculator");

            textbox = window.Get<TextBox>(SearchCriteria.ByAutomationId("226"));


            //Waits until the textbox value becomes "123". isTextMatch method user defined method for this condition.
            window.WaitTill(new WaitTillDelegate(isTextMatched));

        }

        static bool isTextMatched()
        {
            bool isMatched = false;

            if (textbox.Text.Equals("123")) { isMatched = true; }

            return isMatched;
        }
    }
  

Comments(0)

Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility