Selenium Anti-Pattern: Using the browser (for everything)

One thing that I see in Selenium blog posts, the irc channel, etc. is the overuse of the browser to do stuff. Yes, the whole point of Selenium is to drive a browser, and it does it quite well. But that doesn’t mean you must, or even should, use the browser for everything.

Take for instance checking whether a page is available. If you are testing the page flow from a particular page to the next page you should use the browser (as there likely is some action for whether the page is available or not). But if you are checking for something outside the flow you are testing, use something else. For example, python’s urllib.request module.

Same thing for database access. I seem to recall seeing an extension someone wrote which would let you contact the database through the browser (okay, through the Selenese — but it runs in the browser). If you need database access from your test, you should be using Remote Control which then gives you full access to the binding language’s database code. Use that instead.

My rule of thumb is this: If something in a Selenium script can be done outside of the browser, it should not be done in the browser.

Post a Comment

Your email is never published nor shared. Required fields are marked *