Thursday, June 21, 2012

Creating and Writing Text in Text File


/// <summary>
/// Creating Text File
/// Writing in Text file
/// </summary>
public void CreatingTextFile()
{
string filename = "test1.txt";
string text = " this text should be written in file";
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(text);
}

}

Wednesday, June 20, 2012

Best Practices for Coded UI Tests

  • Use the Coded UI Test Builder whenever possible.
  • Do not modify the UIMap.designer.cs file directly. If you do this, the changes to the file will be overwritten.
  • If you want to change some recorded code, add it in UIMap.cs and update the code and change the function name.
  • Each recorded method should act on a single page, form, or dialog box. Create a new test method for each new page, form, or dialog box.
  • When you create a method, use a meaningful method name instead of the default name. A meaningful name helps identify the purpose of the method.
  • When possible, limit each recorded method to fewer than 10 actions. This modular approach makes it easier to replace a method if the UI changes.
  • Create each assertion using the Coded UI Test Builder, which automatically adds an assertion method to the UIMap.Designer.cs file.
  • If the user interface (UI) changes, re-record the test methods, or the assertion methods, or re-record the affected sections of an existing test method.
  • Create a separate UIMap file for each module in your application under test. 
  • If you are creating assertions by coding with the API, create a method for each assertion in the part of the UIMap class that is in the UIMap.cs file. Call this method from your test method to execute the assertion.


Thursday, May 31, 2012

Finding Word present in Text File


/// <summary>
/// Finding word present in Text File
/// </summary>
public void SearchingwordinTextfile()
{
string fpath = "VSTSsite.txt";
string line;


using (StreamReader file = new StreamReader(fpath))
{
//// read full text file
line = file.ReadToEnd();
if (line.Contains("msd"))
{
Console.WriteLine("word 2 is present in file");
}
}
}

Wednesday, April 11, 2012

Adding UI controls to UIMap for hand coding


Drag the cross-hair from Coded UI Test Builder and drop it on a control to see its properties. It will highlight the selected control. Now click on button Add Control to UI Control Map from Add Assertion window.

We can use [win+I] for highlighting the control if control is getting disappear while selecting the cross-hair from Coded UI Test Builder.

In VSTS 2012 [Win+I] is changed to [Ctrl+I].

Shortcut key for Add Control to UI Map is [Alt+C].

No Need to give any method name if we are adding just control to UI Map.