Automated Testing with Selenium

As we explained in a previous article, testing is critical to success of modern applications such as SaaS. We must provide functional, reliable software. At Webapper, we’re huge fans of test automation where it’s feasible, and that’s why we use Selenium as part of our CI/CD testing methodology. The more likely you are to author tests, the better your results… Automation is the best way to increase test coverage, execution speed, and efficacy in software testing. Automated testing eliminates the tedium of manual, error-prone tests and facilitates unattended (e.g., overnight) testing. Automated testing is an important element in your CI/CD process, and Selenium is a powerful platform for it.

What is Selenium?

Selenium is an open-source, powerful framework you can use to test web browser behavior such as navigating menus, typing data into fields, and clicking buttons. It enables developers to write code simulating anything a “live” user can do in web browsers. It also supports a variety of browsers (Chrome, Firefox, Safari) and languages (Java, Python, C#).

Webapper: Automated Testing with Selenium

Selenium is a suite, with components addressing varied testing requirements:

Selenium Integrated Development Environment (IDE)

Getting started with Selenium IDE is as easy as installing an extension on your browser. The IDE is simple, enabling you to run tests on any browser/OS combination. It allows you to quickly develop reliable end-to-end tests out of the box, including breakpoints and pausing on exceptions. Most importantly, the IDE provides a playback tool to create tests without having to learn a test scripting language.

Selenium WebDriver

Selenium WebDriver offers a simple, concise programming interface that drives the browser, simulating a user’s activity either locally or on a remote machine using Selenium server. WebDriver includes the language bindings and the implementation of the browser controlling code.

Selenium Grid

Selenium Grid enables running parallel tests across different browsers, operating systems, and machines. Grid routes commands of remote browser instances with a server acting as a hub. You must configure a remote server to execute the tests. You’re only running the test on a single hub machine, but execution is performed on different machines called nodes. Grid runs several tests concurrently, so testing time will be abbreviated.

How Do Selenium Tests Work?

Selenium test scripts can apply to any test case or any application under test. You’ll follow a common series of steps.

  • Create a WebDriver instance.
  • Navigate to a web page in your application.
  • Select an HTML element on the page.
  • Perform an action on the selected element.
  • Wait for the browser to respond to the action on the selected.
  • Record test results using a test framework.

Types of Selenium Tests

Functional Tests

Are we building the product right? Does the feature or system function properly?

Functional tests verify that the feature or system works without errors (e.g., 404s, crashes) and the outcome matches specifications.

You can automate functional tests with Selenium by simulating expected returned results using record/playback or scripted tests.

Acceptance Tests

Are we building the right product? Does the feature or system meet the customer expectations and requirements?

You can automate acceptance tests by simulating expected behavior using record/playback or scripted tests.

Regression Tests

Regression tests ensure that updates do not break any existing functionality. Previous test cases are re-run in full or in part, depending on the application and development team.

Best Practices for Selenium Testing

  • Test early and often.
  • Create small, independent, focused tests instead of long complex ones. Every test should test only one thing.
  • Manual first, then automate.
  • Have developers run tests before they commit their code (so they don’t break automated tests).
  • Name your tests such that you know what they do (when you revisit them in a few months!).
  • Create high quality test data.
  • Run parallel tests to simulate real-world operation.
  • Log your test results. Selenium only drives the browser; it does not record results or include any native reporting.
  • Include cross-browser tests (Chrome, Firefox, Edge, Safari).
  • Automate screenshot captures to help investigate errors.
  • Validate tests — if a test fails, identify if it’s a bug in the app or in the test.

Automated Testing with Selenium

Automated testing with Selenium makes frequent regression testing and custom issue reporting possible. As a result, you can provide rapid feedback to developers with virtually unlimited test cases. Starting manually and layering in automation enables a roadmap to higher quality software, all with less overall effort, fewer resources, and simplified management. Note, like any software tool, inexperienced users can deliver poor results. Working with Selenium-experienced DevOps teams can overcome this issue. In the end, this process should help reach quality and operations delivery goals.

Want to Discuss Cloud Application Development?

Contact Webapper for a free consultation. We’ll help you get started on the right foundation.