Selenium Test Automation
Selenium is a software robot sent from the future to help us test web applications. But keep in mind that it's not one of those fancy shape-shifting robots than can run really fast. It's more like one of those really strong robots that's not very fast and is best suited for accomplishing a certain objective.
That is to say, Selenium is really good at a specific set of things. If you know what those are and stick to them then you can easily write reliable, scalable, and maintainable tests that you and your team can trust.
What Selenium Is and Is Not Good At
#Selenium is built to automate browsers, specifically human interaction with them. Things like navigating to pages, clicking on elements, typing text into input fields, etc.
It's less ideal for checking lower-level functionality like HTTP status codes or HTTP headers. While you can use Selenium this way, it requires additional setup of a third-party tool (e.g., BrowserMob Proxy), and it is a slippery slope since there are numerous edge cases to consider at this level.
Selenium Highlights
Selenium works on every major browser, with a number of major programming languages, and on every major operating system. Each language binding and browser is actively being developed to stay current. Yes, even Internet Explorer (thanks to Jim Evans and support from Microsoft!).
Selenium can be run on your local computer, on a server (with Selenium Remote), on your own set of servers (with Selenium Grid), or on a third-party cloud provider (like Sauce Labs). As your test suite grows, your test runs will take longer to complete. To speed them up you will want to run them in parallel, which is where the benefit of having your own servers or using a cloud provider comes in -- that, and the ability to have numerous browser and operating system combinations to run your tests on.
One of the guiding philosophies of Selenium is to be able to write your tests once and run them across multiple browsers. While this is a rosy proposition, it's not entirely accurate. There are plenty of gotchas to watch out for when you get into it.
Picking A Language
In order to work well with Selenium, you need to choose a programming language to write your acceptance tests in. Conventional wisdom will tell you to choose the same language that the application is written in. That way if you get stuck you can ask the developers on your team for help. But if you're not proficient in this language (or new to development), then your progress will be slow and you'll likely end up asking for more developer help than they have time for --hindering your automation efforts and setting you up for failure.
A great way to determine which language to go with is to answer one simple question: Who will own the automated tests? The answer to this and the discussion that unfolds from it will help you more effectively choose a programming language.
Open Source Selenium Frameworks
You can find a list of open-source Selenium WebDriver frameworks and their respective languages:
- C#: Golem
- Groovy: Geb
- Java: Stevia
- Intern, wd
- PHP: Saunter
- Python: Robot Framework Saunter
- Ruby: ChemistryKit
Outro
Choosing a programming language for automated testing is not a decision that should be taken lightly. If you're just starting out (or looking to port your tests) then considering and discussing these things will help position you for long term success.
With all that being said, the rest of this book will show you how to build your own test harness (in addition to writing well-factored tests) in Java with JUnit.
Team Lead At HCL
5 年informative article