0

I'm currently working on a selenium framework model which will be based on C# .net.

One main thing i'd like to know from all the selenium experts is if i should really build the framework in c#.net? Are there any real benefits of building the framework in JAVA over building it in C#.net?

Main ingredients/USP of this framework-

  1. Ease of writing a test. E.g for clicking on a button, the coder has to simply write Dom.find("#elementid").click(), Dom.WaitFor("#elementid") or Dom.WaitTillDisappears("#elementd") Purpose of this is to abstract the whole selenium driver,properties,handling chromedriver, and all the dirty stuff thats too long for a not-so-experienced-coder. For this, i've built an model, using OOPS, defining classes that handle the whole initialisation of chromedriver and the other stuff, so the tester doesn't have to care about it while writing the code.

  2. I'm using unit testing frameworks, such as unit test and defining abstract classes which represent a Test run and a test case, so what a the person writing the code has to do is simply define testcases and write their script under it and run these cases as unit tests.

  3. I've added Db logging which will create logs for each and every action performed, from "trying to find an element" to "typing something in an element", so if anything fails, a person has the ability to study the log and find out what exactly went wrong.

  4. Error handling is done using SeleniumExceptions, and i am overiding the messages to make it more readable for the framework users.

  5. I was thinking of creating a simple abstract class, lets say PageComponents.cs which could be an abstract class and have have basic functions like retrieving page info, getting id,attributes,class,etc. A person preferring creating their scripts in POM can simply define all the components using the By type, so lets say all they have to do is create another class file called LoginPage.cs, inherit from PageComponents.cs and then simply start declaring their objects. In the other files, where users will be writing their script, they can simple access these Page objects by initialising LoginPage. Anything changes, in loginpage, all they have to do is Change properties of objects in LoginPage.cs

Now, the reason i write this whole discussion is to understand the perspective of all the people who are working on selenium or have worked on a framework. I would like to understand all the pros and cons of this framework model i am trying to follow and if there is anything better you guys can suggest(which you have already worked on) that would be great. I'm starting this discussion to understand, what is being followed by other companies and individuals who are far more experienced than i am. Thank you in advance for you valuable feedbacks!

Prateek
  • 627
  • 1
  • 7
  • 19
  • 2
    This would be an interesting discussion, but I don't think that SO is the right place for interesting discussions. – stuXnet Aug 11 '15 at 11:11
  • Hmm have you already tried some behaviour or test-driven-development approaches? You could try Serenity BDD (former thucydides) with JBehave for example where you already have a lot of features implemented you want to implement (page objects, living documentation, handling teststeps etc.) – spcial Aug 11 '15 at 11:24
  • Hey @stuXnet, do you think i should post this somewhere else? would stack exchange be a better place for this discussion. I basically want as much feedback as i can get. – Prateek Aug 11 '15 at 11:36
  • @spcial , thanks for your response. Just wanted to know if Serenity is based on C#.net? – Prateek Aug 11 '15 at 11:37
  • @Prateek I'm using serenity with Java so I can't tell you but maybe there are similar tools for C# (e.g. http://stackoverflow.com/questions/8922079/what-behavior-driven-development-bdd-tooling-frameworks-are-available-for-the ) – spcial Aug 11 '15 at 11:42
  • And yes, i have developed a basic framework around these points using Nunit as a unit testing framework, with DB logging and stuff. It runs well enough, but i wanted some more insight and feedback...there are a few places where there would be some refactoring needed in my framework, but i wanted to know if i am headed in the right direction.. – Prateek Aug 11 '15 at 11:45

1 Answers1

2

Looks like you have done a great job. If you don't have any special reason to move (and re-implement) from C# to JAVA, my advice is not to. IMHO there will be no benefits from this:

of building the framework in JAVA over building it in C#.net

The concepts are pretty much the same, all functionality that you're gonna need can be found to support both target languages.

However I don't see any BDD (for .Net is Specflow). The biggest advantage is that it's a common ground for all team members involved (POs, devs, QAs, BA etc.) and will fit nicely with

not-so-experienced-coder. .... so the tester doesn't have to care about it while writing the code.

The abstraction around the

whole selenium driver,properties,handling chromedriver, and all the dirty stuff thats too long

is a good approach. And maybe you can designed it further with the Test harness main concept - divide your test logic to 3 main areas of single responsibility :

  • Test Engine - will not carry any information about the tested product
  • Test Data - Data driven or generated dynamically
  • Test Specification - consists of test steps, environments variables etc.

Another nice-to-have feature is the image recognition, that will be validating the layout.

Since by nature all UI tests are slow - do you plan to execute your tests in parallel? If yes - this article will be a good place to start. Also an in-memory DB RAM optimization is possible.

The POM is a good practice

I was thinking of creating a simple abstract class, lets say PageComponents.cs which could be an abstract class and have have basic functions like retrieving page info, getting id,attributes,class,etc.

and if you're aiming to continue with the simplicity, then the LoadableComponent is one way to go. It'll give you a good Information hiding, but will hurt the Single responsibility, since it introduces Actions logic (clicks, waits etc.) into your Page objects (presentation is not fully separated from the model). But anyway the design is a matter of trade-offs.

ekostadinov
  • 6,880
  • 3
  • 29
  • 47
  • Thank you for such a detailed feedback,ekostadinov. Really appreciate it. I'll look into BDD, and about Test harness and single responsibility concept- 1. I have created the following classes- SeleniumTest- An abstract class that initiates a test run. This class, simply initiates the webdriver and passes the driver object to different Helper classes' constructors. This can be considered a [TestFixture] in nunit language – Prateek Aug 12 '15 at 11:56
  • SeleniumTestCase- This is an abstract class where the tester, will write their whole script for a particular testcase, or for some particular page. The abstract class has basic functions like logging steps, throwing errors etc, which will be useful while writing a script DomWrapper- This is a class used to define all the methods required to find a particular element in the page using the DOM concept. Things like Find,Waitfor, waittodisappear fit here – Prateek Aug 12 '15 at 11:57
  • DomElement- This is a class type i created for a pagelement, so, any page element is a DomElement. In this type, user has the ability to access element properties like class,id,etc and also use functions like Findchild,click,sendkeys etc. DBOperations- This is the class that has functions to log test cases status and stuff. Basically DB logging of the test cases is handled by this class – Prateek Aug 12 '15 at 11:57
  • Now, about data driven, well, i'm not sure if it will be helpful to build a feature around this in the framework, because this framework can be used to automate any product if a user wants to, we dont know the intent of the user, so thats upto the user, if he wants something to be datadriven, they would have to code their stuff accordingly.... Apart from that, what do you think so far about the whole Test harness and single responsibility concept, do you think i'd following that? – Prateek Aug 12 '15 at 11:57
  • Sorry about the long comment :) – Prateek Aug 12 '15 at 11:58
  • @prateek,like I said the design is a trade off, which should favor your situation and needs. From what I can see here (which is just a fragment) I think you kept the main concepts. Of course, you can put your code to an architectural review here - http://codereview.stackexchange.com/ – ekostadinov Aug 12 '15 at 12:28