Ui Testing with Selenium and Logging it automatically?

Hey /r/csharp, got a question for you.

tl;dr: Done a lot of Unit Tests in MSTest using [TestClass]. Trying to make a detailed cross-browser [CodedUITest] test report using selenium that tracks each action taken (click here, hover over element x, etc). Looking for lessons learned by others. I'm using Selenium, but I'm totally open to changing test frameworks. I just need something that is clean and readable. Does anyone have experience trying to attempt anything like the following?

Backstory: My company is getting big into UI testing for our asp.net apps. We had some contractors develop some ui testing on my project while we were doing new development. The test report came out good, but the code itself is a real mess (talking 10 to 20 asserts in a test that are nested under external methods, that reference other external methods, that have 10 – 20 asserts). It makes me question the validity of the testing. The scary thing is, we're going to have to develop tests based on this for all projects moving forward, unless I can do something better right now.

They hooked into Selenium using the test type [CodedUITest], but the dll's (its not even a NuGet package) they used to do it seems to be unsupported and runs really slow. For some developers, IE is really slow, for others Chrome is really slow. The process just seems buggy to me.

Requirements: They chose [CodedUITest] because they can turn up the logging level and it hooks into the BrowserWindow object. The HtmlControl object/methods seem to automatically log each action (click/hover/navigate mostly) to an html file with screenshots for each action. We're required to capture each action for regulatory purposes. So basically I need to emulate the same:

  • Organize the tests into categories (i.e. Login, Filters, Library, etc)
  • Log each action taken, the result (pass/fail) and a screenshot
  • Create some kind of report (html) that a QA person can basically click through and verify things did things.

Where I'm having Trouble: I've figured out the screenshot stuff (base 64 encoded string). I also figured out how to output the data to a Json file instead of writing the results directly to html (to hopefully trend test data). Making an html report out of that should be pretty trivial. The big hurdle is, how could I automate the logging each action part? The data I'm capturing is only there because I manually added a method to log a step each time an action is taken. I then did a try/catch around the method, pass if it runs, fail with a manual message if it doesn't and rethrow the exception.

Is there a way to automatically log when a selenium action is taken and handle the result? Attaching events of some kind? Could this be done better through a different framework (NUnit, javascript)?

Thanks for the help. Not looking to have it done for me, just looking for some direction.

by mindbullet via /r/csharp

Leave a Reply