0
votes

How do I write the following tests which is written in Watin using CodedUI

I am trying to learn CodedUI but really struggling

[Test]

public void SearchForWatiNOnGoogle()

{

using (var browser = new IE("http://www.google.com"))

 {

   browser.TextField(Find.ByName("q")).TypeText("WatiN");

   browser.Button(Find.ByName("btnG")).Click();

  Assert.IsTrue(browser.ContainsText("WatiN"));

 }
}
2

2 Answers

0
votes

You might find a bit of help from one of these links: http://blogs.msdn.com/b/gautamg/archive/2009/12/18/why-is-coded-ui-test-generated-code-not-a-straight-line-code.aspx - this is a blog post on MSDN that talks about the code generated by recording a test. It has a sample project attached you might consider looking at.

As I said in your other question, the best way is to create recordings. There is a nice little walkthrough also on MSDN, here: http://msdn.microsoft.com/en-us/library/ff977233.aspx. This one shows you the process of recording a test and generating and maintaining the code for it.

I would strongly encourage you to thoroughly read those two articles.

0
votes

WatiN and the Visual Studio Coded UI tests are different. 'Coded UI tests' refer to Visual Studio's own UI testing tools. WatiN is a different test framework.

Personally, I don't like WatiN because it takes a long time to write tests and it does not playback tests reliably (at least from my experience). The Visual Studio Coded UI tests I prefer more because they provide a test recorder which auto-generates the test code and a a graphical test editor, while still giving you the flexibility to edit the test code yourself.

I have found more success with Visual Studio coded UI tests. The best thing you can do to get started with creating tests using VS Coded UI tests is to read the MSDN documentation, particularly be sure to read the 'Anatomy of a Coded UI Test' to get a hang for the generated code. Read each article in the documentation as it goes through the whole process, from recording tests to editing, maintaining them and best practices.

Also, make sure you have downloaded Visual Studio Feature Pack 2 to be able to use the graphical test editor which is useful when creating and editing tests.

The really off-putting thing about WatiN (apart from its unreliability) is that it doesn't really have a proper documentation, so it can be difficult to know how to handle elements. It's my opinion that you should ditch WatiN, and go with the Visual Studio coded UI tests, if they are available to you. The great thing about the Visual Studio coded UI tests is that it can deal with minor changes to the UI and automatically adapts. WatiN can do no such thing.