Test Automation Using Selenium
Selenium is a test tool that automates tests. 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 at the same time.
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/home") self.assertIn("Kartaca - Home", 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 name of the method), and after each test, the tearDown method is called automatically. 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.