Hey guys
Some feedback I got from users got me thinking about our actions and pages models. As I said before I really believe we need to support a natural language way of defining actions. That's not what this post is about.
Actions Model
-------------------
Looking at how Pyccuracy actions are structured, I noticed a great deal of waste in our code.
class SampleAction(ActionBase):
regex = r'some regex'
def execute(self, context, *args, **kwargs):
//does something.
All my actions feature this same code. That got me thinking about the actual need for all this code. I came to a different, and I think improved, approach, based on Cucumber's solution to this:
@action('And I do something with "<whatever>"')
def do_something(context, whatever):
pass
Note that this is WILDLY brainstormed. I'm thinking we should still support full regular expressions, yet I'm really tempted to provide some shortcuts. There are portions of the regex that EVERY SINGLE action repeats, like (And )?I and things like that. Also everyone uses a word enclosed in quotes, which is what whatever means there. It would get replaced with (?P<whatever>[^"]*) or something like that.
Even though that does not seem like much modification it simplifies both the user and Pyccuracy code. Auto-registering actions with a decorator is way easier and cleaner than with meta-classes (the current approach).
Anyway, I'd love to hear what you guys think of this approach.
Pages Model
------------------
I'm still in the dark here. It's hard to maintain the page model as it is today. I checked other BDD(-Web)? Frameworks (sorry for the regex joke, lol). None of them provides an abstraction for pages. I still think it is an useful abstraction, though.
Some considerations to think about:
URLS
I go to the post of 11 of 09 of 2010 is easier to understand than I go to '/posts/2010/09/11' ?
I think it's pretty much the same, even though with Google Search vs
http://www.google.com, the first one is more expressive. Our target are web applications, though.
Registered Elements
Here is where the main issues with the page model lie. It's HARD to register the proper elements and to keep them in sync with the markup. Specially with dynamic elements. Consider the following:
<a href='/posts/1'>My Blog Post</a>
<a href='/posts/3'>Another Blog Post</a>
How would you register those two links? Register dynamically in an action? Register both using a hard-coded id (Fragile)?
I haven't found a best answer for that yet. I was wondering what a page model of only urls would look like, so I thought of a pages.py that has:
PAGES = {
'Google Search Page': '
http://www.google.com',
'post': /posts/{{year}}/{{month}}/{{day}}'
}
Or something like that. Not sure if that's better than what we have, though. I don't have any better ideas than that. I REALLY need help thinking about a better approach.
Selenium
-------------
I think we are at a point where we should commit to selenium and eliminate browser drivers from the face of the earth. The browser drivers have proven to be a fallacy (in 2 years we haven't created a single browser driver that works other than selenium's). We have a lot of functionality tied to selenium right now (grid, interface of the browser driver are the ones that come to mind).
If we commit to selenium we can simplify a lot of stuff. We can give the actions selenium via context and let the actions do their thing using selenium directly. We don't have the burden of providing documentation for anything that we don't code (like browser drivers) since selenium has its own docs.
Even better, users can upgrade to whatever version of selenium that they want since they'll use it directly (as long as our actions are compatible with the new version).
That's just an idea, AGAIN. I'm not saying we are eliminating browser drivers tomorrow. I wanted to hear from you guys!
Well, I've said enough.
I REALLY want to hear what you guys think!
Cheers,
Bernardo Heynemann