Collaborative Coded UI tests - c#

I have a question about Coded UI and how to best use it together with others. We are a team(of 3) who are testing a large web application(which is hard by itself) but we also want to make all the tests in one solution and share that solution through GIT(or TFS). What is the best way of doing this?
We have tried a few things already. We tried using the default UI map, but this creates a lot of merge conflicts and the UI map class becomes long and hard to understand.
We also tried using different UI maps for every page on the site. This seemed like a good idea since we all could test different parts of the website. The problem with this was that once you created one UI map and mapped the content of that page, you could not go back to mapping against that UI map again. So if we had mapped one page and then written a few tests and then some functionality was added, we could not go back to map this. If we created a new test and mapped through this test, this mapping was added to the default UI test. I think this method would work if we could just change which UI map the code would be added to for a new test.
Any reply would be appreciated!

To record and add new methods and controls into a UI Map other than the default, right-click on the UI Map's .uitest file in solution explorer and select the "Edit with Coded UI test builder" menu entry. By contrast, if you right-click in a method within the test sources and select the "Generate code for Coded UI test" menu entry then it will write to the default UI Map; creating it without warning if it does not exist. See also this Visual Studio user voice entry http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3378897-choosing-the-uimap-when-recording-tests

I am sure you`ve read this one: http://msdn.microsoft.com/en-us/library/ff398056.aspx
In case of my app with similar issues we`ve got rid off UI Maps and hand code everything, wrap it in methods and make is as reusable as possible.

Related

Creating a Coded UI map manually without recorder

I'm trying to find a way to create an Object Repository without using the recording function. What I would like to do is create individual "pages" for each window of my WPF app (page object pattern for those who are familiar with WebDriver).
I want to avoid all the extra stuff coded UI records and adds to the project. All I would like is a simple class that maps to all of the controls I want, and then use that class in my tests.
Is that possible with Coded UI, if so , how?
Thanks for your help.
There is a framework (set of helper classes) in codeplex that does exactly what you want but for websites. Since it is open source I imagine that it would not be too hard to adapt it for a WPF application. You can find all the details at:
http://codeduicodefirst.codeplex.com/

Workflow with C# in Visual Studio

I normally code with PHP, I am used to opening up my editor of choice and going away at it, coding classes,methods, etc. It is fairly easy as there is no GUI to worry about.
Last night I spent the whole night following a couple tutorials with C# in Visual Studio, it's turning out to be harder then I thought it would be. Once thing that I am not use to is, all the tutorials have you add a form object like a text box or button, then have you double clikc it to get to the code part, you then enter some code for that method. Then back to the form and re-peat
This seems very hard as you are never really working on "just the code" so 1 question is, is it always like that or just because i'm new and following tutorials?
Another question, when I see source code online to do certain functions, say I see a class I would like to try using, how can I use that class in the existing form class created by VS, do you somehow import other classes or do you add them right to the form code you are working on?
I'm sure that didn't make much sense but hopefully it does to someone, i'll try wording it better if not.
I should add that this was with WPF, also I feel like you have to learn 2 languages, the C# which has very similar syntax to PHP so that doesn't seem too difficult and the for GUI that's like a whole diff language
You can download the classes you are interested into.
Then you go to the Solution Explorer panel and you add existing items.
This will COPY the files to your project.
In order to use those classes you need to declare that you wan to use them.
So, what you have to do is to say something like
using FooNamespace;
Then you are ready to use the classes.
The name space is declared right before any class. You can go edit it.
Now about the forms. Each form is a Class and it consists of three files
ClassForm.cs
ClassForm.designer.cs
ClassForm.resx
You ONLY need the first one. Right click and view code. You can go there and use it.
Many questions, Many answers
Difficulty and Repetition
you can add form objects via the designer or you can hit the source button (CTRL-PgDn). From there you can edit elements in asp and html just like any php IDE. I do most of the work in source. I am a real programmer so I can never do the drag and drop. With intelligence and time you learn the properties and what to do.
to make complex pages you just have to know what you are doing.
What I started with VS I had the same feelings as you, but i have gotten into the flow of it.
As far as the code behind, you are just hooking methods up to the asp elements that get called by the built in code. You can add your own classes, functions, everything in the code behind or in separate files, just like c++, php, whatever.
Hope that helps, VS is really powerful and runs smooth when you learn where things are, been using it for years now and I'm still learning. Bottom line, never use drag and drop and just play with it.
unfortunately the .net world love drag-drop controls. so most tutorials are designed around this concept. drag a textbox on the to form. drag a button onto the form. double click button image to get the click handler.
it's not needed, it's just the approach for most people using visual studio. being that this is a WPF project everything can be done from code, or xaml markup. you don't need the WYSIWYG editor.
as for adding/referencing classes first you need to reference the assembly the class is located in. your core .net types (part of the BCL, base class library) are automatically included as references. then you add a using statement to the appropriate namespace. then you can instantiate the object.
There are ways to have a C# interactive window; see this question. Alternatively, you don't need to use a form, but you could also create a command-line application.
As for the second question, you can add a new class to your project and then use it in your form. There's really no additional step, except that if the namespaces are different, then it is easier if you import that namespace (via using).
Partly, yes, because you're new and using tutorials.
Partly, no, because you're working with forms, and you really don't want to hand-code those by hand.
If you just want to play with C#, and not concern yourself with forms and display, look for information on Console application. Instead of worrying about buttons and textboxes, your worst nightmare will be Console.WriteLine();
Here are some console-based C# tutorials:
C# Station tutorial
C# Yellow Book - it's a PDF. It's good.
Yes, it is exactly because you are following the video tutorials which are almost always tailored for beginners... Most of us making a living working in VS, developing WPF solutions do not even use the visual editor but instead work directly with XAML to build our UI and have very little or no code in the code behind files following the MVVM pattern.
To answer your second question, most of your classes that "do stuff" which is not directly intertwined with the UI should be in a separate class library (dll file) and should not even be referenced directly by your main UI project (in order to facilitate loose coupling) but instead accessed using some form of Dependency Injection, typically utilizing Interfaces.
The code that responds to user interaction should be in your ViewModel classess which are typically a data context for your views and these VM classes are typically using service agents which implement different Interfaces in order to use code stored in the class libraries mentioned in the previous paragraph.
Now, it is possible to just double click on a button and write all your code in that method created for you in the code behind file just like with Winforms, but just like in the Winforms world that leads to code that is hard to maintain, that is tightly coupled to your user interface and very difficult to test so try to resist that instant gratification and invest some time in learning the MVVM pattern, DI and OO design patterns which facilitate code reuse, decoupling and testability...
Hope this helps...
It really depends on what you are trying to learn. I don't think I would start off with WPF if I was using C#. I would start off with a console application to get the basics of the language down, then move down to a simple WinForms application, and finally to WPF where you started.
But yes, your questions about how the editor works is correct. It's how that platform works.

