Introduction
Code UI is the quickest way to create test cases ,It can we functional of integration test cases. In different scenario's, when you are going to write unit test case which is basically testing your code and integration basically only include back-end functionality not the whole UI.
Code UI is the “Record and play” approach, Here you can write the whole test cases with UI integration in no time. Here we are going to demonstrate the how we can quickly write the code by using code UI for automating any web portal. This is also useful for cover whole scenario including front end validations
Code UI is available with Microsoft visual studio 2010 Ultimate or Premium version. Here we are going to create a functional test case for web portal so we take google mail sign up functionality automation
Step to create a test scenario
1) Open Visual studio 2010 premium and click on Test in menu bar and add a new test case and choose "Code UI Test" template.Set the name of the project
2) Generate code for coded UI Test pop up select "Record Action, edit UI map or add assertions"
3) A recording panel is visible click on red button to start recording the steps
4) So after click on recording play button you can iterate any functional step after completing the functional step stop the recording button and you can see the steps and you can edit if needed.
5) Now click on generate code button this will prompt you the pop up for function name,after putting the name click on "Add and Generate" button now you can see the automation code with same function name a test case already written for testing the functional step
below is the code which is automated generated by system for sign up a new account in google mail
public void SignUpGmail() {
#region Variable Declarations
WinComboBox uIOpenComboBox = this.UIRunWindow.UIItemWindow.UIOpenComboBox;
WinEdit uIOpenEdit = this.UIRunWindow.UIItemWindow1.UIOpenEdit;
WinEdit uIAddressandsearchbarEdit = this.UINewTabGoogleChromeWindow.UIItemGroup.UIAddressandsearchbarEdit;
WinClient uIChromeLegacyWindowClient = this.UINewTabGoogleChromeWindow.UIChromeLegacyWindowWindow.UIChromeLegacyWindowClient;
WinControl uIChromeLegacyWindowDocument = this.UINewTabGoogleChromeWindow.UIChromeLegacyWindowWindow1.UIChromeLegacyWindowDocument;
WinButton uICloseButton = this.UINewTabGoogleChromeWindow.UIInbox3ks232333gmailcTabPage.UICloseButton;
#endregion
Keyboard.SendKeys(this.SignUpGmailParams.SendKeys, ModifierKeys.Windows);
uIOpenComboBox.EditableItem = this.SignUpGmailParams.UIOpenComboBoxEditableItem;
Keyboard.SendKeys(uIOpenEdit, this.SignUpGmailParams.UIOpenEditSendKeys, ModifierKeys.None);
Keyboard.SendKeys(uIAddressandsearchbarEdit, this.SignUpGmailParams.UIAddressandsearchbarEditSendKeys, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowClient, new Point(1320, 37));
Mouse.Click(uIChromeLegacyWindowClient, new Point(1320, 37));
Mouse.Click(uIChromeLegacyWindowClient, new Point(1315, 22));
Mouse.Click(uIChromeLegacyWindowClient, new Point(1088, 480));
Mouse.Click(uIChromeLegacyWindowDocument, new Point(670, 540));
Mouse.Click(uIChromeLegacyWindowDocument, new Point(673, 475));
Mouse.Click(uIChromeLegacyWindowDocument, new Point(865, 51));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(856, 121));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys1, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(923, 176));
Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(975, 118));
Mouse.StopDragging(uIChromeLegacyWindowDocument, -241, 0);
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys2, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(881, 180));
Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(951, 110));
Mouse.StopDragging(uIChromeLegacyWindowDocument, -190, -7);
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys3, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(843, 182));
Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(942, 106));
Mouse.StopDragging(uIChromeLegacyWindowDocument, -44, 0);
Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(925, 123));
Mouse.StopDragging(uIChromeLegacyWindowDocument, -298, -3);
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys4, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(867, 183));
Mouse.Click(uIChromeLegacyWindowDocument, new Point(924, 113));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys5, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(884, 184));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys6, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(871, 259));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys7, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(892, 223));
Mouse.Click(uIChromeLegacyWindowDocument, new Point(866, 274));
Mouse.Click(uIChromeLegacyWindowDocument, new Point(1001, 222));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys8, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(1053, 217));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys9, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(920, 189));
Mouse.Click(uIChromeLegacyWindowDocument, new Point(891, 220));
Mouse.Click(uIChromeLegacyWindowDocument, new Point(918, 160));
Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(885, 161));
Mouse.StopDragging(uIChromeLegacyWindowDocument, 480, -56);
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys11, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(1034, 226));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys12, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(846, 322));
Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys13, ModifierKeys.None);
Mouse.Click(uIChromeLegacyWindowDocument, new Point(893, 16));
Mouse.Click(uICloseButton, new Point(11, 16));
}
This is very helpful when any developer do not have any code access then he can play the things by using UI. Really its a very fast technique to automate any system with less number of faults and bugs !