Modelo de Pages e Actions

5 views
Skip to first unread message

Bernardo Heynemann

unread,
Aug 27, 2010, 4:08:48 PM8/27/10
to pycc...@googlegroups.com
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

Bernardo Heynemann

unread,
Aug 27, 2010, 4:12:58 PM8/27/10
to pyccuracy
Sorry for the title in Portuguese. It means Pages and Actions Model.
> I think it's pretty much the same, even though with Google Search vshttp://www.google.com, the first one is more expressive. Our target are web

Felipe Knorr Kuhn

unread,
Aug 27, 2010, 4:19:03 PM8/27/10
to pycc...@googlegroups.com
Hello Bernardo,

Just a quick question about Selenium.

You probably know that Selenium 2 is VERY different from the Selenium 1 API.

Even though there is a backwards compatibility layer (SeleniumBackedWebDriver), it's still not working 100%.

Moving to WebDriver (Se2) would be very important, because Se1 support is going to die eventually. I don't know how if there are Python bindings for Se2 yet, though.

What are your thoughts about this?

FK

--
You received this message because you are subscribed to the Google Groups "pyccuracy" group.
To post to this group, send email to pycc...@googlegroups.com.
To unsubscribe from this group, send email to pyccuracy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyccuracy?hl=en.

Bernardo Heynemann

unread,
Aug 27, 2010, 4:24:59 PM8/27/10
to pycc...@googlegroups.com
Are you sure that they changed the API?

We updated the JAR to selenium 2.0 alpha and everything ran smooth.

No code changes required whatsoever. Pyccuracy's trunk is using the updated jar for testing as we speak.

Maybe I did something stupid, though.

Cheers,
Bernardo Heynemann
Developer @ globo.com

Felipe Knorr Kuhn

unread,
Aug 27, 2010, 4:42:19 PM8/27/10
to pycc...@googlegroups.com
Well, yes.

With Selenium 2 and WebDriver, you no longer need to run Selenium RC for example, as WebDriver takes control of the browser on its own.

Launching different browsers requires changing just the driver constructor, as noted at [1].

They also strongly encourage the use of the Page Objects Model [2] when writing your tests.

If you are talking about the Selenium RC jar, it does display 2.0 a2 (I think), which is misleading.

FK

[1] http://seleniumhq.org/docs/09_webdriver.html
[2] http://code.google.com/p/selenium/wiki/PageObjects
Reply all
Reply to author
Forward
0 new messages