TestStack / TestStack.Seleno

Seleno helps you write automated UI tests in the right way by implementing Page Objects and Page Components and by reading from and writing to web pages using strongly typed view models.
http://teststack.github.com/TestStack.Seleno/
MIT License
180 stars 60 forks source link

Idea for PageWriter Model method #193

Open mattcowen opened 9 years ago

mattcowen commented 9 years ago

I've been thinking more about PageWriter's Model method again. To make it more usable, would a parameter of Action delegates passed in to customise the model's write behaviour be a good idea? So in the case of a checkbox for a boolean model property you could call the Action you want used to update checkboxes on the view. If no Action delegate exists then it works as it does now i.e. assume it is a textbox.

Would this work and also is there any benefit in this? Or is it too complicated?

robdmoore commented 9 years ago

Are you thinking that the delegate would take an IWebElement or just the property name and type or...?

mattcowen commented 9 years ago

Semi structured idea so I'm not sure what would work best to be honest. Still learning.

I want to be able to default to the following code from PageWriter as it is now...

_componentFactory.HtmlControlFor<CheckBox>(propertyExpression)
.ReplaceInputValueWith(stringValue);

But override this if I have a Boolean for example with something like the following call...

if(stringValue == "true"){
_componentFactory.HtmlControlFor<CheckBox>(propertyExpression)
                .Checked();
}else {...}

So there would need to be a parameter to pass in the propertyExpression? And one would need to remember to specify the propertyTypeHandling for Boolean.ToString() so GetStringValue returns the right value?

Is there a potential problem with a group of checkboxes though? How do we ensure the right box is ticked based on value? Is this where a IWebElement parameter would come in useful? And is there anything that does this already?