WhiteSharp

UI test automation library designed to simplify automated test writing and reading.


Writing tests with WiteSharp and ScreenObjects

Lets consider testing the sample application (you can get it here) For example we will take a simple scenario:

To make the code reusable we will use ScreenObjects pattern.
We will wrap every window with controls into objects and use it's methods to interact with controls from the test. Screen object will look like this:
	  
public class MainWindowTab1
{
  private static MainWindowTab1 _instance;

  private Window _window;
  private Control _combobox;
	
  private MainWindowTab1()
  {
  	_window = new Window("MainWindow");
	_combobox = _window.FindControl("AComboBox");
  }

  public static MainWindowTab1 Instance
  {
	get { return _instance ?? 
	  (_instance = new MainWindowTab1()); }
  }
  
  public MainWindowTab1 SelectItemFromCombobox(string item)
  {
    _combobox.SelectItem(item);
	return this;
  }
}
		  
And resulting test is pretty simple:

[Test]
public void SampleTest()
{
  MainWindowTab1.Instance
	//Tab 1
	.SelectItemFromCombobox("Test4")
	.SetItem1CheckboxState(ToggleState.On)
	.SetItem2CheckboxState(ToggleState.On)
	.SetItem1CheckboxState(ToggleState.Off)
	.OpenSecondTab()
	//Tab 2
	.SetTextToMultilineTextbox("some text")
	.SelectRadiobuttonState();
}
		
You can seen full code in SampleTests project inside the solution or here.


Project maintained by ilya-murzinov Hosted on GitHub Pages — Theme by mattgraham