Skip to content

Crazy blog

No money, no honey, no funny…

Tag Archives: C Sharp

Today, I research about create project test Coded UI on C# (Microsoft Visual Studio Ultimate 2010). The first time, it creates difficult code, and very hard to read. But I found that I can create the test so simple, don’t need generate code test of Microsoft. Please read this post for more detail about the simple Coded UI test automation

1. Create Test Project: File > New Project > C# Test Project
2. Delete file UnitTest1.cs in Solution Explorer
3. From menu, choose Test > New Test
4. Choose Coded UI Test + name the file as: RunGMail.cs
5. Add this library

using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;

6. Add this script to function CodedUITestMethod1():
BrowserWindow browser = BrowserWindow.Launch(new Uri("http://gmail.com"));
HtmlEdit txtUsername = new HtmlEdit(browser);
txtUsername.SearchProperties[HtmlEdit.PropertyNames.Id] = "Email";
txtUsername.Text = "truongkimminh";
HtmlEdit txtPassword = new HtmlEdit(browser);
txtPassword.SearchProperties[HtmlEdit.PropertyNames.Id] = "Passwd";
txtPassword.Text = "your-password";
HtmlInputButton btnLogin = new HtmlInputButton(browser);
btnLogin.TechnologyName = "Web";
btnLogin.SearchProperties.Add(HtmlInputButton.PropertyNames.Name, "signIn");
Mouse.Click(btnLogin);

7. Save and now press F5 to run Test

Tags: ,

1. Open Visual Studio 2010

2. File > New Project > Visual C# > Test > Test Project

3. Delete the UnitTest1.cs file and add a Coded UI Test by right clicking on the Project Name -> Add -> New Test

4. Add new TestMethod, then right click, choose Use Coded UI Test Builder

5. Record your test and then click Generate Code

6. Name your code then click Add and generate button

7. Run the test by placing the cursor in the function, right click in the method and click “Run Tests”

8. Finish

9. Please careful when try to edit UIMap.Designer.cs and UIMap.uitest.

File Description Can this be edited?
GMailTest.cs The default name for the file is CodedUITest1.cs. This is the file in which all the Test Methods are added. YES
UIMap.uitest An XML file has all the information about the recording including actions, objects and data. NO today. In future, we may have editor for this file.
UIMap.Designer.cs This file contains the code generated by the tool based on the recording in UIMap.uitest file (a.k.a. code behind file). NO. Any edits to this will be lost.
UIMap.cs The main class generated by the tool is UIMap. This is partial class and is split into UIMap.Designer.cs  and UIMap.cs. While UIMap.Designer.cs contains code generated by the tool and should not be edited, the UIMap.cs file is the place where you would place all your customization. More on this later. YES

Tags: