views:

677

answers:

4

I run Selenium tests with Selenium RC from .NET (c#).

In some cases, I would like to keep the test case source as HTML (to be able to modify it from Selenium IDE), but I would like to run/include these tests from my c# unit tests.

Maybe it is obvious, but I can't find the API method in the Selenium Core to achieve this. Any idea how to do that?

(I think the "includePartial" command in Selenium on Rails does the thing that I would need, but for c#.)

A: 

I don't think there was a way to do this the last time I used Selenium RC .NET

Jeff Martin
A: 

You can set the format when working in Selenium IDE by going to Options-> Format and then set it to the language of your choice. It means that you can create c# tests without having to convert them as you go. You can still rightclick and choose your command and it will update to c# in the IDE.

I think thats what you are after.

AutomatedTester
A: 

Probably you could parse the xhtml of the test and use .NET reflection to convert it to method calls, but it requires some work from your side

gustavogb
A: 

I have asked this question some time ago, and since then I have moved forward in automated functional testing, more to the BDD/ATDD/Specification by Example direction with SpecFlow.

I only realize it now however that I have implemented a solution for this concrete question during my experiments. I share my solution, maybe can help others.

I have created a small parser and an interpreter for the Selenium html files (you can download it from here: http://bit.ly/ciTMA2). Besides the implementation, these classes add some extension methods to the Selenium's ICommandProcessor interface. Base on that, a test can look like this:

List commands = SeParser.ParseSeFile(@"HomePageTest.html"); selenium.Processor.InterpretCommands(commands); selenium.Processor.AssertNoVerifyErrors();

(The InterpretCommands and the AssertNoVerifyErrors are custom extension methods.)

Gaspar Nagy