Thanks to Skills Matter I attended a Selenium session tonight. Selenium is a tool for automated web testing. The session was led by Erik Doernenburg. He's a ThoughtWorker, so I knew the presentation was going to be good quality. Not only did he present what Selenium is, but he also presented many good techniques for using it with your project.
Some of my notes below:
- All important browsers are supported
- All important languages are supported
- He used Java at the talk
- SeleniumIDE is the tool for recording tests
- It's not necessary to use it, you can write tests in your favourite language
- SeleniumIDE is only for Firefox
- You need to start the Selenium server in order to run tests
- Many methods available:
- createCookie
- dragdrop
- fireEvent
- selenium.click("btnG")
- assertTitle
- There is a concept of locators
- It means the way to locate your DOM elements
- name, id, identifier
- document.forms['myForm'].myDropDown
- XPath
- link text
- css selectors, css = a[href="#id3"]
- Selenium server sets the proxy in your browser, so your browser asks the server for everything
- It's bad for performance testing
- Good for testing multiple browsers
- There was some great advice, which I think applies for all kinds of functional tests
- "Test what you want to test"
- Which means, if you have already tested creating users in a functional way, you don't need to test it functionally again
- So, you can actually use your production code to change the state and then functionally test what you're actually testing
- Saves time
- Makes your tests less fragile
- Cool!
- It's a good pattern to have classes for all of your pages
- WelcomePage
- DailyViewPage
- And one class for your test
- AddItemToBasket
- CreateUser
- Your test classes will then use your page classes
- welcomePage = WelcomePage()
- welcomePage.setDailyView()
- There are other ways of functionally testing your web application
- HttpUnit which asks your web server, not the browser
- Use a Presentation pattern
- have only thin presentation layer
- test only your "event handlers" methods
- It's common practice for QA people to create Selenium scenarios
- You can start your TDD session with a failing Selenium test