Test Automation Using Selenium
Selenium is a test tool that automates tests. You can use multiple programming languages like Java, C#, Python etc to create Selenium Test Scripts. And also with the Selenium-IDE that also has a Firefox extension, you can easily automate your tests without learning any required programming languages.
- supports regression tests.
- provides quick feedback for developers.
- allows repeating test cases.
- Selenium IDE: a tool with a Firefox extension to create test commands. Using the Selenium IDE, test cases are recorded and executed so that reusable test commands are generated.
- Selenium RC: allows multiple tests to be performed continuously and works with a Selenium RC server.
- Selenium Grid: can work with multiple servers similar to Selenium RC. It works parallel, which means it can run different tests on different remote machines simultaneously.
For example, let’s write a small test using Webdriver in Python. Firstly, you need to install the Selenium module for Python. Then, let’s open Kartaca’s Turkish web page with our application and check the title information.
import unittest from selenium import webdriver class FFKartacaTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() def test_baslik(self): self.driver.get("http://www.kartaca.com/TR/anasayfa") self.assertIn("Kartaca - Anasayfa", driver.title) def tearDown(self): self.driver.close() if __name__ == "__main__": unittest.main()
We can write multiple tests into the class we define. Tests run in alphabetical order (according to the method name), and after each test, the tearDown method is automatically called. We can use Firefox’s Firepath and Firebug tools to find the browser elements that will interact with the program. The elements can be found by the class name (find_element_by_class_name), by CSS (find_element_by_css_selector), by the element id (find_element_by_id). These elements can be a form element or a menu. We can fill out forms using Webdriver’s methods and navigate pages by clicking on the links.