Friday, 11 July 2014

How to debug an Cassini hosted website and the UnitTest that uses WatiN to automate that hosted website

One of the cool new capabilities that I'm using when writing QA Automation scripts for the latest version of TeamMentor, is the which allows the execution of an an 'in memory' version of Cassini (hosting the full TeamMentor website) in the same process as the Unit Test driving the IE automation of the hosted website (using FluentSharp.WatiN)

In practice, what this means is that the UnitTests are being executed in the same process as the main TeamMentor Website. This something that I have been wanting to have for ages, and the key capability I gained from it was the ability to debug both live website and UnitTest in the same session.

Lets set it in action.

1) Unit test that triggers the workflow

2) In this case I'm executing the UnitTest using Resharper (vs nCrunch)

3) The UnitTest starts with the creation of an NUnitTests_Cassini_TeamMentor object

4) ... and the invocation of its start method

5) which will check that we have found the root of TeamMentor website, create a new API_Cassini object ...

6) ... and invoke its start command (which will start Cassini server on a local non-used port)

7) Back in the UnitTest, a new popupWindow is created (i.e. a WinForms Form with title 'test' and with an Embedded Watin_IE object inside it) and the root of the cassini web is opened (which in this case it the root of TeamMentor)

8) At the moment the IE browser window doesn't show anything ...

9) ... because a breakpoint I added to the core TeamMentor Code base has just been triggered (this is the part that until now I was never able to do)

10) For example here is a callback received from the Global.asax Application_Start:

11) Once I stop stepping thought TeamMentor, the website load continues on the Cassini's AppDomain, and the next breakpoint on the UnitTest is triggered (in the case below, on the line that will open a FluentSharp.REPL script editor for the IE object)

12) Here is a screenshot of what is created by the line shown above:
  • a real-time scripting environment for the IE object (currently showing the TeamMentor homepage)
  • note how the return ie.links(); script shows (in the Output window) a list with all links that exist on the current page (see this page for more examples of IE Automation methods)

See the Using WatiN and Embedded Cassini to run complex TeamMentor Automation (Create and Delete an Library) post for a good example of the type of scripts that can be developed and executed in this REPL environment

This is a really powerful development and QA environment, since I am now (finally) able to write quite complex QA workflows, using WatiN to drive the automation, and with the main website running directly in the same process (which as you can see above, allows the easy debugging of both Website and UnitTest codebases).

One thing that is missing (but I think I know how to do it), is to be able to run asserts directly on the Cassini AppDomain (and have direct programatically access to the TM objects that exist inside that AppDomain).
Post a Comment