Handle navigation between several view in a WPF application

I've done several WPF application(not using MVVM) in the past and I had always to implement my own system of navigation between view(instantiate the view once, and then load in a container component, with refreshing required components of my view).
It works, but:
It's always custom, so if a new developer comes he has to learn of it how it works
I'm pretty sure that It's not the most optimized(most of things haven't been done in background worker, ...)
It's a time loss
So I was wondering if there is an official way to handle this ? I don't exactly how, but I was thinking to a navigation component, which can act a little like a tab panel, or a little like the MVC framework in asp.net, we can call a specified controller for an action and some parameters.
Maybe deactiviting bindings when they aren't in the current view
You can use DataTemplates/Styles to customize content of your control ( not only apearance, but data, cause that what you're asking for I presume)
http://msdn.microsoft.com/en-us/library/ms742521.aspx
You can have one Host control and at runtime change its appearance based on events/ states.
Like an example can have a look here:
http://code.google.com/p/svnradar/ how this program manages a appearance of Group and Flat view of repository information.
Another example:
Podder of Josh Smith
http://joshsmithonwpf.wordpress.com/2008/03/05/podder-v2-has-been-released/
Hope this helps.
You may be interested by Lakana, a lightweight (but powerful) framework that can handle for you all the navigation concerns !
Riana

Guidelines for using the ASP.NET Wizard efficiently

A web app our group has put together uses the ASP.NET Wizard control. Each step in the wizard contains a corresponding custom UserControl.
The trouble is that as you go through the wizard steps, all the UserControls are loaded on each step, rather than just the one used in that step. That doesn't seem right to me.
So...is there anybody here that's done a lot of work with the Wizard control and can give some guidelines on how to use it correctly, and keep it from loading way too much junk with each step?
One thing that could help you a bit is not putting any code in your UserControls's Page_Load function but instead putting that same code in it's Page_PreRender. That's crucial when using a MultiView and probably applies to the wizard as well.
mspmsp has a good recommendation about PreRender, another option that I have noticed used before is to simply move all configuration code inside the control to a ConfigureControl method.
Then when switching views, you can call the ConfigureControl() method to explicitly create/load your control. It has the same purpose, but it helps make the code a bit easier to understand in my opinion.
FYI, (at least part of) the reason it loads all user controls on each step is so that you can access the values entered on other steps. If it didn't load the controls, you couldn't easily make decisions about the current step based on what was entered in a previous step (e.g. filtering a list based on a selection in a previous step).

Programmatically start UserControlTestContainer.exe

I implemented a C# user control and succesfully tested it with the UserControlTestContainer.exe by manually interacting with it. Now I would like to programmatically, instead of manually, feed data into the control, through my unit tests and then automatically display the control filled with that data. I guess I need to create an instance of the control, fill it up and then programatically start the container with the control as parameter, don't I? How do I succeed displaying my filled control? The solution doesn't have to involve the above mentioned container of course, any other suggestion to get the work done would be very appreciated.
I just created an other "Unit Test" project doing all UserControlTestContainer work. UserControlTestContainer is started through the external application option on the project's properties.

Categories

Resources