Command pattern implementation for testing
-
I'm curently trying to simplify testing in my company by enabling the use of the command pattern. So I need: Command - interfact/abstract class defining public contract for concrete commands ConcreteCommand - and command to use Receiver - class that receives command to execute Invoker - class that invokes the command on the receiver. Ok so this is all standard GOF stuff, where I'm scratching my head is the implementation of the command and receiver classes. We use selenium for testing the web apps UI and will make a call something like:
selenium.Click("link")
orselenium.GetXPathCount("//div[@id='ctl00_MainContent_pnlWork']/table/tbody/tr")
What I want to do is enable a developer to create a command to perform a selenium action such as the code above (ok technically they're 2 different commands since one has a return and one doesn't) but I don't want to have to create a concrete class for each type of selenium action i.e. method but at the same time in my receiver class I don't want to have a huge switch statement that caters for each type of command. I didn't want to pass the receiver to the concrete command object as I have other types of command I need, such as db commands, which need different receivers and where possible would like to use a generic interface for the receivers to enable easy expansion in the future (I already have 3 potential receivers and this may grow). I'm using C# and Asp.Net with the .Net 3.5 framework. Any help appreciated. -
I'm curently trying to simplify testing in my company by enabling the use of the command pattern. So I need: Command - interfact/abstract class defining public contract for concrete commands ConcreteCommand - and command to use Receiver - class that receives command to execute Invoker - class that invokes the command on the receiver. Ok so this is all standard GOF stuff, where I'm scratching my head is the implementation of the command and receiver classes. We use selenium for testing the web apps UI and will make a call something like:
selenium.Click("link")
orselenium.GetXPathCount("//div[@id='ctl00_MainContent_pnlWork']/table/tbody/tr")
What I want to do is enable a developer to create a command to perform a selenium action such as the code above (ok technically they're 2 different commands since one has a return and one doesn't) but I don't want to have to create a concrete class for each type of selenium action i.e. method but at the same time in my receiver class I don't want to have a huge switch statement that caters for each type of command. I didn't want to pass the receiver to the concrete command object as I have other types of command I need, such as db commands, which need different receivers and where possible would like to use a generic interface for the receivers to enable easy expansion in the future (I already have 3 potential receivers and this may grow). I'm using C# and Asp.Net with the .Net 3.5 framework. Any help appreciated. -
Lowest of the Low wrote:
Any help appreciated.
Ok, I suggest you ask at least one question. That way people here might be able to help you. ;)
led mike
Thought I had :confused: To be clear I'm asking the best way to implement the ConcreteCommand & Invoker (which sort of go hand in hand as command passed through needs to be interpreted by the invoker). Once specific example of this is utilising selenium and being able to pass a command to an invoker than will execute that command by calling a method on an instance of the selenium. Hope thats clearer.
-
Thought I had :confused: To be clear I'm asking the best way to implement the ConcreteCommand & Invoker (which sort of go hand in hand as command passed through needs to be interpreted by the invoker). Once specific example of this is utilising selenium and being able to pass a command to an invoker than will execute that command by calling a method on an instance of the selenium. Hope thats clearer.
Lowest of the Low wrote:
To be clear I'm asking the best way
My experience in forum discussions on design issues indicates that it's normally not possible to gain sufficient understanding of the problem domain (due to the limits of text messaging conversations) to definitively know what the "best" solution is. Most likely what you can get is some ideas. Some may not be based on a correct understanding of your problem domain and therefore won't seem very good to you because you do have a more comprehensive understanding of the problem domain. Ultimately it will be up to you to determine which is the "best" solution.
Lowest of the Low wrote:
but I don't want to have to create a concrete class for each type of selenium action i.e. method but at the same time in my receiver class I don't want to have a huge switch statement that caters for each type of command.
Keep in mind what I said above about not having a clear picture, but that statement seems to say something like, we have options A and B and I don't want to do either. So I guess you are asking if someone knows of a another option. I suppose delegates or since you are in 3.5 maybe Lambda expressions could be leveraged to provide a solution that is neither a class for each selenium action nor conditional statements for each selenium action. I am doubtful that delegates are superior to classes and I have not yet ventured into 3.5 and Lambda. However many people that have seem enamored with it, so you might want to spend some time looking at it.
led mike
-
Lowest of the Low wrote:
To be clear I'm asking the best way
My experience in forum discussions on design issues indicates that it's normally not possible to gain sufficient understanding of the problem domain (due to the limits of text messaging conversations) to definitively know what the "best" solution is. Most likely what you can get is some ideas. Some may not be based on a correct understanding of your problem domain and therefore won't seem very good to you because you do have a more comprehensive understanding of the problem domain. Ultimately it will be up to you to determine which is the "best" solution.
Lowest of the Low wrote:
but I don't want to have to create a concrete class for each type of selenium action i.e. method but at the same time in my receiver class I don't want to have a huge switch statement that caters for each type of command.
Keep in mind what I said above about not having a clear picture, but that statement seems to say something like, we have options A and B and I don't want to do either. So I guess you are asking if someone knows of a another option. I suppose delegates or since you are in 3.5 maybe Lambda expressions could be leveraged to provide a solution that is neither a class for each selenium action nor conditional statements for each selenium action. I am doubtful that delegates are superior to classes and I have not yet ventured into 3.5 and Lambda. However many people that have seem enamored with it, so you might want to spend some time looking at it.
led mike
Thanks for the feedback. I think I'll post in the C# forum about Linq and see if anybody can offer some advice there.
-
Thanks for the feedback. I think I'll post in the C# forum about Linq and see if anybody can offer some advice there.