Background In my last post I wrote about automating C1Win controls; however, the scope of automation in ComponentOne is not limited only to Windows. In this informative discussion, I would like to talk about automation of Web Controls. C1Web controls can be easily captured by Microsoft CodedUI Tool. As I explained in my last post, automated scripts can be used to ensure the correct output being generated by Win Application every time it is built and the same is applicable for Web Applications. Implementation: Let us take C1ReportViewer with a very simple scenario as an example to showcase the automation using CodedUI Tool. Create and Run a Coded UI Test: Let us begin by creating a web application and adding the Test Project to it. To add a test project to your application, follow these steps: 1) In Solution Explorer, right-click the solution, click Add, and then select New Project. The Add New Project dialog box appears. 2) In the Installed Templates pane, expand either Visual C# or Visual Basic, and then select Test. 3) In the middle pane, select the Test Project template. 4) Click 'Ok'. In Solution Explorer, the new test project named "TestProject1" is added to your solution and either the UnitTest1.cs or UnitTest1.vb file appears in the Code Editor. It is ok to delete UnitTest1 file since we will not be using it. 5) In Solution Explorer, right-click TestProject1, click Add and then select Coded UI test. The Generate Code for Coded UI Test dialog box appears. Here is the image below: To add and create scripts follow the given steps: 1) Select option "Record actions, edit UI map or add assertions option" and click OK. The UIMap - Coded UI Test Builder appears. Below is the image: 2) Click Start Recording on the UIMap - Coded UI Test Builder 3) Launch Internet Explorer. In Internet Explorer's address bar, enter the address of the Web application. -for example: http://localhost:/ Default.aspx 4) Record the action using 'Red Button' and give any method name for recorded steps. You may also look at the sample ("C1ReportViewer.AutomationSample") attached below. It has "C1ReportViewer.TestScripts" added as a "Test Project" to it. Besides, it also has "OpenPrintButton_IE" specific to Internet Explorer and "OpenPrintButton_FF" specific to FireFox added to it. You can have a look at the recorded steps: _BrowserWindow.CurrentBrowser = "IE"; // Mentioning the Browser in which script has to run BrowserWindow win = BrowserWindow.Launch(@"http://localhost:1988/C1ReportViewer.TestSamples/BrowseC1ReportsPage.aspx"); win.Maximized = true; Playback.PlaybackSettings.DelayBetweenActions = 5000; // To incorporate delay time between the steps. this.UIMap.Press_PrintBtn(); // Click Print Button to open "Print" Dialog Box Playback.PlaybackSettings.DelayBetweenActions = 5000;// To incorporate delay time between the steps. this.UIMap.Exist_PrintBtn(); // Put an assertion on Print Button to verify it exist or not i.e; Print Button has opened or not Playback.PlaybackSettings.DelayBetweenActions = 5000;// To incorporate delay time between the steps. ? this.UIMap.Close_PrintDlg();//Close the opened Print Dialog box Playback.PlaybackSettings.DelayBetweenActions = 5000; ? win.Close(); // Closing the browser_ In order to run the scripts,open "Test List Editor" and select the scripts to be run according to your default browser. For example if IE is the default browser in your system then select "OpenPrintButton_IE" and select "Run Checked Test" from the context menu. For a better understanding, look at the image below: Browser Compatibility The scripts written are fuly compatible with IE And FF. Scripts recorded in IE can be very well played in FireFox. However, if you use FireFox to run the scripts you will need an additional plug-in. You can find the additional plug-in here: "http://msdn.microsoft.com/en-us/vstudio/ff655021.aspx". After installation of Microsoft Visual Studio 2010 Feature Pack 2, one must install and configure the Test Helper Extension for Mozilla Firefox. Please follow the insturctions given below for the desired intallation and configuration. Installing the Test Helper Extension for Mozilla Firefox: 1. Verify that all instances of Mozilla Firefox are closed. 2. Run the extension installation tool from the following location: 32 bit machines: %CommonProgramFiles%\microsoft shared\VSTT\10.0\UITestExtensionPackages\ConfigFFExtension.exe. 64 bit machines: %CommonProgramFiles(x86)%\microsoft shared\VSTT\10.0\UITestExtensionPackages\ConfigFFExtension.exe ? After the installation finishes, run Mozilla Firefox and you will be notified about the new extension. Configuration Required MSVS2010 Ultimate, Professional. Important Notes 1) Please do not move mouse while script is running 2) Please add C1NWind.mdb from "C:\Users\stduser\Documents\ComponentOne Samples\Common" to "AppData" folder inside project "C1ReportViewer.TestSamples" or else the report will not be able to render because of incorrect connection strings. 3) Make sure that the attached sample is run on a system where C1Report control is licensed or else the scripts might fail. 4) Please run the sample once before running the scripts. C1ReportViewer.AutomationSample
← Back to all blogs
What's new in the latest releases
For more information, contact Amy Reese at firstname.lastname@example.org.