Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Quickest Automation of web by code UI (A microsoft Utility)

0.00/5 (No votes)
30 Nov 2015 1  

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 

/// <summary>

/// SignUpGmail - Use 'SignUpGmailParams' to pass parameters into this method.

/// </summary>

  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

     // Press keyboard shortcut keys 'Windows + R'

      Keyboard.SendKeys(this.SignUpGmailParams.SendKeys, ModifierKeys.Windows);

      // Select 'chrome.exe' in 'Open:' combo box

      uIOpenComboBox.EditableItem = this.SignUpGmailParams.UIOpenComboBoxEditableItem;

      // Type '{Enter}' in 'Open:' text box

      Keyboard.SendKeys(uIOpenEdit, this.SignUpGmailParams.UIOpenEditSendKeys, ModifierKeys.None);

      // Type 'gmail{Right}{Enter}' in 'Address and search bar' text box

      Keyboard.SendKeys(uIAddressandsearchbarEdit, this.SignUpGmailParams.UIAddressandsearchbarEditSendKeys, ModifierKeys.None);

      // Click 'Chrome Legacy Window' client

      Mouse.Click(uIChromeLegacyWindowClient, new Point(1320, 37));

      // Click 'Chrome Legacy Window' client

      Mouse.Click(uIChromeLegacyWindowClient, new Point(1320, 37));

      // Click 'Chrome Legacy Window' client

      Mouse.Click(uIChromeLegacyWindowClient, new Point(1315, 22));

      // Click 'Chrome Legacy Window' client

      Mouse.Click(uIChromeLegacyWindowClient, new Point(1088, 480));

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(670, 540));

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(673, 475));

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(865, 51));

      // Type 'kumar{Tab}singh{Tab}kumar123{Tab}' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(856, 121));

      // Type '.singh' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys1, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(923, 176));

      // Move 'Chrome Legacy Window' document from (975, 118) to (734, 118)

      Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(975, 118));

      Mouse.StopDragging(uIChromeLegacyWindowDocument, -241, 0);

      // Type 'kumar5555' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys2, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(881, 180));

      // Move 'Chrome Legacy Window' document from (951, 110) to (761, 103)

      Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(951, 110));

      Mouse.StopDragging(uIChromeLegacyWindowDocument, -190, -7);

      // Type 'kamaljeet2222' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys3, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(843, 182));

      // Move 'Chrome Legacy Window' document from (942, 106) to (898, 106)

      Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(942, 106));

      Mouse.StopDragging(uIChromeLegacyWindowDocument, -44, 0);

      // Move 'Chrome Legacy Window' document from (925, 123) to (627, 120)

      Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(925, 123));

      Mouse.StopDragging(uIChromeLegacyWindowDocument, -298, -3);

      // Type 'ks2323' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys4, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(867, 183));

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(924, 113));

      // Type '33' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys5, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(884, 184));

      // Type 'kumar{LShiftKey}@123{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}diwali{LShiftKey}@123' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys6, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(871, 259));

      // Type 'diwali{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}{Back}diwali{LShiftKey}@123' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys7, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(892, 223));

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(866, 274));

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(1001, 222));

      // Type '2' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys8, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(1053, 217));

      // Type '1982' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys9, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(920, 189));

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(891, 220));

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(918, 160));

      // Move 'Chrome Legacy Window' document from (885, 161) to (1365, 105)

      Mouse.StartDragging(uIChromeLegacyWindowDocument, new Point(885, 161));

      Mouse.StopDragging(uIChromeLegacyWindowDocument, 480, -56);

      // Type '{Delete}1212121212' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys11, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(1034, 226));

      // Type 'gaurav2522321{LShiftKey}@gmail.com' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys12, ModifierKeys.None);

      // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(846, 322));

      // Type '123' in 'Chrome Legacy Window' document

      Keyboard.SendKeys(uIChromeLegacyWindowDocument, this.SignUpGmailParams.UIChromeLegacyWindowDocumentSendKeys13, ModifierKeys.None);

     // Click 'Chrome Legacy Window' document

      Mouse.Click(uIChromeLegacyWindowDocument, new Point(893, 16));

      // Click 'Close' button

      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 !

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here